Class: Assistor::Assistant

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/assistor/assistant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, job) ⇒ Assistant

Returns a new instance of Assistant.



9
10
11
12
# File 'lib/assistor/assistant.rb', line 9

def initialize(configuration, job)
  @configuration = configuration
  @job = job
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/assistor/assistant.rb', line 7

def pid
  @pid
end

Instance Method Details

#assistObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/assistor/assistant.rb', line 22

def assist
  @pid = Process.fork do
    start
    process
    stop
  end
  detach
rescue => e
  log_file.error e
end

#assists?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/assistor/assistant.rb', line 33

def assists?
  Process.kill(0, pid)
rescue Errno::ESRCH
  false
end

#idObject



14
15
16
# File 'lib/assistor/assistant.rb', line 14

def id
  @id ||= [@configuration.id, @job.id].join ':'
end

#nameObject



18
19
20
# File 'lib/assistor/assistant.rb', line 18

def name
  @name ||= [:assistor, id].join ':'
end