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

worker timeouts #7

Merged
merged 7 commits into from
Oct 1, 2015
Merged

worker timeouts #7

merged 7 commits into from
Oct 1, 2015

Conversation

bkendall
Copy link
Collaborator

Now workers can be set to time out! Pretty cool, eh!? Unit and functional tests have been created for this functionality.

One interesting corner is that setting the timeout to 0 does not actually give the worker infinite time (it will fail almost immediately). Is this good? Is that what we want to do? I might be able to have the timeout added conditionally, but I just want to pose the question.

Edit: I think the 0 timeout thing has been resolved. See discussion below.

@rsandor
Copy link
Contributor

rsandor commented Sep 29, 2015

Easy way to get around the 0 timeout is to have a minimum if one is defined. You could use the check like so:

if (!isNumber(timeout) || timeout < process.env.MINIMUM_TIMEOUT) {
  throw ...
}

This way you allow the user to set the minimum timeout in a 12-factor way, while keeping things sane in case someone misses a 1 in front of their 0. Suggest a minimum timeout of 10 ms.

.cancellable()
.then(function () { return this.task(this.job); });
})
.timeout(this.msTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

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

So you are always applying the timeout? I wonder if it should just not apply it if the user did not define one...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this has been changed now. If a user specifies no timeout (or a timeout of 0), it will not set a timeout on the promise.

})
.then(function () {
var timeout = module.exports.globalTimeout;
module.exports.globalTimeout = module.exports.globalTimeout / 2;
Copy link
Member

Choose a reason for hiding this comment

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

do you cut the timeout in half every retry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, for this particular example worker. I'm thinking now that maybe I should supply a list of timeouts, and once there are no more timeouts, it throws a TaskFatalError. That could be useful...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added more information to the description, but didn't change the implementation

@anandkumarpatel
Copy link
Member

seems good to me, but I am not an expert with promises yet.

@bkendall
Copy link
Collaborator Author

bkendall commented Oct 1, 2015

@rsandor I got around the 0 timeout thing by simply not adding the timeout if none was specified. I didn't set a default timeout any higher (or a suggested minimum), but I did add documentation about the environment variables :)

@rsandor
Copy link
Contributor

rsandor commented Oct 1, 2015

This looks great! 💯

rsandor added a commit that referenced this pull request Oct 1, 2015
@rsandor rsandor merged commit a3c4887 into master Oct 1, 2015
@rsandor rsandor deleted the feature-timeout branch October 1, 2015 07:00
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.

None yet

3 participants