-
Notifications
You must be signed in to change notification settings - Fork 226
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 Scheduler Feature for Running Cron Jobs #735
Changes from 7 commits
03de04c
da7d0f4
ab992e2
8f19fad
84b1145
7b22c1a
dcd7951
19d2a0f
e4e01c0
667ce38
f85601b
779935b
c2c253d
3a40a02
615f0fc
4b1716e
c1d72d1
b36bbd2
7b05e8d
3444f61
0bcd8c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,35 @@ auth: | |
expiration: 604800 # 7 days | ||
# </snip> | ||
|
||
# Scheduler Jobs Configuration | ||
# <snip id="configuration-scheduler"> | ||
scheduler: | ||
# Location of shipping the command stdout and stderr. | ||
output: stdout | ||
# A list of jobs to be scheduled. | ||
jobs: | ||
# The name of the job. | ||
- name: "Run command" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a hashmap instead of vec, id instead of name
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree. |
||
# The type of job. | ||
shell: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be just:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: f85601b |
||
command: "echo loco >> ./scheduler.txt" | ||
# The cron expression defining the job's schedule. | ||
cron: "*/1 * * * * *" | ||
output: silent | ||
tags: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. 667ce38 |
||
- base | ||
- infra | ||
|
||
- name: "Run command" | ||
task: | ||
name: "foo" | ||
cron: "*/5 * * * * *" | ||
|
||
- name: "list if users" | ||
task: | ||
name: "user_report" | ||
cron: "*/7 * * * * *" | ||
tags: | ||
- base | ||
- users | ||
# </snip> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
jobs: | ||
- name: "add text" | ||
shell: | ||
command: "echo loco >> ./scheduler.txt" | ||
cron: "*/1 * * * * *" | ||
tags: | ||
- base | ||
- infra | ||
|
||
- name: "Run command" | ||
task: | ||
name: "foo" | ||
vars: | ||
path: /tmp/scheduler.txt | ||
cron: "*/5 * * * * *" | ||
|
||
- name: "list if users" | ||
task: | ||
name: "user_report" | ||
cron: "*/7 * * * * *" | ||
tags: | ||
- base | ||
- users |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
```console | ||
$ LOCO_ENV=test blo-cli scheduler --list | ||
# job_name cron tags kind | ||
1 Run command */1 * * * * * base, infra Shell { command: "echo loco >> ./scheduler.txt" } | ||
2 Run command */5 * * * * * - Task { name: "foo", vars: None } | ||
3 list if users */7 * * * * * base, users Task { name: "user_report", vars: None } | ||
|
||
|
||
``` | ||
|
||
```console | ||
$ LOCO_ENV=test blo-cli scheduler --config ./config/scheduler.yaml --list | ||
# job_name cron tags kind | ||
1 add text */1 * * * * * base, infra Shell { command: "echo loco >> ./scheduler.txt" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are some libraries that do "english to cron" and "cron to english" |
||
2 Run command */5 * * * * * - Task { name: "foo", vars: Some({"path": "/tmp/scheduler.txt"}) } | ||
3 list if users */7 * * * * * base, users Task { name: "user_report", vars: None } | ||
|
||
|
||
``` |
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 would add some more value for example
This will upsert a schedule record.
You can also experiment with english-to-cron libraries
Notice we generate a
job
If we say
scheduler
it is the thing that runsjobs
Its also a good opportunity to centralize and sharpen our concepts and terminology:
task
is a one time, you run it any way you likejob
is a repeat on a schedule, run by thescheduler
worker
is something that performs abackground job
from a queue