Skip to content

Commit bb03d1c

Browse files
authored
Add nested folder capability for crontab tasks (#543)
2 parents b2542d9 + 3e2ae6c commit bb03d1c

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Read more:
4444
- `helpers.abortPromise` added; will reject when `abortSignal` aborts (useful
4545
for `Promise.race()`)
4646
- `backfillPeriod` is now marked as optional in TypeScript (defaults to 0).
47+
- Support for loading tasks from nested folders in crontab.
48+
- (`* * * * * nested/folder/task ?jobKey=my_key&jobKeyMode=preserve_run_at`)
4749

4850
## v0.16.6
4951

__tests__/__snapshots__/crontab.test.ts.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,35 @@ Array [
143143
"task": "with_key_and_mode",
144144
Symbol(isParsed): true,
145145
},
146+
Object {
147+
"identifier": "nested/task",
148+
"match": [Function],
149+
"options": Object {
150+
"backfillPeriod": 0,
151+
"jobKey": "my_key",
152+
"jobKeyMode": "preserve_run_at",
153+
"maxAttempts": undefined,
154+
"priority": undefined,
155+
"queueName": undefined,
156+
},
157+
"payload": null,
158+
"task": "nested/task",
159+
Symbol(isParsed): true,
160+
},
161+
Object {
162+
"identifier": "nested/folder/task",
163+
"match": [Function],
164+
"options": Object {
165+
"backfillPeriod": 0,
166+
"jobKey": "my_key",
167+
"jobKeyMode": "preserve_run_at",
168+
"maxAttempts": undefined,
169+
"priority": undefined,
170+
"queueName": undefined,
171+
},
172+
"payload": null,
173+
"task": "nested/folder/task",
174+
Symbol(isParsed): true,
175+
},
146176
]
147177
`;

__tests__/crontab.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ test("parses crontab file correctly", () => {
4444
* * * * * lots_of_spaces
4545
* * * * * with_key ?jobKey=my_key
4646
* * * * * with_key_and_mode ?jobKey=my_key&jobKeyMode=preserve_run_at
47+
* * * * * nested/task ?jobKey=my_key&jobKeyMode=preserve_run_at
48+
* * * * * nested/folder/task ?jobKey=my_key&jobKeyMode=preserve_run_at
4749
`;
4850
const parsed = parseCrontab(exampleCrontab);
4951

@@ -173,6 +175,20 @@ test("parses crontab file correctly", () => {
173175
});
174176
expect(parsed[8].payload).toEqual(null);
175177

178+
expect(parsed[9].task).toEqual("nested/task");
179+
expect(parsed[9].identifier).toEqual("nested/task");
180+
const parsedCronMatch9 = (parsed[9].match as any)
181+
.parsedCronMatch as ParsedCronMatch;
182+
expect(parsedCronMatch9.minutes).toEqual(ALL_MINUTES);
183+
expect(parsedCronMatch9.hours).toEqual(ALL_HOURS);
184+
185+
expect(parsed[10].task).toEqual("nested/folder/task");
186+
expect(parsed[10].identifier).toEqual("nested/folder/task");
187+
const parsedCronMatch10 = (parsed[10].match as any)
188+
.parsedCronMatch as ParsedCronMatch;
189+
expect(parsedCronMatch10.minutes).toEqual(ALL_MINUTES);
190+
expect(parsedCronMatch10.hours).toEqual(ALL_HOURS);
191+
176192
expect(parsed).toMatchSnapshot();
177193
});
178194

src/cronConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const CRONTAB_WILDCARD = /^\*(?:\/([0-9]+))?$/;
2828
// The command from the crontab line
2929
/** Splits the command from the crontab line into the task, options and payload. */
3030
export const CRONTAB_COMMAND =
31-
/^([_a-zA-Z][_a-zA-Z0-9:_-]*)(?:\s+\?([^\s]+))?(?:\s+(\{.*\}))?$/;
31+
/^([_a-zA-Z][_a-zA-Z0-9:/_-]*)(?:\s+\?([^\s]+))?(?:\s+(\{.*\}))?$/;
3232

3333
// Crontab command options
3434
/** Matches the id=UID option, capturing the unique identifier */

0 commit comments

Comments
 (0)