Module: QueueDispatcher::ActsAsTask::InstanceMethods
- Defined in:
- lib/queue_dispatcher/acts_as_task.rb
Instance Method Summary collapse
-
#aborted? ⇒ Boolean
Was this task aborted?.
-
#acquire_lock? ⇒ Boolean
Is this task pending?.
- #acts_as_task_task_queue ⇒ Object
-
#args ⇒ Object
Add task_id to the args.
-
#dependent_tasks_executed? ⇒ Boolean
Are all dependent_tasks executed?.
-
#dependent_tasks_had_errors ⇒ Object
Check recursive, if one or more of the tasks, which this task is dependent on had errors.
-
#error? ⇒ Boolean
Had this task error(s)?.
-
#execute! ⇒ Object
Execute task.
-
#executed? ⇒ Boolean
Was this task already executed?.
-
#init_queue? ⇒ Boolean
Is this task waiting until the queue is initialized?.
-
#md5 ⇒ Object
Calculate md5-Checksum.
-
#new? ⇒ Boolean
Is this task new?.
-
#pending? ⇒ Boolean
Is this task pending?.
-
#prosa ⇒ Object
Placeholder.
-
#running? ⇒ Boolean
Is this task running?.
-
#successful? ⇒ Boolean
Was this task finsihed successful?.
-
#update_message(args = {}) ⇒ Object
Update the attributes perc_finished and message according to the args.
-
#update_state(rc_and_msg) ⇒ Object
This method updates the task state according to the return code of their corresponding command.
Instance Method Details
#aborted? ⇒ Boolean
Was this task aborted?
139 140 141 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 139 def aborted? state == 'aborted' end |
#acquire_lock? ⇒ Boolean
Is this task pending?
115 116 117 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 115 def acquire_lock? acts_as_task_task_queue && acts_as_task_task_queue.running? && state == 'acquire_lock' end |
#acts_as_task_task_queue ⇒ Object
53 54 55 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 53 def acts_as_task_task_queue self.send(self.class.acts_as_task_config.task_queue_class_name) end |
#args ⇒ Object
Add task_id to the args
59 60 61 62 63 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 59 def args a = super a[-1] = a.last.merge(task_id: self.id) if a && a.instance_of?(Array) && a.last.instance_of?(Hash) a end |
#dependent_tasks_executed? ⇒ Boolean
Are all dependent_tasks executed?
157 158 159 160 161 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 157 def dependent_tasks_executed? state = true dependent_tasks.each{ |dt| state = false unless dt.executed? } state end |
#dependent_tasks_had_errors ⇒ Object
Check recursive, if one or more of the tasks, which this task is dependent on had errors
165 166 167 168 169 170 171 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 165 def dependent_tasks_had_errors error = false dependent_tasks.each do |t| error = true if t.state == 'error' || t.dependent_tasks_had_errors end error end |
#error? ⇒ Boolean
Had this task error(s)?
133 134 135 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 133 def error? state == 'error' || state.blank? end |
#execute! ⇒ Object
Execute task
188 189 190 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 188 def execute! target.send(method_name, *args) end |
#executed? ⇒ Boolean
Was this task already executed?
151 152 153 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 151 def executed? successful? || error? || aborted? end |
#init_queue? ⇒ Boolean
Is this task waiting until the queue is initialized?
145 146 147 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 145 def init_queue? state == 'init_queue' end |
#md5 ⇒ Object
Calculate md5-Checksum
180 181 182 183 184 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 180 def md5 attr_str = "" Task.attribute_names.each{ |a| attr_str += self.send(a).to_s } Digest('MD5').digest(attr_str) end |
#new? ⇒ Boolean
Is this task new?
103 104 105 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 103 def new? state == 'new' || state == 'new_popped' end |
#pending? ⇒ Boolean
Is this task pending?
109 110 111 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 109 def pending? acts_as_task_task_queue && state == 'new' end |
#prosa ⇒ Object
Placeholder. Please override it in your model.
175 176 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 175 def prosa end |
#running? ⇒ Boolean
Is this task running?
121 122 123 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 121 def running? acts_as_task_task_queue && acts_as_task_task_queue.running? && state == 'running' end |
#successful? ⇒ Boolean
Was this task finsihed successful?
127 128 129 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 127 def successful? state == 'successful' || state == 'finished' end |
#update_message(args = {}) ⇒ Object
Update the attributes perc_finished and message according to the args
93 94 95 96 97 98 99 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 93 def args = {} msg = args[:msg] perc_finished = args[:perc_finished] self.update_attribute :message, msg if msg self.update_attribute :perc_finished, perc_finished if perc_finished end |
#update_state(rc_and_msg) ⇒ Object
This method updates the task state according to the return code of their corresponding command
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/queue_dispatcher/acts_as_task.rb', line 67 def update_state(rc_and_msg) rc = output = error_msg = nil if rc_and_msg.kind_of?(QueueDispatcher::RcAndMsg) rc = rc_and_msg.rc output = rc_and_msg.output error_msg = rc_and_msg.error_msg elsif rc_and_msg.kind_of?(Hash) rc = rc_and_msg[:rc] output = rc_and_msg[:output] error_msg = rc_and_msg[:error_msg] end if rc.nil? || rc == 0 self.update_attributes :state => "successful", :perc_finished => 100, :message => output else self.update_attributes :state => "error", :error_msg => error_msg, :message => output end end |