Class: ActiveWorker::Controller
Constant Summary
JobQueue::RunRemotely::RESQUE, JobQueue::RunRemotely::THREADED
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
after_fork, cleanup_after_children, execute_concurrently, execute_fork, execute_thread, forked?, forking?, in_fork, in_thread, kill_children, local_worker_mode, local_worker_mode=, parent?, pids, reset_mongoid, reset_resque, role, role=, set_process_name, threaded?, threads, wait_for_children
run_remotely, worker_mode, worker_mode=
Constructor Details
#initialize(configuration) ⇒ Controller
Returns a new instance of Controller.
84
85
86
87
|
# File 'lib/active_worker/controller.rb', line 84
def initialize(configuration)
@configuration = configuration
setup
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
6
7
8
|
# File 'lib/active_worker/controller.rb', line 6
def configuration
@configuration
end
|
Class Method Details
.after_thread_launch(method) ⇒ Object
68
69
70
|
# File 'lib/active_worker/controller.rb', line 68
def self.after_thread_launch(method)
after_thread_launch_methods << method
end
|
.after_thread_launch_methods ⇒ Object
72
73
74
|
# File 'lib/active_worker/controller.rb', line 72
def self.after_thread_launch_methods
@after_thread_launch_methods ||= []
end
|
.execute(configuration) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/active_worker/controller.rb', line 21
def self.execute(configuration)
worker = new(configuration)
worker.started
worker.execute
worker.finished
end
|
.execute_expanded(configuration_id) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/active_worker/controller.rb', line 8
def self.execute_expanded(configuration_id)
config = Configuration.find(configuration_id)
configurations = config.expand_for_threads
execute_concurrently(configurations)
after_thread_launch_methods.each { |method| send(method, config, configurations) }
wait_for_children
ensure
worker_cleanup_methods.each { |method| send(method, configurations) }
end
|
.handle_error(error, method, params) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_worker/controller.rb', line 28
def self.handle_error(error, method, params)
configuration_id = params.shift
configuration = Configuration.find(configuration_id)
if threaded?
FailureEvent.from_error(configuration, error)
end
if forking? && parent?
ParentEvent.create_error_from_configuration(configuration, error)
kill_children
wait_for_children
end
if forked?
FailureEvent.create_error_from_configuration(configuration, error)
end
rescue Exception => e
puts "ERROR: While Handling #{error} Had : #{e}\n#{e.backtrace.join("\n")}"
end
|
.handle_termination(params) ⇒ Object
.worker_cleanup(method) ⇒ Object
76
77
78
|
# File 'lib/active_worker/controller.rb', line 76
def self.worker_cleanup(method)
worker_cleanup_methods << method
end
|
.worker_cleanup_methods ⇒ Object
80
81
82
|
# File 'lib/active_worker/controller.rb', line 80
def self.worker_cleanup_methods
@worker_cleanup_methods ||= []
end
|
Instance Method Details
#execute ⇒ Object
97
98
99
|
# File 'lib/active_worker/controller.rb', line 97
def execute
raise "Can't call execute on base controller #{configuration.inspect}'"
end
|
#finished ⇒ Object
101
102
103
|
# File 'lib/active_worker/controller.rb', line 101
def finished
configuration.finished
end
|
#setup ⇒ Object
89
90
91
|
# File 'lib/active_worker/controller.rb', line 89
def setup
end
|
#started ⇒ Object
93
94
95
|
# File 'lib/active_worker/controller.rb', line 93
def started
configuration.started
end
|