Skip to content
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

Cron jobs #69

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Cron jobs #69

wants to merge 7 commits into from

Conversation

maximevanhees
Copy link

@maximevanhees maximevanhees commented Oct 4, 2024

The ability to create a cron job by specifying the cron flag in the <service>.yaml file.

cron field syntax is: sec min hour day_of_month month day_of_week year

Example hello.yaml (runs every 5th second of each minute):

exec: sh -c "echo 'hello each 5 sec from cronjob'"
oneshot: true
cron: "*/5 * * * * *"
log: stdout

Start (as default):

  • zinit monitor hello

Closes #66

Copy link
Member

@muhamadazmy muhamadazmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @maximevanhees for this PR. But I left few "questions" of things that should be taken care of.

In general. I don't fully agree that cron jobs should be implemented in zinit this way due to the following points:

  • Zinit is a process manager. This unnecessary complicate the state machine of zinit.
  • Service dependency. What happens if another service is depending on a oneshot service that has cron ?
  • My major concern of what happens when:
    • You start a service (that has cron)
    • You then decide to stop and forget it
    • You monitor it again with new cron schedule

Again embedding cron in zinit this way makes it hard to answer those questions this is why I suggest the following:

implement a completely separate zinit cron service that can understand /etc/crontab file

That is a normal daemon that can read this file, and run jobs as scheduled in this file https://linux.die.net/man/5/crontab

When zinit start. it auto start zinit cron (without configuration) and this service canb't be managed by external zinit commands (so you can't stop it or restart it)

This way we take the cron outside of zinit state machine and at the same time it's natively supported by it. It also avoids the dependency problem since cron tasks are completely external tasks that are managed by zinit itself but rather by zinit cron same way as crond

Note: this is just a proposal, feel free to ignore it if it's required that cron is configured per service as you did.

src/zinit/config.rs Show resolved Hide resolved
src/zinit/mod.rs Outdated Show resolved Hide resolved
src/zinit/mod.rs Outdated Show resolved Hide resolved
@maximevanhees
Copy link
Author

My major concern of what happens when:

  • You start a service (that has cron)
  • You then decide to stop and forget it
  • You monitor it again with new cron schedule

What exactly is your concern here? When a service is stopped and forgotten it becomes completely unrelated to monitoring it again (even with a new cron schedule).

@maximevanhees
Copy link
Author

  • Zinit is a process manager. This unnecessary complicate the state machine of zinit.

I've spoken with KDS about it and he is adamant that we should keep it as one single process and thus not create a separate zinit cron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

check how easy is it to add cron scheduling to zinit
2 participants