module QueueDispatcher::ActsAsTask::InstanceMethods

Public Instance Methods

aborted?() click to toggle source

Was this task aborted?

# File lib/queue_dispatcher/acts_as_task.rb, line 185
def aborted?
  state == 'aborted'
end
acquire_lock?() click to toggle source

Is this task pending?

# File lib/queue_dispatcher/acts_as_task.rb, line 161
def acquire_lock?
  acts_as_task_task_queue && acts_as_task_task_queue.running? && state == 'acquire_lock'
end
acts_as_task_task_queue() click to toggle source
# File lib/queue_dispatcher/acts_as_task.rb, line 70
def acts_as_task_task_queue
  self.send(self.class.acts_as_task_config.task_queue_class_name)
end
args() click to toggle source

Add task_id to the args

Calls superclass method
# File lib/queue_dispatcher/acts_as_task.rb, line 85
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?() click to toggle source

Are all dependent_tasks executed?

# File lib/queue_dispatcher/acts_as_task.rb, line 203
def dependent_tasks_executed?
  state = true
  dependent_tasks.each{ |dt| state = false unless dt.executed? }
  state
end
dependent_tasks_had_errors() click to toggle source

Check recursive, if one or more of the tasks, which this task is dependent on had errors

# File lib/queue_dispatcher/acts_as_task.rb, line 211
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?() click to toggle source

Had this task error(s)?

# File lib/queue_dispatcher/acts_as_task.rb, line 179
def error?
  state == 'error' || state.blank?
end
execute!() click to toggle source

Execute task

# File lib/queue_dispatcher/acts_as_task.rb, line 234
def execute!
  payload.task_id = id if payload.methods.include?(:task_id=)
  payload.send(method_name, *args)
end
executed?() click to toggle source

Was this task already executed?

# File lib/queue_dispatcher/acts_as_task.rb, line 197
def executed?
  successful? || error? || aborted?
end
init_queue?() click to toggle source

Is this task waiting until the queue is initialized?

# File lib/queue_dispatcher/acts_as_task.rb, line 191
def init_queue?
  state == 'init_queue'
end
md5() click to toggle source

Calculate md5-Checksum

# File lib/queue_dispatcher/acts_as_task.rb, line 226
def md5
  attr_str = ''
  Task.attribute_names.each{ |a| attr_str += self.send(a).to_s }
  Digest('MD5').digest(attr_str)
end
new?() click to toggle source

Is this task new?

# File lib/queue_dispatcher/acts_as_task.rb, line 143
def new?
   state == 'new' || state == 'new_popped'
end
payload() click to toggle source
# File lib/queue_dispatcher/acts_as_task.rb, line 75
def payload
  if target.is_a?(QueueDispatcher::TargetContainer)
    target.payload
  else
    target
  end
end
pending?() click to toggle source

Is this task pending?

# File lib/queue_dispatcher/acts_as_task.rb, line 149
def pending?
  acts_as_task_task_queue && state == 'new'
end
prosa() click to toggle source

Placeholder. Please override it in your model.

# File lib/queue_dispatcher/acts_as_task.rb, line 221
def prosa
end
reloading_config?() click to toggle source

Is the task_queue in state config_reload?

# File lib/queue_dispatcher/acts_as_task.rb, line 155
def reloading_config?
  acts_as_task_task_queue && acts_as_task_task_queue.reloading_config? && acts_as_task_task_queue.tasks.where(state: 'new').first.id == id
end
running?() click to toggle source

Is this task running?

# File lib/queue_dispatcher/acts_as_task.rb, line 167
def running?
  acts_as_task_task_queue && acts_as_task_task_queue.running? && state == 'running'
end
successful?() click to toggle source

Was this task finsihed successful?

# File lib/queue_dispatcher/acts_as_task.rb, line 173
def successful?
  state == 'successful' || state == 'finished'
end
update_message(args = {}) click to toggle source

Update the attributes perc_finished and message according to the args

# File lib/queue_dispatcher/acts_as_task.rb, line 133
def update_message(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_and_exec_callbacks(result, remove_from_queue = false, logger = nil) click to toggle source

This method updates the task state according to the return code of their corresponding command and removes it from the task_queue

# File lib/queue_dispatcher/acts_as_task.rb, line 93
def update_state_and_exec_callbacks(result, remove_from_queue = false, logger = nil)
  rc = output = error_msg = nil

  if result.methods.map(&:to_sym).include?(:rc) && result.methods.map(&:to_sym).include?(:output) && result.methods.map(&:to_sym).include?(:error_msg)
    rc        = result.rc
    output    = result.output
    error_msg = result.error_msg
    result    = nil
  elsif result.kind_of?(Hash)
    rc        = result[:rc]
    output    = result[:output]
    error_msg = result[:error_msg]
    result    = nil
  end

  output ||= ''
  successful = result.methods.map(&:to_sym).include?(:successful?) ? result.successful? : rc.nil? || rc == 0

  if successful
    self.update_attributes :state         => 'successful',
                           :perc_finished => 100,
                           :message       => output.truncate(10256),
                           :result        => result
    success_callbacks(logger)
  else
    self.update_attributes :state     => 'error',
                           :error_msg => error_msg,
                           :message   => output.truncate(10256),
                           :result    => result
    error_callbacks(logger)
  end

  self.update_attributes :task_queue_id => nil if remove_from_queue


  rc
end