Class: Locd::Agent::Job

Inherits:
Locd::Agent show all
Defined in:
lib/locd/agent/job.rb

Overview

A user-defined agent that runs periodically to perform a task.

Direct Known Subclasses

RotateLogs

Defined Under Namespace

Modules: Types

Constant Summary

Constants inherited from Locd::Agent

TO_H_NAMES

Instance Attribute Summary

Attributes inherited from Locd::Agent

#path, #plist

Creating Servers collapse

Class Method Summary collapse

Methods inherited from Locd::Agent

#<=>, add, add_or_update, all, class_for, #cmd_template, #config, default_log_path, #default_log_path?, #err_path, exists?, find_all, find_all!, find_only!, from_path, get, #initialize, #label, labels, #last_exit_code, #load, #log_paths, #out_path, #pid, plist_abs_path, plists, #reload, #remove, render_cmd, resolve_log_path, #restart, #running?, #start, #status, #stop, #stopped?, #to_h, #to_json, #to_yaml, #unload, #update, user_plist_abs_dir, #workdir

Constructor Details

This class inherits a constructor from Locd::Agent

Class Method Details

.create_plist_data(cmd_template:, label:, workdir:, start_interval:, log_path: nil, keep_alive: false, run_at_load: false, **extras) ⇒ Hash<String, Object>

Create the launchd property list data for a new Site, which has an additional port: keyword versus Locd::Agent.create_plist_data.

Examples:

Run a job about every minute

Locd::Agent::Job.create_plist_date \
  cmd_template:     'myexe do-some-job',
  label:            'myexe.do-some-job',
  workdir:          '~',
  start_interval:   60

Run a job every hour, on the hour

Locd::Agent::Job.create_plist_date \
  cmd_template:     'myexe do-some-job',
  label:            'myexe.do-some-job',
  workdir:          '~',
  start_interval:   {
                      minute: 0,
                    }

Parameters:

  • start_interval: (Fixnum | Hash)

    How often to start the job:

    1. Fixnum - Run about every X number of seconds (positive integer).
    2. Hash

Returns:

  • (Hash<String, Object>)



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/locd/agent/job.rb', line 97

def self.create_plist_data  cmd_template:,
                            label:,
                            workdir:,
                            start_interval:,
                            log_path: nil,
                            keep_alive: false,
                            run_at_load: false,
                            **extras
  
  plist_data = super  cmd_template: cmd_template,
                      label: label,
                      workdir: workdir,
                      log_path: log_path,
                      keep_alive: keep_alive,
                      run_at_load: run_at_load,
                      **extras
  
  start_interval_data = t.match start_interval,
    t.pos_int,
      { "StartInterval" => start_interval },
    
    Types.start_calendar_interval,
      ->( interval ) {
        { 'StartCalendarInterval' =>
            interval.map { |key, value| [key.to_s.capitalize, value] }.to_h }
      },
    
    Types.start_calendar_intervals,
      ->( intervals ) {
        intervals.map { |interval|
          interval.map { |key, value| [key.to_s.capitalize, value] }.to_h
        }
      }
  
  plist_data.merge start_interval_data
end

.plist?(plist) ⇒ return_type

TODO:

Document plist? method.

Returns @todo Document return value.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



54
55
56
57
# File 'lib/locd/agent/job.rb', line 54

def self.plist? plist
  super( plist ) && ( plist.key?( 'StartInterval' ) ||
                      plist.key?( 'StartCalendarInterval' ) )
end