Skip to content

Conversation

@archanaserver
Copy link
Contributor

@archanaserver archanaserver commented Nov 27, 2025

Introduce Foreman::Cron with a hard-coded mapping from hourly/daily/weekly/monthly to existing rake tasks, and add cron:hourly, cron:daily, cron:weekly and cron:monthly rake tasks.

These serve as generic entrypoints for scheduling (e.g. systemd timers in foremanctl) instead of wiring individual tasks.

Related to: theforeman/foremanctl#288 (review)

@archanaserver
Copy link
Contributor Author

Also the failure looks unrelated to the changes

@evgeni
Copy link
Member

evgeni commented Dec 9, 2025

Also the failure looks unrelated to the changes

Yepp, that's a regression in facterdb

@evgeni
Copy link
Member

evgeni commented Dec 9, 2025

The tests were fixed in #10794 -- if you rebase CI should turn green.

I think Foreman::Cron could use some tests too ;-)

@archanaserver
Copy link
Contributor Author

I think Foreman::Cron could use some tests too ;-)

fair, working on it :/

@evgeni
Copy link
Member

evgeni commented Dec 12, 2025

This needs a redmine, and the test setup fixed, but other than that it looks good!

Thanks!

@archanaserver
Copy link
Contributor Author

This needs a redmine, and the test setup fixed, but other than that it looks good!

@evgeni seems like redmine is not accessible atm

@evgeni
Copy link
Member

evgeni commented Dec 15, 2025

This needs a redmine, and the test setup fixed, but other than that it looks good!

@evgeni seems like redmine is not accessible atm

Fixed it now.

@archanaserver archanaserver changed the title Add cron rake tasks for recurring jobs Fixes #38956 - Add cron rake tasks for recurring jobs Dec 15, 2025
@archanaserver archanaserver force-pushed the cron-rake-tasks branch 2 times, most recently from c600fe2 to 43d493c Compare December 17, 2025 08:35
@archanaserver archanaserver requested a review from evgeni December 17, 2025 08:45
@archanaserver
Copy link
Contributor Author

@evgeni i see that db fixture error is unrelated to this fix, and rest is working fine now.

@archanaserver
Copy link
Contributor Author

@evgeni sorry, i forgot looking at this PR earlier, so missed the comment, but thanks, updated now!

Introduce `Foreman::Cron` with a hard-coded mapping from
hourly/daily/weekly/monthly to existing rake tasks, and add
`cron:hourly`, `cron:daily`, `cron:weekly` and `cron:monthly` rake tasks.

These serve as generic entrypoints for scheduling (e.g. systemd
timers in foremanctl) instead of wiring individual tasks.

Allow plugins to register extra tasks in Foreman::Cron

Fail cron:* rake tasks when a job fails

Refine Foreman::Cron task

Add unit tests for Foreman::Cron

unified registry

add section on scheduling recurring plugin tasks
Foreman::Cron.register(:daily, 'reports:daily')
Foreman::Cron.register(:daily, 'db:sessions:clear')
Foreman::Cron.register(:daily, 'reports:expire')
Foreman::Cron.register(:daily, 'audits:expire')
Copy link
Member

Choose a reason for hiding this comment

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

When testing this, I realized that the audits:expire task calls exit here:

puts "The interval for keeping the Audits is not defined in the settings, exiting..."
exit 0

Which will abort the whole rake run and skip any follow up tasks, while exiting 0, so no error reporting happens.

I don't think we need to fix that in this PR, but something we should address before going live with this new framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right, thanks for pointing this out! but yeah let's keep this PR focused for wiring up the cron framework work we did, i'll follow up on another PR for refactor of both reports:* and audits:expire

Foreman::Cron.register(:daily, 'reports:expire')
Foreman::Cron.register(:daily, 'audits:expire')

Foreman::Cron.register(:weekly, 'reports:weekly')
Copy link
Member

Choose a reason for hiding this comment

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

reports:* similarly uses exit, but it seems at least the default config is fine as it did not abort for me.

$stdout.puts "Unable to find puppet environment=#{env}"
exit 1

$stdout.puts "invalid fact #{ENV['fact']}"
exit 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack!

Copy link

@shubhamsg199 shubhamsg199 left a comment

Choose a reason for hiding this comment

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

ACK, Tested and works as expected.

@evgeni evgeni merged commit c35a101 into theforeman:develop Jan 7, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants