class BackOps::Action

Public Class Methods

after(action) click to toggle source
# File lib/back_ops/action.rb, line 24
def self.after(action)
  next_on_branch = BackOps::Action.where(operation: action.operation, branch: action.branch).
                  where('back_ops_actions.order > ?', action.order).
                  order(order: :asc).
                  limit(1).
                  first

  return next_on_branch if next_on_branch.present?

  BackOps::Action.where({
      operation: action.operation,
      branch: 'main',
      completed_at: nil
    }).
    limit(1).
    first
end

Public Instance Methods

get(field) click to toggle source
# File lib/back_ops/action.rb, line 48
def get(field)
  self.operation.get(field)
end
jump_to(pointer) click to toggle source
# File lib/back_ops/action.rb, line 56
def jump_to(pointer)
  # :branch
  # { branch: Action }
  next_action = nil

  if pointer.is_a?(Symbol)
    next_action = self.operation.actions.
                    where(branch: pointer).
                    order(order: :asc).
                    limit(1).
                    first
  elsif pointer.is_a?(Hash)
    branch, name = pointer.first
    next_action = self.operation.actions.
                    where(name: name, branch: branch).
                    order(order: :asc).
                    limit(1).
                    first
  else
    raise ArgumentError, 'jump_to only accepts as Symbol or a Hash'
  end

  raise "Could not jump_to(#{pointer.inspect}). Action not found." if next_action.nil?

  self.operation.next_action = next_action
  self.operation.save!
end
mark_completed() click to toggle source
# File lib/back_ops/action.rb, line 93
def mark_completed
  self.errored_at = nil
  self.error_message = nil
  self.stack_trace = nil

  self.completed_at = Time.zone.now
  self.attempts_count += 1
  self.save!
end
mark_errored(e) click to toggle source
# File lib/back_ops/action.rb, line 84
def mark_errored(e)
  self.error_message = e.message
  self.stack_trace = e.backtrace
  self.errored_at = Time.zone.now

  self.attempts_count += 1
  self.save!
end
premature?() click to toggle source

Instance Methods =====================================================

# File lib/back_ops/action.rb, line 44
def premature?
  perform_at.present? && perform_at > Time.zone.now
end
set(field, value) click to toggle source
# File lib/back_ops/action.rb, line 52
def set(field, value)
  self.operation.set(field, value)
end