Skip to content

Commit

Permalink
feat(job-scheduler): save iteration count (#3018)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Jan 24, 2025
1 parent 824fc4c commit ad5c07c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/classes/job-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export class JobScheduler extends QueueBase {
if (jobData) {
return {
key,
iterationCount: parseInt(jobData.ic) || null,
name: jobData.name,
endDate: parseInt(jobData.endDate) || null,
tz: jobData.tz || null,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/addJobScheduler-6.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ local function storeRepeatableJob(schedulerId, schedulerKey, repeatKey, nextMill
table.insert(optionalValues, templateData)
end

rcall("HMSET", schedulerKey, "name", opts['name'],
rcall("HMSET", schedulerKey, "name", opts['name'], "ic", 1,
unpack(optionalValues))
end

Expand Down
1 change: 1 addition & 0 deletions src/commands/updateJobScheduler-7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if prevMillis ~= false then
local schedulerAttributes = rcall("HMGET", schedulerKey, "name", "data")

rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
rcall("HINCRBY", schedulerKey, "ic", 1)

local eventsKey = KEYS[5]
local metaKey = KEYS[2]
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/job-scheduler-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface JobSchedulerJson<D = any> {
key: string; // key is actually the job scheduler id
name: string;
id?: string | null;
iterationCount?: number;
endDate: number | null;
tz: string | null;
pattern: string | null;
Expand Down
3 changes: 3 additions & 0 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ describe('Job Scheduler', function () {

expect(scheduler).to.deep.equal({
key: 'test',
iterationCount: 1,
name: 'test',
endDate: null,
tz: null,
Expand Down Expand Up @@ -750,6 +751,7 @@ describe('Job Scheduler', function () {

expect(scheduler).to.deep.equal({
key: 'rrule',
iterationCount: 1,
name: 'rrule',
endDate: null,
next: 1486481042000,
Expand Down Expand Up @@ -1719,6 +1721,7 @@ describe('Job Scheduler', function () {

expect(jobSchedulers[0]).to.deep.equal({
key: 'test',
iterationCount: 2,
name: 'a',
endDate: null,
tz: 'Asia/Calcutta',
Expand Down

0 comments on commit ad5c07c

Please sign in to comment.