Class: ActiveOperator::Operation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveOperator::Operation
- Defined in:
- lib/active_operator/operation.rb
Instance Method Summary collapse
- #errored! ⇒ Object
- #errored? ⇒ Boolean
- #perform ⇒ Object
- #perform_later ⇒ Object
- #process ⇒ Object
- #process! ⇒ Object
- #processed? ⇒ Boolean
- #received? ⇒ Boolean
- #request ⇒ Object
- #request! ⇒ Object
Instance Method Details
#errored! ⇒ Object
41 42 43 |
# File 'lib/active_operator/operation.rb', line 41 def errored! update!(errored_at: Time.current) end |
#errored? ⇒ Boolean
11 |
# File 'lib/active_operator/operation.rb', line 11 def errored? = errored_at? |
#perform ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_operator/operation.rb', line 13 def perform request! process! rescue errored! raise end |
#perform_later ⇒ Object
21 22 23 |
# File 'lib/active_operator/operation.rb', line 21 def perform_later ActiveOperator::PerformOperationJob.perform_later(self) end |
#process ⇒ Object
49 50 51 |
# File 'lib/active_operator/operation.rb', line 49 def process raise NotImplementedError, "Operations must implement the `process` method" end |
#process! ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/active_operator/operation.rb', line 31 def process! return false if !received? return false if processed? ActiveRecord::Base.transaction do process update!(processed_at: Time.current) end end |
#processed? ⇒ Boolean
10 |
# File 'lib/active_operator/operation.rb', line 10 def processed? = processed_at? |
#received? ⇒ Boolean
9 |
# File 'lib/active_operator/operation.rb', line 9 def received? = received_at? |
#request ⇒ Object
45 46 47 |
# File 'lib/active_operator/operation.rb', line 45 def request raise NotImplementedError, "Operations must implement the `request` method" end |
#request! ⇒ Object
25 26 27 28 29 |
# File 'lib/active_operator/operation.rb', line 25 def request! return false if received? update!(response: request, received_at: Time.current) end |