Class: RailsWorkflow::Error
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RailsWorkflow::Error
- Defined in:
- app/models/rails_workflow/error.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_from(exception, context) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/rails_workflow/error.rb', line 47 def self.create_from exception, context parent = context[:parent] if parent.is_a? RailsWorkflow::Operation correct_parent = parent.becomes(RailsWorkflow::Operation) elsif parent.is_a? RailsWorkflow::Process correct_parent = parent.becomes(RailsWorkflow::Process) end error = RailsWorkflow::Error.create( parent_id: parent.id, parent_type: (correct_parent || parent).class.to_s, message: exception..first(250), stack_trace: exception.backtrace.join("<br/>\n") ) error.create_context(data: context) # Workflow.config.sidekiq_enabled ? # Workflow::ErrorWorker.perform_async(parent.id, parent.class.to_s) : # Workflow::ErrorWorker.new.perform(parent.id, parent.class.to_s) RailsWorkflow::ErrorWorker.new.perform(parent.id, parent.class.to_s) end |
Instance Method Details
#can_restart_process(process) ⇒ Object
42 43 44 45 |
# File 'app/models/rails_workflow/error.rb', line 42 def can_restart_process process process.workflow_errors. unresolved.where.not(id: self.id).count == 0 end |
#retry ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/rails_workflow/error.rb', line 9 def retry update_attribute(:resolved, true) target = data[:target] method = data[:method] args = data[:args] target.send(method, *args) operation = parent if parent.is_a? RailsWorkflow::Operation process = if operation operation.process elsif target.is_a? RailsWorkflow::Process target elsif parent.is_a? RailsWorkflow::Process parent end if operation.present? operation.reload if operation.status == RailsWorkflow::Operation::ERROR operation.update_attribute(:status, RailsWorkflow::Operation::NOT_STARTED) end end if process.present? && can_restart_process(process) process.update_attribute(:status, RailsWorkflow::Process::IN_PROGRESS) process.start end end |