Class: Kongnomal::Job
- Inherits:
-
Object
- Object
- Kongnomal::Job
- Extended by:
- Forwardable
- Defined in:
- lib/kongnomal/job.rb
Constant Summary collapse
- PUT =
"put".freeze
- RESERVED =
"reserved".freeze
- DELETED =
"deleted".freeze
- TOUCHED =
"touched".freeze
- RELEASED =
"released".freeze
Class Method Summary collapse
- .bind {|_self| ... } ⇒ Object
- .when_deleted(&blk) ⇒ Object
- .when_put(&blk) ⇒ Object
- .when_released(&blk) ⇒ Object
- .when_reserved(&blk) ⇒ Object
- .when_touched(&blk) ⇒ Object
Instance Method Summary collapse
- #delete(*args, &blk) ⇒ Object
-
#initialize(event_tube, beanstalk_job, tube) ⇒ Job
constructor
A new instance of Job.
- #release(*args, &blk) ⇒ Object
- #touch(data) ⇒ Object
Constructor Details
#initialize(event_tube, beanstalk_job, tube) ⇒ Job
Returns a new instance of Job.
47 48 49 50 51 |
# File 'lib/kongnomal/job.rb', line 47 def initialize(event_tube, beanstalk_job, tube) @event_tube = event_tube @beanstalk_job = beanstalk_job @tube = tube end |
Class Method Details
.bind {|_self| ... } ⇒ Object
39 40 41 |
# File 'lib/kongnomal/job.rb', line 39 def bind(&blk) yield self end |
.when_deleted(&blk) ⇒ Object
21 22 23 |
# File 'lib/kongnomal/job.rb', line 21 def self.when_deleted(&blk) @deleted_handler = blk end |
.when_put(&blk) ⇒ Object
9 10 11 |
# File 'lib/kongnomal/job.rb', line 9 def self.when_put(&blk) @put_handler = blk end |
.when_released(&blk) ⇒ Object
25 26 27 |
# File 'lib/kongnomal/job.rb', line 25 def self.when_released(&blk) @released_handler = blk end |
.when_reserved(&blk) ⇒ Object
13 14 15 |
# File 'lib/kongnomal/job.rb', line 13 def self.when_reserved(&blk) @reserved_handler = blk end |
.when_touched(&blk) ⇒ Object
17 18 19 |
# File 'lib/kongnomal/job.rb', line 17 def self.when_touched(&blk) @touched_handler = blk end |
Instance Method Details
#delete(*args, &blk) ⇒ Object
66 67 68 69 70 |
# File 'lib/kongnomal/job.rb', line 66 def delete(*args, &blk) deleted = @beanstalk_job.delete(*args, &blk) @event_tube.put({"state" => Kongnomal::Job::DELETED, "id" => id, "body" => body, "tube" => @tube}.to_json) unless deleted.nil? deleted end |
#release(*args, &blk) ⇒ Object
60 61 62 63 64 |
# File 'lib/kongnomal/job.rb', line 60 def release(*args, &blk) released = @beanstalk_job.release(*args, &blk) @event_tube.put({"state" => Kongnomal::Job::RELEASED, "id" => id, "body" => body, "tube" => @tube}.to_json) unless released.nil? released end |
#touch(data) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/kongnomal/job.rb', line 53 def touch(data) as_msg = data.respond_to?(:to_hash) ? data.to_hash : data.to_s touched = @beanstalk_job.touch @event_tube.put({"state" => Kongnomal::Job::TOUCHED, "id" => id, "body" => body, "tube" => @tube, "msg" => as_msg}.to_json) if touched == :ok touched end |