Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail Job After N Seconds #187

Open
bmeynell opened this issue Jan 3, 2018 · 1 comment
Open

Fail Job After N Seconds #187

bmeynell opened this issue Jan 3, 2018 · 1 comment

Comments

@bmeynell
Copy link
Contributor

bmeynell commented Jan 3, 2018

When running several jobs in parallel similar to this, the worker should be able to define a job-level timeout, and when that time is exceeded, mark the job as failed. This is important for all blocking (foreground) jobs as the client is perpetually stalled until the slowest running job is completed.

Gearman Protocol:

Worker Requests
...
CAN_DO_TIMEOUT

Same as CAN_DO, but with a timeout value on how long the job
is allowed to run. After the timeout value, the job server will
mark the job as failed and notify any listening clients.

Arguments:

  • NULL byte terminated Function name.
  • Timeout value.

GearmanWorker::register ( string $function_name [, int $timeout ] ):

Registers a function name with the job server with an optional timeout. The timeout specifies how many seconds the server will wait before marking a job as failed. If the timeout is set to zero, there is no timeout.

GearmanWorker::addFunction ( string $function_name , callable $function [, mixed &$context [, int $timeout ]] ):

Registers a function name with the job server and specifies a callback corresponding to that function. Optionally specify ... a timeout.

Is there a way to achieve this functionality with this bundle?

@daum
Copy link
Collaborator

daum commented Jan 3, 2018

@bmeynell Right now we don't have that built into the bundle, however adding it shouldn't be too difficult. For the most part I think it'd be adding a new option to the work definition like jobTimeout, then adding it to when we add the function to the worker here: https://github.com/mmoreram/GearmanBundle/blob/master/Service/GearmanExecute.php#L321
Finally just would need to update the docs and to add a test for it.

I think for the most part that is all there is. I'm a bit busy with getting caught up after the holidays so don't have time to work on it right now. If you want to make a PR I can get it merged and released for you, otherwise I can try to work on it later this month.

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

No branches or pull requests

2 participants