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

feat: lazy timer commands #28

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cookbooks/fb_timers/README.md
Original file line number Diff line number Diff line change
@@ -65,7 +65,8 @@ Required fields:
when you want your job to run. Corresponds to the `OnCalendar` field of the
systemd timer. See below for helpers to generate common calendar patterns.
* `command`: The command to run. Corresponds to the `ExecStart` field of the
systemd service.
systemd service. Specify a Proc to lazily evaluate the command string, useful
for an attribute-driven command.
* `commands`: The commands to run. Will generate several `ExecStart` lines.
Useful if you want to run multiple commands in sequence, without forking to
bash. Mixing `commands` and `command` will produce a warning, but the
4 changes: 4 additions & 0 deletions cookbooks/fb_timers/spec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -156,6 +156,10 @@
'command' => '/usr/local/bin/foobar.sh',
'timer_options' => { 'OnBootSec' => '1s' },
},
'lazy' => {
'calendar' => '*:0/15:0',
'command' => proc { '/usr/local/bin/foobar.sh' },
},
}
end
end
12 changes: 12 additions & 0 deletions cookbooks/fb_timers/spec/fixtures/default/lazy.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file managed by chef.
# Local changes to this file will be overwritten.

[Unit]
Description=Run scheduled task lazy
After=network.target

[Service]
Type=oneshot
Slice=system-timers-lazy.slice
ExecStart=/usr/local/bin/foobar.sh
TimeoutStopSec=90s
15 changes: 15 additions & 0 deletions cookbooks/fb_timers/spec/fixtures/default/lazy.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file managed by chef.
# Local changes to this file will be overwritten.

[Unit]
Description=Run scheduled task lazy

[Install]
WantedBy=timers.target

[Timer]
OnCalendar=*:0/15:0
AccuracySec=1s
Persistent=false
RandomizedDelaySec=0s
Unit=lazy.service
2 changes: 1 addition & 1 deletion cookbooks/fb_timers/templates/default/service.erb
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ EnvironmentFile=<%= @conf['envfile'] %>
Slice=system-timers-<%= @conf['name'] %>.slice
<% end %>
<% @conf['commands'].each do |command| %>
ExecStart=<%= command %>
ExecStart=<%= if command.instance_of?(Proc) then command.call() else command end %>
<% end %>
<% if @conf['timeout'] %>
TimeoutStartSec=<%= @conf['timeout'] %>