Class: Postburner::TrackedJob
- Inherits:
-
Job
- Object
- ActiveRecord::Base
- ApplicationRecord
- Job
- Postburner::TrackedJob
- Defined in:
- app/models/postburner/tracked_job.rb
Overview
Job wrapper for executing tracked ActiveJob instances.
TrackedJob is a Postburner::Job subclass that deserializes and executes ActiveJob instances that opted-in to PostgreSQL tracking via the ‘Postburner::Tracked` concern.
When an ActiveJob with ‘tracked` is enqueued, the adapter:
-
Creates a TrackedJob record in PostgreSQL
-
Stores the ActiveJob data in the ‘args` JSONB column
-
Queues a minimal payload to Beanstalkd with the TrackedJob ID
When the worker executes the job:
-
Loads the TrackedJob record
-
Deserializes the ActiveJob from ‘args`
-
Executes it with full audit trail (logs, timing, errors)
Instance Attribute Summary
Attributes inherited from Job
#args, #attempt_count, #attempting_at, #attempts, #bkid, #duration, #errata, #error_count, #id, #lag, #log_count, #logs, #processed_at, #processing_at, #queued_at, #removed_at, #run_at, #sid, #type
Instance Method Summary collapse
-
#perform(args) ⇒ void
Executes the wrapped ActiveJob instance.
Methods inherited from Job
#bk, #bk!, #bk=, #destroy, #destroy!, find_sti_class, #orphaned?
Methods included from Statistics
#elapsed_ms, #intended_at, #stats
Methods included from Execution
Methods included from Insertion
#queue!, #requeue!, #will_insert?
Methods included from Commands
#delete!, #extend!, #kick!, #remove!
Methods included from Logging
#log, #log!, #log_exception, #log_exception!
Methods included from Properties
#priority, #queue_name, #retry_delay_for_attempt, #should_retry?, #ttr, #tube_name
Instance Method Details
#perform(args) ⇒ void
This method returns an undefined value.
Executes the wrapped ActiveJob instance.
Deserializes the ActiveJob from args, restores metadata, sets up the bidirectional link for logging, and executes the job.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/postburner/tracked_job.rb', line 52 def perform(args) # Extract ActiveJob metadata from args job_class = args['job_class'].constantize arguments = ::ActiveJob::Arguments.deserialize(args['arguments']) # Instantiate the ActiveJob job = job_class.new(*arguments) # Restore ActiveJob metadata job.job_id = args['job_id'] job.queue_name = args['queue_name'] job.priority = args['priority'] job.executions = args['executions'] || 0 job.exception_executions = args['exception_executions'] || {} job.locale = args['locale'] job.timezone = args['timezone'] if args['enqueued_at'] job.enqueued_at = Time.iso8601(args['enqueued_at']) end # Give the ActiveJob access to this Postburner::Job for logging if job.respond_to?(:postburner_job=) job.postburner_job = self end # Execute the job (ActiveJob handles retry_on/discard_on) # Exceptions are caught by Postburner::Job#perform! and logged to errata job.perform_now end |