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_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
99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/lato/operation.rb', line 99 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
88 89 90 91 92 93 94 |
# File 'app/models/lato/operation.rb', line 88 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
80 81 82 83 84 85 86 |
# File 'app/models/lato/operation.rb', line 80 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
35 36 37 |
# File 'app/models/lato/operation.rb', line 35 def finished? completed_status? || failed_status? end |
#output_error ⇒ Object
Helpers
54 55 56 |
# File 'app/models/lato/operation.rb', line 54 def output_error active_job_output['_error'] end |
#output_error? ⇒ Boolean
43 44 45 |
# File 'app/models/lato/operation.rb', line 43 def output_error? active_job_output && !active_job_output['_error'].blank? end |
#output_file? ⇒ Boolean
47 48 49 |
# File 'app/models/lato/operation.rb', line 47 def output_file? output_file.attached? end |
#output_message ⇒ Object
58 59 60 |
# File 'app/models/lato/operation.rb', line 58 def active_job_output['_message'] end |
#output_message? ⇒ Boolean
39 40 41 |
# File 'app/models/lato/operation.rb', line 39 def active_job_output && !active_job_output['_message'].blank? end |
#running ⇒ Object
76 77 78 |
# File 'app/models/lato/operation.rb', line 76 def running update(status: :running) end |
#start ⇒ Object
Operations
65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/lato/operation.rb', line 65 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 |