Class: TasksScheduler::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks_scheduler/daemon.rb

Constant Summary collapse

ACTIONS =
%w[status start stop restart].freeze

Class Method Summary collapse

Class Method Details

.daemon_command(action) ⇒ Object



10
11
12
13
14
15
# File 'lib/tasks_scheduler/daemon.rb', line 10

def daemon_command(action)
  raise "Action not allowed: #{action} (Allowed: #{ACTIONS})" unless ACTIONS.include?(action)

  ::TasksScheduler::AppGem.instance.bundle('exec', 'tasks_scheduler', action)
    .envvar(::TasksScheduler::Checker::LOG_ON_FILE_ENV_KEY, '1')
end

.env_args_to_s(command) ⇒ Object



31
32
33
# File 'lib/tasks_scheduler/daemon.rb', line 31

def env_args_to_s(command)
  command.send(:extra_options).fetch(:envvars).map { |k, v| "#{k}=#{v}" }.join(' | ')
end

.execute(action) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/tasks_scheduler/daemon.rb', line 17

def execute(action)
  command = daemon_command(action)
  result = command.execute
  {
    action: action, env_args: env_args_to_s(command), command: command.to_s,
    status: result.fetch(:exit_code), stdout: result.fetch(:stdout),
    stderr: result.fetch(:stderr)
  }
end

.running?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/tasks_scheduler/daemon.rb', line 27

def running?
  execute('status')[:status].zero?
end