Sha256: 67dfed6e6467e31b2fa3f7f4ff492725ad9ed7fe8b973933e1405409e6af2e24

Contents?: true

Size: 1.02 KB

Versions: 21

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'tasks_scheduler/app_gem'

module TasksScheduler
  class Daemon
    ACTIONS = %w[status start stop restart].freeze

    class << self
      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

      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

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

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tasks_scheduler-0.7.0 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.12 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.11 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.10 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.9 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.8 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.7 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.6 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.5 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.4 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.3 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.2 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.1 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.6.0 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.5.4 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.5.3 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.5.2 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.5.1 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.5.0 lib/tasks_scheduler/daemon.rb
tasks_scheduler-0.4.2 lib/tasks_scheduler/daemon.rb