-
Notifications
You must be signed in to change notification settings - Fork 225
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
Conversation
@@ -96,6 +96,13 @@ jobs: | |||
REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}} | |||
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test | |||
|
|||
- name: scheduler | |||
run: cargo run -- generate scheduler |
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
$ cargo run -- generate job send_emails --cron '* * * * ..'
Added `send_emails` to scheduler jobs
Total 12 jobs in `config/development.yaml` under `scheduler:`.
This will upsert a schedule record.
You can also experiment with english-to-cron libraries
$ cargo run -- generate job send_emails --at 'every sunday at 1pm'
Cron schedule: 0 * * * 1 *
Added `send_emails` to jobs
Total 12 jobs in `config/development.yaml` under `scheduler:`.
Notice we generate a job
If we say scheduler
it is the thing that runs jobs
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
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
use a hashmap instead of vec, id instead of name
jobs:
send_emails:
...
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.
agree.
changed: 19d2a0f
# The name of the job. | ||
- name: "Run command" | ||
# The type of job. | ||
shell: |
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 think it should be just:
run: "...command.."
shell: true | false
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.
Done: f85601b
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
can we do tags: ['base', 'infra']
in YAML example?
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.
Done. 667ce38
```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 comment
The 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"
might be good to add a "cron to english" description here, based on the cron expression that's saved in the configuration
This PR introduces the ability to schedule and run cron jobs within the Loco framework. The new scheduler functionality includes: