Class: Bumbleworks::Task
- Inherits:
-
Object
- Object
- Bumbleworks::Task
- Extended by:
- Forwardable
- Includes:
- WorkitemEntityStorage
- Defined in:
- lib/bumbleworks/task.rb,
lib/bumbleworks/task/finder.rb
Defined Under Namespace
Classes: AlreadyClaimed, AvailabilityTimeout, Finder, MissingWorkitem, NotCompletable
Instance Attribute Summary collapse
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#workitem ⇒ Object
readonly
Returns the value of attribute workitem.
Class Method Summary collapse
-
.autoload_all(options = {}) ⇒ Object
Autoload all task modules defined in files in the tasks_directory.
- .find_by_id(sid) ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .storage_participant ⇒ Object
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) ⇒ Object
Claim task and assign token to claimant.
-
#claimant ⇒ Object
Token used to claim task, nil if not claimed.
-
#claimed? ⇒ Boolean
true if task is claimed.
-
#claimed_at ⇒ Object
Timestamp of last claim, nil if not currently claimed.
-
#complete(metadata = {}) ⇒ Object
proceed workitem (saving changes to fields).
- #extend_module ⇒ Object
- #humanize(options = {}) ⇒ Object
-
#initialize(workitem) ⇒ Task
constructor
A new instance of Task.
- #log(action, metadata = {}) ⇒ Object
- #on_dispatch ⇒ Object
-
#release ⇒ Object
release claim on task.
- #reload ⇒ Object
- #role ⇒ Object
- #task_module ⇒ Object
- #titleize(options = {}) ⇒ Object
- #to_s(options = {}) ⇒ Object
-
#update(metadata = {}) ⇒ Object
update workitem with changes to fields & params.
- #with_hooks(action, *args, &block) ⇒ Object
Methods included from WorkitemEntityStorage
#entity, #entity_fields, #has_entity?, #has_entity_fields?
Constructor Details
#initialize(workitem) ⇒ Task
Returns a new instance of Task.
54 55 56 57 58 59 60 61 |
# File 'lib/bumbleworks/task.rb', line 54 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 (readonly)
Returns the value of attribute nickname.
16 17 18 |
# File 'lib/bumbleworks/task.rb', line 16 def nickname @nickname end |
#workitem ⇒ Object (readonly)
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 |
# File 'lib/bumbleworks/task.rb', line 27 def autoload_all( = {}) [:directory] ||= Bumbleworks.tasks_directory Bumbleworks::Support.all_files([:directory], :camelize => true).each do |path, name| Object.autoload name.to_sym, path end end |
.find_by_id(sid) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/bumbleworks/task.rb', line 41 def find_by_id(sid) workitem = storage_participant[sid] if sid raise MissingWorkitem unless workitem new(workitem) rescue ArgumentError => e raise MissingWorkitem, e. end |
.method_missing(method, *args) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/bumbleworks/task.rb', line 34 def method_missing(method, *args) if Finder.new.respond_to?(method) return Finder.new([], self).send(method, *args) end super end |
.storage_participant ⇒ Object
49 50 51 |
# File 'lib/bumbleworks/task.rb', line 49 def storage_participant Bumbleworks.dashboard.storage_participant end |
Instance Method Details
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem)
69 70 71 |
# File 'lib/bumbleworks/task.rb', line 69 def [](key) fields[key] end |
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem)
74 75 76 |
# File 'lib/bumbleworks/task.rb', line 74 def []=(key, value) fields[key] = value end |
#call_after_hooks(action, *args) ⇒ Object
98 99 100 |
# File 'lib/bumbleworks/task.rb', line 98 def call_after_hooks(action, *args) call_hooks(:after, action, *args) end |
#call_before_hooks(action, *args) ⇒ Object
94 95 96 |
# File 'lib/bumbleworks/task.rb', line 94 def call_before_hooks(action, *args) call_hooks(:before, action, *args) end |
#claim(token) ⇒ Object
Claim task and assign token to claimant
138 139 140 141 142 143 |
# File 'lib/bumbleworks/task.rb', line 138 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
128 129 130 |
# File 'lib/bumbleworks/task.rb', line 128 def claimant params['claimant'] end |
#claimed? ⇒ Boolean
true if task is claimed
146 147 148 |
# File 'lib/bumbleworks/task.rb', line 146 def claimed? !claimant.nil? end |
#claimed_at ⇒ Object
Timestamp of last claim, nil if not currently claimed
133 134 135 |
# File 'lib/bumbleworks/task.rb', line 133 def claimed_at params['claimed_at'] end |
#complete(metadata = {}) ⇒ Object
proceed workitem (saving changes to fields)
117 118 119 120 121 122 123 124 125 |
# File 'lib/bumbleworks/task.rb', line 117 def complete( = {}) raise NotCompletable.new() unless completable? with_hooks(:update, ) do with_hooks(:complete, ) do proceed_workitem log(:complete, ) end end end |
#extend_module ⇒ Object
82 83 84 85 86 |
# File 'lib/bumbleworks/task.rb', line 82 def extend_module extend Bumbleworks::Tasks::Base extend task_module if nickname rescue NameError end |
#humanize(options = {}) ⇒ Object
182 183 184 |
# File 'lib/bumbleworks/task.rb', line 182 def humanize( = {}) displayify(:humanize, ) end |
#log(action, metadata = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/bumbleworks/task.rb', line 164 def log(action, = {}) Bumbleworks.logger.info({ :actor => params['claimant'], :action => action, :target_type => 'Task', :target_id => id, :metadata => .merge(:current_fields => fields) }) end |
#on_dispatch ⇒ Object
159 160 161 162 |
# File 'lib/bumbleworks/task.rb', line 159 def on_dispatch log(:dispatch) call_after_hooks(:dispatch) end |
#release ⇒ Object
release claim on task.
151 152 153 154 155 156 157 |
# File 'lib/bumbleworks/task.rb', line 151 def release current_claimant = claimant with_hooks(:release, current_claimant) do log(:release) set_claimant(nil) end end |
#reload ⇒ Object
63 64 65 66 |
# File 'lib/bumbleworks/task.rb', line 63 def reload @workitem = storage_participant[sid] self end |
#role ⇒ Object
78 79 80 |
# File 'lib/bumbleworks/task.rb', line 78 def role participant_name end |
#task_module ⇒ Object
88 89 90 91 92 |
# File 'lib/bumbleworks/task.rb', line 88 def task_module return nil unless nickname klass_name = Bumbleworks::Support.camelize(nickname) klass = Bumbleworks::Support.constantize("#{klass_name}Task") end |
#titleize(options = {}) ⇒ Object
178 179 180 |
# File 'lib/bumbleworks/task.rb', line 178 def titleize( = {}) displayify(:titleize, ) end |
#to_s(options = {}) ⇒ Object
174 175 176 |
# File 'lib/bumbleworks/task.rb', line 174 def to_s( = {}) titleize() end |
#update(metadata = {}) ⇒ Object
update workitem with changes to fields & params
109 110 111 112 113 114 |
# File 'lib/bumbleworks/task.rb', line 109 def update( = {}) with_hooks(:update, ) do update_workitem log(:update, ) end end |
#with_hooks(action, *args, &block) ⇒ Object
102 103 104 105 106 |
# File 'lib/bumbleworks/task.rb', line 102 def with_hooks(action, *args, &block) call_before_hooks(action, *args) yield call_after_hooks(action, *args) end |