-
Notifications
You must be signed in to change notification settings - Fork 799
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
Add top level disable and enable #1109
Add top level disable and enable #1109
Conversation
* Similar to the mapping between `job.remove` and `agenda.cancel`, these methods alter the `disabled` property for all jobs matching the supplied query * Tests covering the new logic have been added to `/test/agenda.js`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is good. Some code comments needs rewording though.
lib/agenda/enable.js
Outdated
const debug = require('debug')('agenda:enable'); | ||
|
||
/** | ||
* Enables any jobs matching the passed MongoDB query, and removes them from the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and removes them from the database" ?
I don't see that happening in the code. :) Perhaps, the comment needs an update?
lib/agenda/enable.js
Outdated
* @name Agenda#enable | ||
* @function | ||
* @param {Object} query MongoDB query to use when enabling | ||
* @caller client code, Agenda.purge(), Job.remove() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct? I don't see that in the PR changes.
@koresar Thanks for the feedback and callouts on the comments/docs. I've updated my code with the upstream master and migrated my code to Typescript. Only remaining task is the HTML docs, which I believe are handled as a part of the release process via the |
Quality PR! Thanks for that. |
Published in v4.2.0. |
* this code has been migrated over from agenda#1109 * migrates old methods from individual files to the top level Agenda Class * test suite updated with original test suite content from original fork
Use Case
We have a job which sends out invites in a staged manner over a period of time: "sendInvites". Once enough people have responded to the invite, we don't want to send out any more invites. If someone later cancels, we want to continue sending out invites in a tiered manner.
Workaround
The same effect can be accomplished by querying any outstanding "sendInvites" jobs, and iterating over them and calling
job.disable()
, and doing the same thing to enable withjob.enable()
.Alternatively the
this._collection.updateMany
based implementation can be patched to a local instance via prototype injection.Proposed Implementation
Following the example of
agenda.cancel()
and its relationship withjob.remove()
, this PR adds the following two methods:PR Checks: