Class: Bumbleworks::Task
Defined Under Namespace
Modules: Base
Classes: AlreadyClaimed, AvailabilityTimeout, CompletionFailed, Finder, MissingWorkitem, NotCompletable
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem).
-
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem).
-
#call_after_hooks(action, *args) ⇒ Object
-
#call_before_hooks(action, *args) ⇒ Object
-
#claim(token, options = {}) ⇒ Object
Claim task and assign token to claimant.
-
#claimant ⇒ Object
Token used to claim task, nil if not claimed.
-
#claimed? ⇒ Boolean
-
#claimed_at ⇒ Object
Timestamp of last claim, nil if not currently claimed.
-
#complete(metadata = {}, options = {}) ⇒ Object
proceed workitem (saving changes to fields).
-
#extend_module ⇒ Object
-
#humanize(options = {}) ⇒ Object
-
#initialize(workitem) ⇒ Task
constructor
-
#log(action, metadata = {}) ⇒ Object
-
#on_dispatch ⇒ Object
-
#release(options = {}) ⇒ Object
-
#reload ⇒ Object
-
#role ⇒ Object
-
#task_module ⇒ Object
-
#temporary_storage ⇒ Object
-
#titleize(options = {}) ⇒ Object
-
#to_s(options = {}) ⇒ Object
-
#update(metadata = {}, options = {}) ⇒ Object
update workitem with changes to fields & params.
-
#with_hooks(action, metadata, options = {}) ⇒ Object
#==, #eql?, #hash, #identifier_for_comparison
#entity_storage_workitem, #wrapped_workitem
Constructor Details
#initialize(workitem) ⇒ Task
61
62
63
64
65
66
67
68
|
# File 'lib/bumbleworks/task.rb', line 61
def initialize(workitem)
@workitem = workitem
unless workitem && workitem.is_a?(::Ruote::Workitem)
raise ArgumentError, "Not a valid workitem"
end
@nickname = params['task']
extend_module
end
|
Instance Attribute Details
#nickname ⇒ Object
Returns the value of attribute nickname.
18
19
20
|
# File 'lib/bumbleworks/task.rb', line 18
def nickname
@nickname
end
|
#workitem ⇒ Object
Returns the value of attribute workitem.
18
19
20
|
# File 'lib/bumbleworks/task.rb', line 18
def workitem
@workitem
end
|
Class Method Details
.autoload_all(options = {}) ⇒ Object
Autoload all task modules defined in files in the tasks_directory. The symbol for autoload comes from the camelized version of the filename, so this method is dependent on following that convention. For example, file ‘chew_cud_task.rb` should define `ChewCudTask`.
33
34
35
36
37
38
39
|
# File 'lib/bumbleworks/task.rb', line 33
def autoload_all(options = {})
if directory = options[:directory] || Bumbleworks.tasks_directory
Bumbleworks::Support.all_files(directory, :camelize => true).each do |path, name|
Object.autoload name.to_sym, path
end
end
end
|
.find_by_id(sid) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/bumbleworks/task.rb', line 48
def find_by_id(sid)
workitem = storage_participant[sid] if sid
raise MissingWorkitem unless workitem
new(workitem)
rescue ArgumentError => e
raise MissingWorkitem, e.message
end
|
.method_missing(method, *args, &block) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/bumbleworks/task.rb', line 41
def method_missing(method, *args, &block)
if Finder.new.respond_to?(method)
return Finder.new(self).send(method, *args, &block)
end
super
end
|
.storage_participant ⇒ Object
56
57
58
|
# File 'lib/bumbleworks/task.rb', line 56
def storage_participant
Bumbleworks.dashboard.storage_participant
end
|
Instance Method Details
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem)
76
77
78
|
# File 'lib/bumbleworks/task.rb', line 76
def [](key)
fields[key]
end
|
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem)
81
82
83
|
# File 'lib/bumbleworks/task.rb', line 81
def []=(key, value)
fields[key] = value
end
|
#call_after_hooks(action, *args) ⇒ Object
107
108
109
|
# File 'lib/bumbleworks/task.rb', line 107
def call_after_hooks(action, *args)
call_hooks(:after, action, *args)
end
|
#call_before_hooks(action, *args) ⇒ Object
103
104
105
|
# File 'lib/bumbleworks/task.rb', line 103
def call_before_hooks(action, *args)
call_hooks(:before, action, *args)
end
|
#claim(token, options = {}) ⇒ Object
Claim task and assign token to claimant
149
150
151
152
153
154
|
# File 'lib/bumbleworks/task.rb', line 149
def claim(token, options = {})
with_hooks(:claim, token, options) do
set_claimant(token)
log(:claim)
end
end
|
#claimant ⇒ Object
Token used to claim task, nil if not claimed
139
140
141
|
# File 'lib/bumbleworks/task.rb', line 139
def claimant
params['claimant']
end
|
#claimed? ⇒ Boolean
157
158
159
|
# File 'lib/bumbleworks/task.rb', line 157
def claimed?
!claimant.nil?
end
|
#claimed_at ⇒ Object
Timestamp of last claim, nil if not currently claimed
144
145
146
|
# File 'lib/bumbleworks/task.rb', line 144
def claimed_at
params['claimed_at']
end
|
#complete(metadata = {}, options = {}) ⇒ Object
proceed workitem (saving changes to fields)
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/bumbleworks/task.rb', line 126
def complete(metadata = {}, options = {})
unless completable? || options.fetch(:force, false)
raise NotCompletable.new(not_completable_error_message)
end
with_hooks(:update, metadata, options) do
with_hooks(:complete, metadata, options) do
proceed_workitem
log(:complete, metadata)
end
end
end
|
#extend_module ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/bumbleworks/task.rb', line 89
def extend_module
extend Bumbleworks::Task::Base
begin
extend task_module if nickname
rescue NameError
end
end
|
#humanize(options = {}) ⇒ Object
193
194
195
|
# File 'lib/bumbleworks/task.rb', line 193
def humanize(options = {})
displayify(:humanize, options)
end
|
#log(action, metadata = {}) ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/bumbleworks/task.rb', line 175
def log(action, metadata = {})
Bumbleworks.logger.info({
:actor => params['claimant'],
:action => action,
:target_type => 'Task',
:target_id => id,
:metadata => metadata.merge(:current_fields => fields)
})
end
|
#on_dispatch ⇒ Object
170
171
172
173
|
# File 'lib/bumbleworks/task.rb', line 170
def on_dispatch
log(:dispatch)
call_after_hooks(:dispatch)
end
|
#release(options = {}) ⇒ Object
162
163
164
165
166
167
168
|
# File 'lib/bumbleworks/task.rb', line 162
def release(options = {})
current_claimant = claimant
with_hooks(:release, current_claimant, options) do
log(:release)
set_claimant(nil)
end
end
|
#reload ⇒ Object
70
71
72
73
|
# File 'lib/bumbleworks/task.rb', line 70
def reload
@workitem = storage_participant[sid]
self
end
|
#role ⇒ Object
85
86
87
|
# File 'lib/bumbleworks/task.rb', line 85
def role
participant_name
end
|
#task_module ⇒ Object
97
98
99
100
101
|
# File 'lib/bumbleworks/task.rb', line 97
def task_module
return nil unless nickname
klass_name = Bumbleworks::Support.camelize(nickname)
klass = Bumbleworks::Support.constantize("#{klass_name}Task")
end
|
#temporary_storage ⇒ Object
21
22
23
|
# File 'lib/bumbleworks/task.rb', line 21
def temporary_storage
@temporary_storage ||= {}
end
|
#titleize(options = {}) ⇒ Object
189
190
191
|
# File 'lib/bumbleworks/task.rb', line 189
def titleize(options = {})
displayify(:titleize, options)
end
|
#to_s(options = {}) ⇒ Object
185
186
187
|
# File 'lib/bumbleworks/task.rb', line 185
def to_s(options = {})
titleize(options)
end
|
#update(metadata = {}, options = {}) ⇒ Object
update workitem with changes to fields & params
118
119
120
121
122
123
|
# File 'lib/bumbleworks/task.rb', line 118
def update(metadata = {}, options = {})
with_hooks(:update, metadata, options) do
update_workitem
log(:update, metadata)
end
end
|
#with_hooks(action, metadata, options = {}) ⇒ Object
111
112
113
114
115
|
# File 'lib/bumbleworks/task.rb', line 111
def with_hooks(action, metadata, options = {})
call_before_hooks(action, metadata) unless options[:skip_callbacks]
yield
call_after_hooks(action, metadata) unless options[:skip_callbacks]
end
|