Class: Employer::Employees::ThreadingEmployee
Instance Attribute Summary
#job, #logger
Instance Method Summary
collapse
before_fork, before_fork_hooks, #free?, #initialize, #perform_job, #stop_working, #wait_for_completion, #work_completed?, #work_failed?, #work_in_progress?
Instance Method Details
#force_work_stop ⇒ Object
31
32
33
34
35
|
# File 'lib/employer/employees/threading_employee.rb', line 31
def force_work_stop
return if free?
@thread.kill
@work_state = :failed
end
|
#free ⇒ Object
21
22
23
24
|
# File 'lib/employer/employees/threading_employee.rb', line 21
def free
super
@thread = nil
end
|
#work(job) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/employer/employees/threading_employee.rb', line 6
def work(job)
super
@work_state = :busy
@thread = Thread.new do
begin
perform_job
@work_state = :complete
rescue => exception
ensure
@work_state = :failed if @work_state == :busy
end
end
end
|
#work_state(wait = false) ⇒ Object
26
27
28
29
|
# File 'lib/employer/employees/threading_employee.rb', line 26
def work_state(wait = false)
@thread.join if wait && @thread
return @work_state
end
|