Class: Quebert::Job
Direct Known Subclasses
AsyncSender::ActiveRecord::RecordJob, AsyncSender::Instance::InstanceJob, AsyncSender::Object::ObjectJob
Defined Under Namespace
Classes: Priority
Constant Summary collapse
- DEFAULT_JOB_DELAY =
Delay a job for 0 seconds on the jobqueue
0- DEFAULT_JOB_TTR =
By default, the job should live for 10 seconds tops.
10- NotImplemented =
Exceptions are used for signaling job status… ewww. Yank this out and replace with a more well thought out controller.
Class.new(StandardError)
- Action =
Class.new(Exception)
- Bury =
Class.new(Action)
- Delete =
Class.new(Action)
- Release =
Class.new(Action)
- Timeout =
Class.new(Action)
- Retry =
Class.new(Action)
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#ttr ⇒ Object
Returns the value of attribute ttr.
Class Method Summary collapse
- .backend ⇒ Object
- .backend=(backend) ⇒ Object
-
.from_json(json) ⇒ Object
Read a JSON string and convert into a hash that Ruby can deal with.
Instance Method Summary collapse
- #backend ⇒ Object
-
#enqueue(override_opts = {}) ⇒ Object
Accepts arguments that override the job options and enqueu this stuff.
-
#initialize(*args) {|_self| ... } ⇒ Job
constructor
A new instance of Job.
- #perform(*args) ⇒ Object
-
#perform! ⇒ Object
Runs the perform method that somebody else should be implementing.
-
#to_json ⇒ Object
Serialize the job into a JSON string that we can put on the beandstalkd queue.
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Job
Returns a new instance of Job.
34 35 36 37 38 39 40 41 |
# File 'lib/quebert/job.rb', line 34 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 |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/quebert/job.rb', line 8 def args @args end |
#delay ⇒ Object
Returns the value of attribute delay.
9 10 11 |
# File 'lib/quebert/job.rb', line 9 def delay @delay end |
#priority ⇒ Object
Returns the value of attribute priority.
9 10 11 |
# File 'lib/quebert/job.rb', line 9 def priority @priority end |
#queue ⇒ Object
Returns the value of attribute queue.
9 10 11 |
# File 'lib/quebert/job.rb', line 9 def queue @queue end |
#ttr ⇒ Object
Returns the value of attribute ttr.
9 10 11 |
# File 'lib/quebert/job.rb', line 9 def ttr @ttr end |
Class Method Details
.backend ⇒ Object
89 90 91 |
# File 'lib/quebert/job.rb', line 89 def self.backend @backend || Quebert.configuration.backend end |
.backend=(backend) ⇒ Object
81 82 83 |
# File 'lib/quebert/job.rb', line 81 def self.backend=(backend) @backend = backend end |
.from_json(json) ⇒ Object
Read a JSON string and convert into a hash that Ruby can deal with.
75 76 77 78 79 |
# File 'lib/quebert/job.rb', line 75 def self.from_json(json) if hash = JSON.parse(json) and not hash.empty? Serializer::Job.deserialize(hash) end end |
Instance Method Details
#backend ⇒ Object
85 86 87 |
# File 'lib/quebert/job.rb', line 85 def backend self.class.backend end |
#enqueue(override_opts = {}) ⇒ Object
Accepts arguments that override the job options and enqueu this stuff.
64 65 66 67 |
# File 'lib/quebert/job.rb', line 64 def enqueue(override_opts={}) override_opts.each { |opt, val| self.send("#{opt}=", val) } backend.put(self) end |
#perform(*args) ⇒ Object
43 44 45 |
# File 'lib/quebert/job.rb', line 43 def perform(*args) raise NotImplemented end |
#perform! ⇒ Object
Runs the perform method that somebody else should be implementing
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/quebert/job.rb', line 48 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 ⇒ Object
Serialize the job into a JSON string that we can put on the beandstalkd queue.
70 71 72 |
# File 'lib/quebert/job.rb', line 70 def to_json JSON.generate(Serializer::Job.serialize(self)) end |