-
Notifications
You must be signed in to change notification settings - Fork 410
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
feat(repeatable): new repeatables structure #2617
Conversation
26744f4
to
5372365
Compare
table.insert(optionalValues, opts['every']) | ||
end | ||
|
||
rcall("HMSET", repeatKey .. ":" .. customKey, "name", opts['name'], |
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.
Do we need to use a HMSET here? wondering if we just could store directly the msg pack data in a normal Redis key 🤔
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.
not sure, but I feel more natural to use a hmset if the intention is also to update those options or if we need to get specific values from it without getting all attributes
return customKey | ||
end | ||
|
||
if ARGV[4] == '0' then |
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.
Why is this check needed?
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.
as one of my comments above, worker checks existence to know if it needs to add a new delayed job while queue.add just adds repeatables whithout this check. That's my understanding from the actual logic
@@ -31,7 +36,7 @@ export class Repeat extends QueueBase { | |||
skipCheckExists?: boolean, |
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.
Do you remember the use case where this boolean was needed?
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.
I was inspecting the code and here is false by default https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L721 in worker class (check the existence in case we need to stop adding the next delayed job), here is true https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue.ts#L209 (where we are not checking the existence of that repeatable job and we add the repeatable job)
src/classes/repeat.ts
Outdated
@@ -70,23 +75,28 @@ export class Repeat extends QueueBase { | |||
repeatOpts.jobId = opts.jobId; | |||
} | |||
|
|||
const repeatJobKey = getRepeatKey(name, repeatOpts); | |||
const optionsConcat = getRepeatKey(name, repeatOpts); |
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.
Maybe we should rename the function getRepeatKey if this is not going to be the key anymore.
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.
sounds good, what about getQualifiedName
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.
As it is returning a concatenation of options, maybe getRepeatCocatOptions ?
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.
sounds good
// | ||
// Generate unique job id for this iteration. | ||
// | ||
const jobId = this.getRepeatJobId({ | ||
name, | ||
const jobId = this.getRepeatDelayedJobId({ |
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.
It is important that this jobId is generated in the same way as in the previous version to avoid breaking changes.
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.
it won't be a breaking change in this case as the jobId is only used for new delayed jobs and set it once. Also when removing old cron jobs I'm considering checking the old format before the new one
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.
In the edge case if it adds a delayed job with a different jobId but the same delay time, then you will end up having 2 reputable jobs at least in one iteration, but maybe this edge case cannot happen in practice.
src/classes/repeat.ts
Outdated
const repeatJobId = this.getRepeatJobId({ | ||
const optionsConcat = getRepeatKey(name, { ...repeat, jobId }); | ||
const repeatJobKey = repeat.key ?? this.hash(optionsConcat); | ||
const oldRepeatJobId = this.getRepeatJobId({ |
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.
Maybe the word "legacy" instead of "old" makes this more explicit.
@@ -1,9 +1,10 @@ | |||
export type RepeatableJob = { | |||
key: string; | |||
name: string; | |||
id: string | null; | |||
id?: string | null; |
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.
jobId is not a useful attribute now that we can pass a custom key, in new repeatable jobs this value won't be used
table.insert(optionalValues, opts['every']) | ||
end | ||
|
||
rcall("HMSET", repeatKey .. ":" .. customKey, "name", opts['name'], |
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.
not sure, but I feel more natural to use a hmset if the intention is also to update those options or if we need to get specific values from it without getting all attributes
@@ -31,7 +36,7 @@ export class Repeat extends QueueBase { | |||
skipCheckExists?: boolean, |
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.
I was inspecting the code and here is false by default https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L721 in worker class (check the existence in case we need to stop adding the next delayed job), here is true https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue.ts#L209 (where we are not checking the existence of that repeatable job and we add the repeatable job)
src/classes/repeat.ts
Outdated
@@ -70,23 +75,28 @@ export class Repeat extends QueueBase { | |||
repeatOpts.jobId = opts.jobId; | |||
} | |||
|
|||
const repeatJobKey = getRepeatKey(name, repeatOpts); | |||
const optionsConcat = getRepeatKey(name, repeatOpts); |
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.
sounds good, what about getQualifiedName
// | ||
// Generate unique job id for this iteration. | ||
// | ||
const jobId = this.getRepeatJobId({ | ||
name, | ||
const jobId = this.getRepeatDelayedJobId({ |
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.
it won't be a breaking change in this case as the jobId is only used for new delayed jobs and set it once. Also when removing old cron jobs I'm considering checking the old format before the new one
return customKey | ||
end | ||
|
||
if ARGV[4] == '0' then |
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.
as one of my comments above, worker checks existence to know if it needs to add a new delayed job while queue.add just adds repeatables whithout this check. That's my understanding from the actual logic
4f584a3
to
aca3f19
Compare
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.
const { immediately, ...filteredRepeatOpts } = repeatOpts; | ||
|
||
// The job could have been deleted since this check | ||
if (repeatableExists) { | ||
if (repeatJobKey) { |
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.
The comment The job could have been deleted since this check
is a bit confusing now since the "repeatableExists" boolean is not used anymore.
f14cf04
to
5c6dd5c
Compare
ref #2612 fixes #2399 #2596