Class: Lato::Operation
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Lato::Operation
- Defined in:
- app/models/lato/operation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #completed(message = nil) ⇒ Object
- #failed(error = nil) ⇒ Object
-
#finished? ⇒ Boolean
Questions.
- #output_action ⇒ Object
- #output_action? ⇒ Boolean
-
#output_error ⇒ Object
Helpers.
- #output_error? ⇒ Boolean
- #output_file? ⇒ Boolean
- #output_message ⇒ Object
- #output_message? ⇒ Boolean
- #running ⇒ Object
-
#start ⇒ Object
Operations.
Class Method Details
.generate(active_job_name, active_job_input = {}, user_id = nil, file = nil) ⇒ Object
Class
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/lato/operation.rb', line 108 def self.generate(active_job_name, active_job_input = {}, user_id = nil, file = nil) operation_params = { active_job_name: active_job_name, active_job_input: active_job_input, lato_user_id: user_id } operation_params[:input_file] = file unless file.nil? Lato::Operation.create(operation_params) end |
Instance Method Details
#completed(message = nil) ⇒ Object
97 98 99 100 101 102 103 |
# File 'app/models/lato/operation.rb', line 97 def completed( = nil) update( status: :completed, closed_at: Time.now, active_job_output: ? active_job_output.merge(_message: ) : active_job_output ) end |
#failed(error = nil) ⇒ Object
89 90 91 92 93 94 95 |
# File 'app/models/lato/operation.rb', line 89 def failed(error = nil) update( status: :failed, closed_at: Time.now, active_job_output: error ? active_job_output.merge(_error: error) : active_job_output ) end |
#finished? ⇒ Boolean
Questions
36 37 38 |
# File 'app/models/lato/operation.rb', line 36 def finished? completed_status? || failed_status? end |
#output_action ⇒ Object
67 68 69 |
# File 'app/models/lato/operation.rb', line 67 def output_action active_job_output['_action'] end |
#output_action? ⇒ Boolean
44 45 46 |
# File 'app/models/lato/operation.rb', line 44 def output_action? active_job_output && !active_job_output['_action'].blank? end |
#output_error ⇒ Object
Helpers
59 60 61 |
# File 'app/models/lato/operation.rb', line 59 def output_error active_job_output['_error'] end |
#output_error? ⇒ Boolean
48 49 50 |
# File 'app/models/lato/operation.rb', line 48 def output_error? active_job_output && !active_job_output['_error'].blank? end |
#output_file? ⇒ Boolean
52 53 54 |
# File 'app/models/lato/operation.rb', line 52 def output_file? output_file.attached? end |
#output_message ⇒ Object
63 64 65 |
# File 'app/models/lato/operation.rb', line 63 def active_job_output['_message'] end |
#output_message? ⇒ Boolean
40 41 42 |
# File 'app/models/lato/operation.rb', line 40 def active_job_output && !active_job_output['_message'].blank? end |
#running ⇒ Object
85 86 87 |
# File 'app/models/lato/operation.rb', line 85 def running update(status: :running) end |
#start ⇒ Object
Operations
74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/lato/operation.rb', line 74 def start begin active_job_name.constantize.perform_later(active_job_input.merge(_operation_id: id)) rescue StandardError errors.add(:base, 'Impossibile eseguire il job') return false end true end |