Class: Do::Task
- Inherits:
-
Object
- Object
- Do::Task
- Defined in:
- lib/do/task.rb
Overview
A single declared task parsed from the TOML configuration.
Tasks are plain Ruby objects; the Validator is responsible for deciding whether their field values are acceptable. This class only carries data and exposes a few derived helpers.
Constant Summary collapse
- SCHEDULES =
%w[once hourly daily weekly monthly].freeze
- WEEKDAY_NAMES =
%w[monday tuesday wednesday thursday friday saturday sunday].freeze
- WEEKDAY_NUMBERS =
{ 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6, 'sunday' => 7 }.freeze
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#working_directory ⇒ Object
readonly
Returns the value of attribute working_directory.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
enabledis true by default for scheduled tasks and false for manual-only (unscheduled) tasks. -
#initialize(name:, command:, schedule: nil, time: nil, day: nil, working_directory: nil, environment: {}, enabled: nil, raw: {}) ⇒ Task
constructor
A new instance of Task.
- #scheduled? ⇒ Boolean
-
#service_unit ⇒ Object
Return the service unit name systemd will use for this task.
- #timer_unit ⇒ Object
Constructor Details
#initialize(name:, command:, schedule: nil, time: nil, day: nil, working_directory: nil, environment: {}, enabled: nil, raw: {}) ⇒ Task
Returns a new instance of Task.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/do/task.rb', line 18 def initialize(name:, command:, schedule: nil, time: nil, day: nil, working_directory: nil, environment: {}, enabled: nil, raw: {}) @name = name @command = command @schedule = schedule @time = time @day = day @working_directory = working_directory @environment = environment || {} @enabled = enabled @raw = raw end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
15 16 17 |
# File 'lib/do/task.rb', line 15 def command @command end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
15 16 17 |
# File 'lib/do/task.rb', line 15 def day @day end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
15 16 17 |
# File 'lib/do/task.rb', line 15 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/do/task.rb', line 15 def name @name end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
15 16 17 |
# File 'lib/do/task.rb', line 15 def raw @raw end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
15 16 17 |
# File 'lib/do/task.rb', line 15 def schedule @schedule end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
15 16 17 |
# File 'lib/do/task.rb', line 15 def time @time end |
#working_directory ⇒ Object (readonly)
Returns the value of attribute working_directory.
15 16 17 |
# File 'lib/do/task.rb', line 15 def working_directory @working_directory end |
Instance Method Details
#enabled? ⇒ Boolean
enabled is true by default for scheduled tasks and false for
manual-only (unscheduled) tasks.
33 34 35 36 37 38 |
# File 'lib/do/task.rb', line 33 def enabled? return scheduled? if @enabled.nil? return @enabled == 'true' || @enabled == true if @enabled.is_a?(String) !!@enabled end |
#scheduled? ⇒ Boolean
40 41 42 |
# File 'lib/do/task.rb', line 40 def scheduled? !@schedule.nil? && @schedule != '' end |
#service_unit ⇒ Object
Return the service unit name systemd will use for this task.
45 46 47 |
# File 'lib/do/task.rb', line 45 def service_unit "do-#{name}.service" end |
#timer_unit ⇒ Object
49 50 51 |
# File 'lib/do/task.rb', line 49 def timer_unit "do-#{name}.timer" end |