Skip to content

Conversation

@alexandre-daubois
Copy link
Member

This adds a new configuration key to configure max consecutive failures for workers:

frankenphp {
    worker {
        # ...
        max_consecutive_failures 10
    }
}

@alexandre-daubois alexandre-daubois force-pushed the worker-max-consec-failures branch 3 times, most recently from eef1c5c to f37aaf8 Compare June 26, 2025 11:09
@alexandre-daubois alexandre-daubois force-pushed the worker-max-consec-failures branch 6 times, most recently from 8ac24e5 to 95c4fdd Compare June 26, 2025 15:16
@AlliBalliBaba
Copy link
Contributor

I think workers will only fail on startup, so not sure if there's much benefit to fine-tuning that failure limit. I would agree though that disabling the failing entirely might be a valid use case.

Also, it would be nice to have something like a worker_option, so we don't break the api anytime theres a new worker configuration. Something like this:

frankenphp.WithWorkers( 
    fileName,
    num,
    WithWorkerEnv(...),
    WithWorkerWatchMode(...),
    WithWorkerMaxFailures(...),
)

@alexandre-daubois alexandre-daubois force-pushed the worker-max-consec-failures branch 3 times, most recently from 3d3d831 to 0b512db Compare June 27, 2025 07:53
@alexandre-daubois
Copy link
Member Author

Good idea, I implemented functional options

@alexandre-daubois alexandre-daubois force-pushed the worker-max-consec-failures branch from 0b512db to 03ce7e2 Compare June 27, 2025 12:48
workerOpts := []frankenphp.WorkerOption{
frankenphp.WithWorkerEnv(opts.env),
frankenphp.WithWorkerWatchMode(opts.watch),
frankenphp.WithWorkerMaxFailures(6),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frankenphp.WithWorkerMaxFailures(6),

options.go Outdated
func WithWorkerMaxFailures(maxFailures int) WorkerOption {
return func(w *workerOpt) {
if maxFailures < -1 {
maxFailures = DefaultMaxConsecutiveFailures
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should return an error here instead of silently ignoring the invalid value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I updated all functions to return an error

workers = make(map[string]*worker)
_, err1 := newWorker(workerOpt{fileName: "filename.php"})
_, err2 := newWorker(workerOpt{fileName: "filename.php"})
_, err1 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: 6})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err1 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: 6})
_, err1 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: DefaultMaxConsecutiveFailures})

_, err1 := newWorker(workerOpt{fileName: "filename.php"})
_, err2 := newWorker(workerOpt{fileName: "filename.php"})
_, err1 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: 6})
_, err2 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: 6})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err2 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: 6})
_, err2 := newWorker(workerOpt{fileName: "filename.php", maxConsecutiveFailures: DefaultMaxConsecutiveFailures})

Comment on lines 202 to 203
_, err1 := newWorker(workerOpt{fileName: "filename.php", name: "workername", maxConsecutiveFailures: 6})
_, err2 := newWorker(workerOpt{fileName: "filename2.php", name: "workername", maxConsecutiveFailures: 6})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, err1 := newWorker(workerOpt{fileName: "filename.php", name: "workername", maxConsecutiveFailures: 6})
_, err2 := newWorker(workerOpt{fileName: "filename2.php", name: "workername", maxConsecutiveFailures: 6})
_, err1 := newWorker(workerOpt{fileName: "filename.php", name: "workername", maxConsecutiveFailures: DefaultMaxConsecutiveFailures})
_, err2 := newWorker(workerOpt{fileName: "filename2.php", name: "workername", maxConsecutiveFailures: DefaultMaxConsecutiveFailures})

num: 1,
fileName: testDataPath + "/" + fileName,
num: 1,
maxConsecutiveFailures: 6,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxConsecutiveFailures: 6,
maxConsecutiveFailures: DefaultMaxConsecutiveFailures,

options.go Outdated
)

// DefaultMaxConsecutiveFailures is the default maximum number of consecutive failures before panicking
const DefaultMaxConsecutiveFailures = 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be unexported, this isn't used outside of the frankenphp package

@alexandre-daubois alexandre-daubois force-pushed the worker-max-consec-failures branch from 03ce7e2 to 648196f Compare June 27, 2025 16:02
@dunglas dunglas merged commit 96400a8 into php:main Jun 30, 2025
43 checks passed
@dunglas
Copy link
Member

dunglas commented Jun 30, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants