Class: Action
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Action
- Defined in:
- app/models/action.rb
Class Attribute Summary collapse
-
.ignored_exceptions ⇒ Object
Returns the value of attribute ignored_exceptions.
Class Method Summary collapse
- .run!(action_name, params, trigger) ⇒ Object
- .running ⇒ Object
- .started_before(time) ⇒ Object
- .unqueued ⇒ Object
Instance Method Summary collapse
- #duration ⇒ Object
- #exception=(exception) ⇒ Object
- #finish!(exception) ⇒ Object
- #finished? ⇒ Boolean
- #in_progress? ⇒ Boolean
- #retry! ⇒ Object
- #run! ⇒ Object
- #started? ⇒ Boolean
Class Attribute Details
.ignored_exceptions ⇒ Object
Returns the value of attribute ignored_exceptions.
27 28 29 |
# File 'app/models/action.rb', line 27 def ignored_exceptions @ignored_exceptions end |
Class Method Details
.run!(action_name, params, trigger) ⇒ Object
41 42 43 44 |
# File 'app/models/action.rb', line 41 def run!(action_name, params, trigger) action = create!(name: action_name, trigger: trigger, params: params) action.run! end |
.running ⇒ Object
33 34 35 |
# File 'app/models/action.rb', line 33 def running where.not(started_at: nil).where(finished_at: nil) end |
.started_before(time) ⇒ Object
29 30 31 |
# File 'app/models/action.rb', line 29 def started_before(time) where arel_table[:started_at].lteq time end |
.unqueued ⇒ Object
37 38 39 |
# File 'app/models/action.rb', line 37 def unqueued where(started_at: nil) end |
Instance Method Details
#duration ⇒ Object
103 104 105 106 |
# File 'app/models/action.rb', line 103 def duration return nil unless finished? finished_at - started_at end |
#exception=(exception) ⇒ Object
95 96 97 |
# File 'app/models/action.rb', line 95 def exception=(exception) self.error = Error.find_or_create_for_exception(exception) if exception end |
#finish!(exception) ⇒ Object
99 100 101 |
# File 'app/models/action.rb', line 99 def finish!(exception) update_attributes! finished_at: Time.now, succeeded: exception.nil?, exception: exception end |
#finished? ⇒ Boolean
112 113 114 |
# File 'app/models/action.rb', line 112 def finished? finished_at.present? end |
#in_progress? ⇒ Boolean
116 117 118 |
# File 'app/models/action.rb', line 116 def in_progress? started_at.present? && finished_at.nil? end |
#retry! ⇒ Object
88 89 90 91 92 93 |
# File 'app/models/action.rb', line 88 def retry! update_attributes! started_at: Time.now, finished_at: nil, succeeded: nil, exception: nil Houston.async do run! end end |
#run! ⇒ Object
49 50 51 52 53 54 55 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 83 84 85 86 |
# File 'app/models/action.rb', line 49 def run! exception = nil Houston.reconnect do touch :started_at Houston.actions.fetch(name).execute(params) end rescue *::Action.ignored_exceptions # Note that the action failed, but do not report _these_ exceptions exception = $! rescue Exception # rescues StandardError by default; but we want to rescue and report all errors # Report all other exceptions exception = $! Houston.report_exception($!, parameters: { action_id: id, action_name: name, trigger: trigger, params: params }) ensure begin Houston.reconnect do finish! exception end rescue Exception # rescues StandardError by default; but we want to rescue and report all errors Houston.report_exception($!, parameters: { action_id: id, action_name: name, trigger: trigger, params: params }) end end |
#started? ⇒ Boolean
108 109 110 |
# File 'app/models/action.rb', line 108 def started? started_at.present? end |