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
- Action =
Exceptions are used for signaling job status… ewww. Yank this out and replace with a more well thought out controller.
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
-
#around_bury ⇒ Object
Event hook that can be overridden.
-
#around_delete ⇒ Object
Event hook that can be overridden.
-
#around_release ⇒ Object
Event hook that can be overridden.
- #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.
33 34 35 36 37 38 39 40 |
# 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 |
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
88 89 90 |
# File 'lib/quebert/job.rb', line 88 def self.backend @backend || Quebert.configuration.backend end |
.backend=(backend) ⇒ Object
80 81 82 |
# File 'lib/quebert/job.rb', line 80 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.
74 75 76 77 78 |
# 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 |
Instance Method Details
#around_bury ⇒ Object
Event hook that can be overridden
93 94 95 |
# File 'lib/quebert/job.rb', line 93 def around_bury yield end |
#around_delete ⇒ Object
Event hook that can be overridden
103 104 105 |
# File 'lib/quebert/job.rb', line 103 def around_delete yield end |
#around_release ⇒ Object
Event hook that can be overridden
98 99 100 |
# File 'lib/quebert/job.rb', line 98 def around_release yield end |
#backend ⇒ Object
84 85 86 |
# File 'lib/quebert/job.rb', line 84 def backend self.class.backend end |
#enqueue(override_opts = {}) ⇒ Object
Accepts arguments that override the job options and enqueu this stuff.
63 64 65 66 |
# 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) ⇒ Object
42 43 44 |
# File 'lib/quebert/job.rb', line 42 def perform(*args) raise NotImplementedError end |
#perform! ⇒ Object
Runs the perform method that somebody else should be implementing
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
Serialize the job into a JSON string that we can put on the beandstalkd queue.
69 70 71 |
# File 'lib/quebert/job.rb', line 69 def to_json JSON.generate(Serializer::Job.serialize(self)) end |