Class: ProcessBot::Process::Handlers::Custom

Inherits:
Object
  • Object
show all
Defined in:
lib/process_bot/process/handlers/custom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ Custom

Returns a new instance of Custom.



4
5
6
7
# File 'lib/process_bot/process/handlers/custom.rb', line 4

def initialize(process)
  @process = process
  @options = process.options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/process_bot/process/handlers/custom.rb', line 2

def options
  @options
end

#processObject (readonly)

Returns the value of attribute process.



2
3
4
# File 'lib/process_bot/process/handlers/custom.rb', line 2

def process
  @process
end

Instance Method Details

#current_pidObject



9
10
11
# File 'lib/process_bot/process/handlers/custom.rb', line 9

def current_pid
  process.current_pid
end

#daemonizeObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/process_bot/process/handlers/custom.rb', line 13

def daemonize
  logger.logs "Daemonize!"

  pid = Process.fork do
    Process.daemon
    yield
  end

  Process.detach(pid) if pid
end

#false_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/process_bot/process/handlers/custom.rb', line 24

def false_value?(value)
  !value || value == "false"
end

#fetch(*args, **opts) ⇒ Object



28
29
30
# File 'lib/process_bot/process/handlers/custom.rb', line 28

def fetch(*args, **opts)
  options.fetch(*args, **opts)
end

#loggerObject



32
33
34
# File 'lib/process_bot/process/handlers/custom.rb', line 32

def logger
  @logger ||= ProcessBot::Logger.new(options: options)
end

#set(*args, **opts) ⇒ Object



42
43
44
# File 'lib/process_bot/process/handlers/custom.rb', line 42

def set(*args, **opts)
  options.set(*args, **opts)
end

#set_option(key, value) ⇒ Object



36
37
38
39
40
# File 'lib/process_bot/process/handlers/custom.rb', line 36

def set_option(key, value)
  raise "Unknown option for Sidekiq handler: #{key}" unless options.key?(key)

  set(key, value)
end

#start_commandObject



46
47
48
# File 'lib/process_bot/process/handlers/custom.rb', line 46

def start_command
  "bash -c 'cd #{options.fetch(:release_path)} && #{options.options.fetch(:custom_command)}'"
end

#stop(**_args) ⇒ Object



50
51
52
53
# File 'lib/process_bot/process/handlers/custom.rb', line 50

def stop(**_args)
  puts "Stop related processes"
  process.runner.stop_related_processes
end