Class: Bumbleworks::Task
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- WorkitemEntityStorage
- Defined in:
- lib/bumbleworks/task.rb,
lib/bumbleworks/task/base.rb,
lib/bumbleworks/task/finder.rb
Defined Under Namespace
Modules: Base
Classes: AlreadyClaimed, AvailabilityTimeout, Finder, MissingWorkitem, NotCompletable
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#entity_storage_workitem
Constructor Details
#initialize(workitem) ⇒ Task
Returns a new instance of Task.
55
56
57
58
59
60
61
62
|
# File 'lib/bumbleworks/task.rb', line 55
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.
16
17
18
|
# File 'lib/bumbleworks/task.rb', line 16
def nickname
@nickname
end
|
#workitem ⇒ Object
Returns the value of attribute workitem.
16
17
18
|
# File 'lib/bumbleworks/task.rb', line 16
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`.
27
28
29
30
31
32
33
|
# File 'lib/bumbleworks/task.rb', line 27
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
42
43
44
45
46
47
48
|
# File 'lib/bumbleworks/task.rb', line 42
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) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/bumbleworks/task.rb', line 35
def method_missing(method, *args)
if Finder.new.respond_to?(method)
return Finder.new([], self).send(method, *args)
end
super
end
|
.storage_participant ⇒ Object
50
51
52
|
# File 'lib/bumbleworks/task.rb', line 50
def storage_participant
Bumbleworks.dashboard.storage_participant
end
|
Instance Method Details
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem)
70
71
72
|
# File 'lib/bumbleworks/task.rb', line 70
def [](key)
fields[key]
end
|
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem)
75
76
77
|
# File 'lib/bumbleworks/task.rb', line 75
def []=(key, value)
fields[key] = value
end
|
#call_after_hooks(action, *args) ⇒ Object
101
102
103
|
# File 'lib/bumbleworks/task.rb', line 101
def call_after_hooks(action, *args)
call_hooks(:after, action, *args)
end
|
#call_before_hooks(action, *args) ⇒ Object
97
98
99
|
# File 'lib/bumbleworks/task.rb', line 97
def call_before_hooks(action, *args)
call_hooks(:before, action, *args)
end
|
#claim(token) ⇒ Object
Claim task and assign token to claimant
141
142
143
144
145
146
|
# File 'lib/bumbleworks/task.rb', line 141
def claim(token)
with_hooks(:claim, token) do
set_claimant(token)
log(:claim)
end
end
|
#claimant ⇒ Object
Token used to claim task, nil if not claimed
131
132
133
|
# File 'lib/bumbleworks/task.rb', line 131
def claimant
params['claimant']
end
|
#claimed? ⇒ Boolean
149
150
151
|
# File 'lib/bumbleworks/task.rb', line 149
def claimed?
!claimant.nil?
end
|
#claimed_at ⇒ Object
Timestamp of last claim, nil if not currently claimed
136
137
138
|
# File 'lib/bumbleworks/task.rb', line 136
def claimed_at
params['claimed_at']
end
|
#complete(metadata = {}) ⇒ Object
proceed workitem (saving changes to fields)
120
121
122
123
124
125
126
127
128
|
# File 'lib/bumbleworks/task.rb', line 120
def complete(metadata = {})
raise NotCompletable.new(not_completable_error_message) unless completable?
with_hooks(:update, metadata) do
with_hooks(:complete, metadata) do
proceed_workitem
log(:complete, metadata)
end
end
end
|
#extend_module ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/bumbleworks/task.rb', line 83
def extend_module
extend Bumbleworks::Task::Base
begin
extend task_module if nickname
rescue NameError
end
end
|
#humanize(options = {}) ⇒ Object
185
186
187
|
# File 'lib/bumbleworks/task.rb', line 185
def humanize(options = {})
displayify(:humanize, options)
end
|
#log(action, metadata = {}) ⇒ Object
167
168
169
170
171
172
173
174
175
|
# File 'lib/bumbleworks/task.rb', line 167
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
162
163
164
165
|
# File 'lib/bumbleworks/task.rb', line 162
def on_dispatch
log(:dispatch)
call_after_hooks(:dispatch)
end
|
#release ⇒ Object
154
155
156
157
158
159
160
|
# File 'lib/bumbleworks/task.rb', line 154
def release
current_claimant = claimant
with_hooks(:release, current_claimant) do
log(:release)
set_claimant(nil)
end
end
|
#reload ⇒ Object
64
65
66
67
|
# File 'lib/bumbleworks/task.rb', line 64
def reload
@workitem = storage_participant[sid]
self
end
|
#role ⇒ Object
79
80
81
|
# File 'lib/bumbleworks/task.rb', line 79
def role
participant_name
end
|
#titleize(options = {}) ⇒ Object
181
182
183
|
# File 'lib/bumbleworks/task.rb', line 181
def titleize(options = {})
displayify(:titleize, options)
end
|
#to_s(options = {}) ⇒ Object
177
178
179
|
# File 'lib/bumbleworks/task.rb', line 177
def to_s(options = {})
titleize(options)
end
|
#update(metadata = {}) ⇒ Object
update workitem with changes to fields & params
112
113
114
115
116
117
|
# File 'lib/bumbleworks/task.rb', line 112
def update(metadata = {})
with_hooks(:update, metadata) do
update_workitem
log(:update, metadata)
end
end
|
#with_hooks(action, *args, &block) ⇒ Object
105
106
107
108
109
|
# File 'lib/bumbleworks/task.rb', line 105
def with_hooks(action, *args, &block)
call_before_hooks(action, *args)
yield
call_after_hooks(action, *args)
end
|