Class: ActiveWorker::Configuration
Constant Summary
collapse
- POLLING_INTERVAL =
0.1
Class Method Summary
collapse
Instance Method Summary
collapse
canonicalize, get_as_flat_hash_by_root_object, get_as_hash_by_root_object, get_children_for, get_mongoid_collection, get_renderable_children_for, get_renderable_hash_by_root_object, renderable_hash_for_configuration
#get_root_object_id, included, #notify_root_of_child_started, #notify_root_of_finished, #set_root_object
Class Method Details
.after_launch(method) ⇒ Object
134
135
136
|
# File 'lib/active_worker/configuration.rb', line 134
def self.after_launch(method)
after_launch_methods << method
end
|
.after_launch_methods ⇒ Object
138
139
140
|
# File 'lib/active_worker/configuration.rb', line 138
def self.after_launch_methods
@after_launch_methods ||= []
end
|
.config_field(name, *args) ⇒ Object
121
122
123
124
|
# File 'lib/active_worker/configuration.rb', line 121
def self.config_field(name, *args)
field name, *args
config_fields << name
end
|
.config_fields ⇒ Object
130
131
132
|
# File 'lib/active_worker/configuration.rb', line 130
def self.config_fields
@config_fields ||= []
end
|
.controller_class ⇒ Object
104
105
106
|
# File 'lib/active_worker/configuration.rb', line 104
def self.controller_class
"#{self.parent}::Controller".constantize
end
|
.css_name ⇒ Object
112
113
114
|
# File 'lib/active_worker/configuration.rb', line 112
def self.css_name
name.split("::").join("_")
end
|
.display_name ⇒ Object
108
109
110
|
# File 'lib/active_worker/configuration.rb', line 108
def self.display_name
name.split("::").join(" ")
end
|
.template_field(name, *args) ⇒ Object
116
117
118
119
|
# File 'lib/active_worker/configuration.rb', line 116
def self.template_field(name, *args)
config_field(name, *args)
template_fields << name
end
|
.template_fields ⇒ Object
126
127
128
|
# File 'lib/active_worker/configuration.rb', line 126
def self.template_fields
@template_fields ||= []
end
|
Instance Method Details
#collect_after_launch_configurations(configurations) ⇒ Object
36
37
38
|
# File 'lib/active_worker/configuration.rb', line 36
def collect_after_launch_configurations(configurations)
self.class.after_launch_methods.map { |method| send(method, configurations) }.flatten
end
|
#completed? ⇒ Boolean
75
76
77
|
# File 'lib/active_worker/configuration.rb', line 75
def completed?
FinishedEvent.where(configuration_id: id).count > 0
end
|
#configurations_for_events ⇒ Object
48
49
50
|
# File 'lib/active_worker/configuration.rb', line 48
def configurations_for_events
[self]
end
|
#defined_fields ⇒ Object
61
62
63
|
# File 'lib/active_worker/configuration.rb', line 61
def defined_fields
attributes.select { |k, v| self.class.config_fields.include? k.to_sym }
end
|
#enqueue_job ⇒ Object
52
53
54
55
|
# File 'lib/active_worker/configuration.rb', line 52
def enqueue_job
self.class.controller_class.run_remotely.execute_expanded(self.id)
self
end
|
#event_name ⇒ Object
65
66
67
68
69
|
# File 'lib/active_worker/configuration.rb', line 65
def event_name
parts = self.class.name.split("::")
parts.pop
parts.join(" ")
end
|
#expand_for_threads ⇒ Object
44
45
46
|
# File 'lib/active_worker/configuration.rb', line 44
def expand_for_threads
[self]
end
|
#expand_for_workers ⇒ Object
40
41
42
|
# File 'lib/active_worker/configuration.rb', line 40
def expand_for_workers
[self]
end
|
#finished ⇒ Object
87
88
89
|
# File 'lib/active_worker/configuration.rb', line 87
def finished
FinishedEvent.create(configuration: self)
end
|
#launch ⇒ Object
29
30
31
32
33
34
|
# File 'lib/active_worker/configuration.rb', line 29
def launch
configurations = expand_for_workers
configurations.each(&:enqueue_job)
configurations += collect_after_launch_configurations(configurations)
configurations
end
|
#notified? ⇒ Boolean
95
96
97
|
# File 'lib/active_worker/configuration.rb', line 95
def notified?
NotificationEvent.where(configuration_id: id).count > 0
end
|
#notify ⇒ Object
91
92
93
|
# File 'lib/active_worker/configuration.rb', line 91
def notify
NotificationEvent.create(configuration: self)
end
|
#renderable_configurations ⇒ Object
71
72
73
|
# File 'lib/active_worker/configuration.rb', line 71
def renderable_configurations
configurations.select { |c| c.renderable }
end
|
#set_flags ⇒ Object
99
100
101
102
|
# File 'lib/active_worker/configuration.rb', line 99
def set_flags
self.flags = parent_configuration.flags if parent_configuration
true
end
|
#started ⇒ Object
83
84
85
|
# File 'lib/active_worker/configuration.rb', line 83
def started
StartedEvent.create(configuration: self)
end
|
#supported_child_configurations ⇒ Object
57
58
59
|
# File 'lib/active_worker/configuration.rb', line 57
def supported_child_configurations
[]
end
|
#wait_until_completed ⇒ Object
79
80
81
|
# File 'lib/active_worker/configuration.rb', line 79
def wait_until_completed
sleep(POLLING_INTERVAL) until completed?
end
|