Class: AsyncRequest::Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AsyncRequest::Job
- Defined in:
- app/models/async_request/job.rb
Overview
rubocop:disable Rails/ApplicationRecord
Class Method Summary collapse
Instance Method Summary collapse
- #finished? ⇒ Boolean
- #finished_with_errors!(error) ⇒ Object
- #processing! ⇒ Object
- #successfully_processed!(response, status_code) ⇒ Object
- #token ⇒ Object
Class Method Details
.create_and_enqueue(worker_class, *params) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/models/async_request/job.rb', line 6 def self.create_and_enqueue(worker_class, *params) raise ArgumentError if worker_class.nil? create( worker: worker_class, params: params, status: statuses[:waiting], uid: SecureRandom.uuid ).tap { |job| JobProcessor.perform_async(job.id) } end |
Instance Method Details
#finished? ⇒ Boolean
34 35 36 |
# File 'app/models/async_request/job.rb', line 34 def finished? processed? || failed? end |
#finished_with_errors!(error) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/async_request/job.rb', line 38 def finished_with_errors!(error) Rails.logger.info("Processing failed for job with id=#{id}") Rails.logger.info(error.) Rails.logger.info(error.backtrace.inspect) update_attributes!(status: :failed, status_code: 500, response: { error: error. }.to_json) end |
#processing! ⇒ Object
29 30 31 32 |
# File 'app/models/async_request/job.rb', line 29 def processing! Rails.logger.info("Processing job with id=#{id}") super end |
#successfully_processed!(response, status_code) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/async_request/job.rb', line 20 def successfully_processed!(response, status_code) Rails.logger.info("Processing finished successfully for job with id=#{id}") update_attributes!( status: :processed, status_code: map_status_code(status_code), response: response.to_s ) end |
#token ⇒ Object
16 17 18 |
# File 'app/models/async_request/job.rb', line 16 def token @token ||= JsonWebToken.encode(id) end |