Class: Wheneverd::DSL::Context
- Inherits:
-
Object
- Object
- Wheneverd::DSL::Context
- Defined in:
- lib/wheneverd/dsl/context.rb
Overview
The evaluation context used for schedule files.
The schedule file is evaluated via instance_eval, so methods defined here become available
as the schedule DSL (every, command, shell).
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Absolute schedule path.
-
#schedule ⇒ Wheneverd::Schedule
readonly
Schedule being built during evaluation.
Instance Method Summary collapse
-
#command(command_value) ⇒ void
Add a oneshot command job to the current
everyentry. -
#every(*periods, at: nil, &block) ⇒ Wheneverd::Entry
Define a scheduled entry and evaluate its jobs block.
-
#initialize(path:) ⇒ Context
constructor
A new instance of Context.
-
#service(name, command: nil, shell: nil, restart: "always", restart_sec: "5s", service: {}) ⇒ Wheneverd::Service
Add a long-running systemd user service to the schedule.
-
#shell(script, shell: "/bin/bash") ⇒ void
Add a oneshot command job that runs via
/bin/bash -lc.
Constructor Details
Instance Attribute Details
#path ⇒ String (readonly)
Returns absolute schedule path.
11 12 13 |
# File 'lib/wheneverd/dsl/context.rb', line 11 def path @path end |
#schedule ⇒ Wheneverd::Schedule (readonly)
Returns schedule being built during evaluation.
14 15 16 |
# File 'lib/wheneverd/dsl/context.rb', line 14 def schedule @schedule end |
Instance Method Details
#command(command_value) ⇒ void
This method returns an undefined value.
Add a oneshot command job to the current every entry.
55 56 57 58 59 60 61 |
# File 'lib/wheneverd/dsl/context.rb', line 55 def command(command_value) ensure_in_every_block!("command") @current_entry.add_job(Wheneverd::Job::Command.new(command: command_value)) rescue Wheneverd::InvalidCommandError => e raise LoadError.new(e., path: path) end |
#every(*periods, at: nil, &block) ⇒ Wheneverd::Entry
Define a scheduled entry and evaluate its jobs block.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wheneverd/dsl/context.rb', line 29 def every(*periods, at: nil, &block) raise InvalidPeriodError.new("every() requires a block", path: path) unless block raise InvalidPeriodError.new("every() requires a period", path: path) if periods.empty? period = periods.length == 1 ? periods.first : periods trigger = @period_parser.trigger_for(period, at: at) entry = Wheneverd::Entry.new(trigger: trigger) schedule.add_entry(entry) with_current_entry(entry) { instance_eval(&block) } entry end |
#service(name, command: nil, shell: nil, restart: "always", restart_sec: "5s", service: {}) ⇒ Wheneverd::Service
Add a long-running systemd user service to the schedule.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/wheneverd/dsl/context.rb', line 93 def service(name, command: nil, shell: nil, restart: "always", restart_sec: "5s", service: {}) command_value = normalize_service_command(command: command, shell: shell) service_obj = Wheneverd::Service.new( name: name, command: command_value, restart: restart, restart_sec: restart_sec, service: service ) schedule.add_service(service_obj) service_obj rescue Wheneverd::InvalidCommandError => e raise LoadError.new(e., path: path) end |
#shell(script, shell: "/bin/bash") ⇒ void
This method returns an undefined value.
Add a oneshot command job that runs via /bin/bash -lc.
71 72 73 74 75 76 |
# File 'lib/wheneverd/dsl/context.rb', line 71 def shell(script, shell: "/bin/bash") ensure_in_every_block!("shell") script_stripped = normalize_shell_script(script) shell_executable = normalize_shell_executable(shell) command([shell_executable, "-lc", script_stripped]) end |