Class: BeanCounter::Strategy::GemeraldBeanstalkStrategy::Job
- Inherits:
-
Object
- Object
- BeanCounter::Strategy::GemeraldBeanstalkStrategy::Job
- Extended by:
- Forwardable
- Defined in:
- lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb
Constant Summary collapse
- STATS_METHODS =
Attributes that should be retrieved via the gemerald job's stats. This list is used to dynamically create the appropriate accessor methods
%w[ age buries delay id kicks pri releases reserves state time-left timeouts ttr tube ]
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Attempts to delete the job.
-
#exists? ⇒ Boolean
Returns a Boolean indicating whether or not the job still exists.
-
#initialize(gemerald_job, connection) ⇒ Job
constructor
Initialize a new GemeraldBeanstalkStrategy::Job wrapping the provided
gemerald_job
in the context of the providedconnection
. -
#to_hash ⇒ Hash
Augment job stats to provide a Hash representation of the job.
Constructor Details
#initialize(gemerald_job, connection) ⇒ Job
Initialize a new GemeraldBeanstalkStrategy::Job wrapping the provided
gemerald_job
in the context of the provided connection
.
54 55 56 57 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb', line 54 def initialize(gemerald_job, connection) @gemerald_job = gemerald_job @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb', line 9 def connection @connection end |
Instance Method Details
#delete ⇒ Boolean
Attempts to delete the job. Returns true if deletion succeeds or if job does not exist. Returns false if job could not be deleted (typically due to it being reserved by another connection).
32 33 34 35 36 37 38 39 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb', line 32 def delete response = connection.transmit("delete #{id}") if response == "DELETED\r\n" || !exists? return true else return false end end |
#exists? ⇒ Boolean
Returns a Boolean indicating whether or not the job still exists.
46 47 48 49 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb', line 46 def exists? return false if state == 'deleted' return connection.transmit("stats-job #{id}") != "NOT_FOUND\r\n" end |
#to_hash ⇒ Hash
Augment job stats to provide a Hash representation of the job.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/job.rb', line 62 def to_hash stats_pairs = stats.to_a stats_pairs << ['body', body] stats_pairs << ['connection', connection] hash = Hash[stats_pairs.sort_by!(&:first)] hash.delete('file') return hash end |