Class: Exekutor::Internal::CLI::Manager

Inherits:
Object
  • Object
show all
Includes:
ApplicationLoader
Defined in:
lib/exekutor/internal/cli/manager.rb

Overview

Manager for the CLI

Defined Under Namespace

Classes: ConfigLoader, DefaultConfigFileValue, DefaultPidFileValue, Error

Constant Summary

Constants included from ApplicationLoader

ApplicationLoader::LOADING_MESSAGE

Instance Method Summary collapse

Methods included from ApplicationLoader

#clear_application_loading_message, #different_time_zone?, #load_application, #print_time_zone_warning

Constructor Details

#initialize(options) ⇒ Manager

Returns a new instance of Manager.



16
17
18
# File 'lib/exekutor/internal/cli/manager.rb', line 16

def initialize(options)
  @global_options = options
end

Instance Method Details

#restart(stop_options, start_options) ⇒ Void

Restarts a daemonized worker

Returns:

  • (Void)


70
71
72
73
# File 'lib/exekutor/internal/cli/manager.rb', line 70

def restart(stop_options, start_options)
  stop stop_options.merge(restart: true)
  start start_options.merge(restart: true, daemonize: true)
end

#start(options) ⇒ Void

Starts a new worker

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :restart (Boolean)

    Whether the worker is being restarted

  • :daemonize (Boolean)

    Whether the worker should be daemonized

  • :environment (String)

    The Rails environment to load

  • :queue (String)

    The queue(s) to watch

  • :threads (String)

    The number of threads to use for job execution

  • :priority (String)

    The priorities to execute

  • :poll_interval (Integer)

    The interval in seconds for job polling

Returns:

  • (Void)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exekutor/internal/cli/manager.rb', line 29

def start(options)
  Process.setproctitle "Exekutor worker (Initializing…) [#{$PROGRAM_NAME}]"
  daemonize(restarting: options[:restart]) if options[:daemonize]

  load_application(options[:environment])

  # Specify `yield: true` to prevent running in the context of the loaded module
  ActiveSupport.on_load(:exekutor, yield: true) do
    worker_options = worker_options(options[:configfile], cli_worker_overrides(options))

    ActiveSupport.on_load(:active_record, yield: true) do
      start_and_join_worker(worker_options, options[:daemonize])
    end
  end
end

#stop(options) ⇒ Void

Stops a daemonized worker

Returns:

  • (Void)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/exekutor/internal/cli/manager.rb', line 47

def stop(options)
  daemon = Daemon.new(pidfile: pidfile)
  pid = daemon.pid
  if pid.nil?
    unless quiet?
      if options[:restart]
        puts "Executor was not running"
      else
        puts "Executor is not running (pidfile not found at #{daemon.pidfile})"
      end
    end
    return
  elsif daemon.status? :not_running, :dead
    return
  end

  Process.kill("INT", pid)
  wait_for_process_end(daemon, pid, shutdown_timeout(options))
  puts "Worker (PID: #{pid}) stopped." unless quiet?
end