class Quebert::Job
Constants
- Action
Exceptions are used for signaling job status… ewww. Yank this out and replace with a more well thought out controller.
- Bury
- DEFAULT_JOB_DELAY
Delay a job for 0 seconds on the jobqueue
- DEFAULT_JOB_TTR
By default, the job should live for 10 seconds tops.
- Delete
- Release
- Retry
- Timeout
Attributes
args[R]
delay[RW]
priority[RW]
queue[RW]
ttr[RW]
Public Class Methods
backend()
click to toggle source
# File lib/quebert/job.rb, line 88 def self.backend @backend || Quebert.configuration.backend end
backend=(backend)
click to toggle source
# File lib/quebert/job.rb, line 80 def self.backend=(backend) @backend = backend end
from_json(json)
click to toggle source
Read a JSON string and convert into a hash that Ruby can deal with.
# File lib/quebert/job.rb, line 74 def self.from_json(json) if hash = JSON.parse(json) and not hash.empty? Serializer::Job.deserialize(hash) end end
new(*args) { |self| ... }
click to toggle source
# File lib/quebert/job.rb, line 33 def initialize(*args) @priority = Job::Priority::MEDIUM @delay = DEFAULT_JOB_DELAY @ttr = DEFAULT_JOB_TTR @args = args.dup.freeze yield self if block_given? self end
Public Instance Methods
around_bury() { || ... }
click to toggle source
Event hook that can be overridden
# File lib/quebert/job.rb, line 93 def around_bury yield end
around_delete() { || ... }
click to toggle source
Event hook that can be overridden
# File lib/quebert/job.rb, line 103 def around_delete yield end
around_release() { || ... }
click to toggle source
Event hook that can be overridden
# File lib/quebert/job.rb, line 98 def around_release yield end
backend()
click to toggle source
# File lib/quebert/job.rb, line 84 def backend self.class.backend end
enqueue(override_opts={})
click to toggle source
Accepts arguments that override the job options and enqueu this stuff.
# File lib/quebert/job.rb, line 63 def enqueue(override_opts={}) override_opts.each { |opt, val| self.send("#{opt}=", val) } backend.put(self) end
perform(*args)
click to toggle source
# File lib/quebert/job.rb, line 42 def perform(*args) raise NotImplementedError end
perform!()
click to toggle source
Runs the perform method that somebody else should be implementing
# File lib/quebert/job.rb, line 47 def perform! Quebert.config.before_job(self) Quebert.config.around_job(self) # Honor the timeout and kill the job in ruby-space. Beanstalk # should be cleaning up this job and returning it to the queue # as well. val = ::Timeout.timeout(ttr, Job::Timeout){ perform(*args) } Quebert.config.around_job(self) Quebert.config.after_job(self) val end
to_json()
click to toggle source
Serialize the job into a JSON string that we can put on the beandstalkd queue.
# File lib/quebert/job.rb, line 69 def to_json JSON.generate(Serializer::Job.serialize(self)) end
Protected Instance Methods
bury!()
click to toggle source
# File lib/quebert/job.rb, line 116 def bury! raise Bury end
delete!()
click to toggle source
# File lib/quebert/job.rb, line 108 def delete! raise Delete end
release!()
click to toggle source
# File lib/quebert/job.rb, line 112 def release! raise Release end