-
Notifications
You must be signed in to change notification settings - Fork 20
add quadlet recurring job runner and timers for core rake tasks #288
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 quadlet recurring job runner and timers for core rake tasks #288
Conversation
|
so now the |
491f7e4 to
1cade7a
Compare
|
@evgeni so moved back to the explicit Also opened two follow-ups PR for katello and foreman_tasks #298 and #299 which actually needs code refactor once this one is merged because to make a generic Question: One thing i was unsure about is for testing, should we keep the exact same behavior as the old cron jobs, or is a journalctl-based flow acceptable as the new baseline for recurring tasks? (not sure if i have seen this conversation anywhere, or i might have missed it) |
You mean logging? Yeah I think journal logging is fine. |
ekohl
left a comment
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'd like to take a step back and ask if there's a better and more native way in Foreman to do this.
Instead of having a huge sprawl of tasks, we should ask ourselves if there's a better way. In foreman-tasks we have recurring logic and perhaps we can find a way to bring that to core Foreman.
Perhaps a short term hack is to create rake tasks in core:
foreman-rake cron:hourlyforeman-rake cron:dailyforeman-rake cron:weeklyforeman-rake cron:monthly
Then individual other tasks can add themselves as prerequisites. Plugins can do the same so you wouldn't need to think about individual cronjobs for plugins. The upside is that you only load the whole of Foreman once (which makes it faster if you perform multiple tasks), but the downside is that if one crashes the later tasks may not run.
A slightly more advanced approach is to build a registry similar to what upgrade:run does. If there is recurring logic present then perhaps that could automatically take it over.
|
I like the idea with |
5119bb4 to
23458ae
Compare
|
@evgeni @ekohl So based on the For this PR I’d still like to get the recurring infra + timers in as a first iteration, and then do the switch to |
evgeni
left a comment
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.
nitpicks and some minor questions
|
Here is the final diff I applied locally when testing things: diff --git src/roles/foreman/tasks/main.yaml src/roles/foreman/tasks/main.yaml
index 291edc9..9d277d4 100644
--- src/roles/foreman/tasks/main.yaml
+++ src/roles/foreman/tasks/main.yaml
@@ -161,7 +161,7 @@
- worker-hosts-queue
- name: Define templated Quadlet for recurring Foreman rake tasks
- when: foreman_recurring_tasks_enabled | default(true)
+ when: foreman_recurring_tasks_enabled
loop: "{{ foreman_recurring_tasks }}"
loop_control:
label: "{{ item.instance }}"
@@ -173,9 +173,7 @@
sdnotify: false
network: host
hostname: "{{ ansible_facts['fqdn'] }}"
- user: foreman
- working_dir: /usr/share/foreman
- command: "bash -lc 'foreman-rake {{ item.rake }}'"
+ command: "foreman-rake {{ item.rake }}"
volume:
- 'foreman-data-run:/var/run/foreman:z'
secrets:
@@ -188,18 +186,12 @@
- 'foreman-client-cert,type=mount,target=/etc/foreman/client_cert.pem'
- 'foreman-client-key,type=mount,target=/etc/foreman/client_key.pem'
quadlet_options:
- - |
- [Install]
- WantedBy=default.target foreman.target
- |
[Unit]
PartOf=foreman.target
- Requires=foreman.service
- After=foreman.service
StartLimitIntervalSec=0
- |
[Service]
- ExecStartPre=/usr/bin/flock -n /run/foreman-recurring-%i.lock -c /usr/bin/true
TimeoutStartSec=30m
TimeoutStopSec=2m
KillMode=mixed
@@ -261,7 +252,7 @@
register: foreman_status
- name: Enable & start recurring timers
- when: foreman_recurring_tasks_enabled | default(true)
+ when: foreman_recurring_tasks_enabled
ansible.builtin.systemd:
name: "foreman-recurring@{{ item.instance }}.timer"
enabled: true
diff --git src/roles/foreman/templates/[email protected] src/roles/foreman/templates/[email protected]
index b22dcbe..7d8a3e2 100644
--- src/roles/foreman/templates/[email protected]
+++ src/roles/foreman/templates/[email protected]
@@ -9,4 +9,6 @@ RandomizedDelaySec=120
AccuracySec=1min
[Install]
-WantedBy=timers.target
+WantedBy=timers.target foreman.target
+[Unit]
+PartOf=foreman.targetworks perfectly fine! thanks a ton for working on this! |
|
yeah seems like everything is working perfectly \o/ |
evgeni
left a comment
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.
dev-ack!
- define templated Quadlet container `[email protected]` via `containers.podman.podman_container` (state: quadlet) - run rake tasks inside the foreman image with same secrets/mounts as foreman.service - so far added per-instance timers for: - reports:daily - db:sessions:clear - reports:expire - audits:expire Refs: theforeman#61
491d676 to
711d4a2
Compare
shubhamsg199
left a comment
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.
ACK, Tested and works as expected.
[email protected]viacontainers.podman.podman_container(state: quadlet)foreman.servicereports:dailydb:sessions:clearreports:expireaudits:expireRefs: #61 and #252