Class: BackOps::Action
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BackOps::Action
- Defined in:
- lib/back_ops/action.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(field) ⇒ Object
- #jump_to(pointer) ⇒ Object
- #mark_completed ⇒ Object
- #mark_errored(e) ⇒ Object
-
#premature? ⇒ Boolean
Instance Methods =====================================================.
- #set(field, value) ⇒ Object
Class Method Details
.after(action) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |
Instance Method Details
#get(field) ⇒ Object
48 49 50 |
# File 'lib/back_ops/action.rb', line 48 def get(field) self.operation.get(field) end |
#jump_to(pointer) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/back_ops/action.rb', line 93 def mark_completed self.errored_at = nil self. = nil self.stack_trace = nil self.completed_at = Time.zone.now self.attempts_count += 1 self.save! end |
#mark_errored(e) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/back_ops/action.rb', line 84 def mark_errored(e) self. = e. self.stack_trace = e.backtrace self.errored_at = Time.zone.now self.attempts_count += 1 self.save! end |
#premature? ⇒ Boolean
Instance Methods =====================================================
44 45 46 |
# File 'lib/back_ops/action.rb', line 44 def premature? perform_at.present? && perform_at > Time.zone.now end |
#set(field, value) ⇒ Object
52 53 54 |
# File 'lib/back_ops/action.rb', line 52 def set(field, value) self.operation.set(field, value) end |