Class: GemeraldBeanstalk::Jobs
- Inherits:
-
ThreadSafe::Array
- Object
- ThreadSafe::Array
- GemeraldBeanstalk::Jobs
- Defined in:
- lib/gemerald_beanstalk/jobs.rb
Instance Attribute Summary collapse
-
#total_jobs ⇒ Object
readonly
Returns the value of attribute total_jobs.
Instance Method Summary collapse
- #counts_by_state ⇒ Object
- #enqueue(job) ⇒ Object
-
#initialize ⇒ Jobs
constructor
A new instance of Jobs.
- #next_id ⇒ Object
Constructor Details
#initialize ⇒ Jobs
Returns a new instance of Jobs.
29 30 31 32 |
# File 'lib/gemerald_beanstalk/jobs.rb', line 29 def initialize(*) @total_jobs = 0 super end |
Instance Attribute Details
#total_jobs ⇒ Object (readonly)
Returns the value of attribute total_jobs.
2 3 4 |
# File 'lib/gemerald_beanstalk/jobs.rb', line 2 def total_jobs @total_jobs end |
Instance Method Details
#counts_by_state ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gemerald_beanstalk/jobs.rb', line 4 def counts_by_state job_stats = { 'current-jobs-urgent' => 0, 'current-jobs-ready' => 0, 'current-jobs-reserved' => 0, 'current-jobs-delayed' => 0, 'current-jobs-buried' => 0, } self.compact.each do |job| state = job.state job_stats["current-jobs-#{state}"] += 1 job_stats['current-jobs-urgent'] += 1 if state == :ready && job.priority < 1024 end return job_stats end |
#enqueue(job) ⇒ Object
22 23 24 25 26 |
# File 'lib/gemerald_beanstalk/jobs.rb', line 22 def enqueue(job) @total_jobs += 1 push(job) return self end |
#next_id ⇒ Object
35 36 37 |
# File 'lib/gemerald_beanstalk/jobs.rb', line 35 def next_id return @total_jobs + 1 end |