Class: GemeraldBeanstalk::Jobs

Inherits:
ThreadSafe::Array
  • Object
show all
Defined in:
lib/gemerald_beanstalk/jobs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJobs

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_jobsObject (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_stateObject



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_idObject



35
36
37
# File 'lib/gemerald_beanstalk/jobs.rb', line 35

def next_id
  return @total_jobs + 1
end