Can you elaborate on the “not needed”? Is that a user deciding “I don’t need that feature of the plugin” or is that the plugin saying “I don’t have data to fulfill the request”?
The audits job has something similar: If the audits_period setting is not set, it doesn’t know which audits to expire and just calls next to skip the execution.
You could either perform that decision in code directly, or also add a setting which the user can toggle.
I know there has been some talk to make those tasks actual Foreman tasks, so you can enable/disable them in the UI, but so far it didn’t happen yet.
settings do
setting('vault_cron_enabled',
full_name: N_('Vault Cronjobs enabled'),
type: :boolean,
description: N_('Enable or disable the Vault Cronjobs for managing policies and auth methods'),
default: false)
end
end
if Setting['vault_cron_enabled'] = true
# Register recurring task with Foreman::Cron framework
Foreman::Cron.register(:hourly, 'foreman_vault:policies:push')
Foreman::Cron.register(:hourly, 'foreman_vault:auth_methods:push')
end
I don’t write ruby often so please have mercy with my idea
The register happens on boot time of Foreman/Rails, so if you change the setting the currently running Rails process won’t know that change (well, it will know the setting changed, but the register/unregister won’t happen). But as the cron runs happen in a newly spawned Rails process anyway, it probably won’t hurt.
I’d do a next unless Setting['vault_cron_enabled'] inside the Rake job definition instead, but I guess that’s more a personal preference?
As I said, the actual execution of the cron job happens in a separate process, and that will have the right cron jobs registered.
Only if you go and build a Foreman::Cron dashboard (which doesn’t exist today), it would show wrong data.
Or if we move it into a persistent foreman-tasks process. I think your suggestion to skip it within the task itself is better. Now that we launch a rails process anyway there is no startup overhead for an individual job anymore.
agree that rails is already loaded for that invocation, so yeah there’s no separate rails startup for each job. and checking the setting inside the task and skipping its work seems like the right approach here. and the timer integration itself doesn’t add per-job enable/disable controls.