Module: Kthxbye::Failure

Extended by:
Helper
Includes:
Helper
Defined in:
lib/kthxbye/failure.rb

Class Method Summary collapse

Methods included from Helper

decode, encode, log, redis

Class Method Details

.allObject



6
7
8
# File 'lib/kthxbye/failure.rb', line 6

def self.all
  redis.hvals( :failed ).sort.map{|x| decode( x )}
end

.clear_allObject



61
62
63
# File 'lib/kthxbye/failure.rb', line 61

def self.clear_all
  redis.del( :failed )
end

.clear_exception(id) ⇒ Object

the only method allowed to clear exceptions out of the exception store



57
58
59
# File 'lib/kthxbye/failure.rb', line 57

def self.clear_exception(id)
  redis.hdel( :failed, id ) 
end

.countObject

gets count of all errors



16
17
18
# File 'lib/kthxbye/failure.rb', line 16

def self.count
  redis.hkeys( :failed ).size
end

.count_type(type) ⇒ Object

gets count of all errors of a specific type



21
22
23
24
25
# File 'lib/kthxbye/failure.rb', line 21

def self.count_type(type)
  vals = redis.hvals( :failed )
  vals.each {|x| o = decode(x); vals.delete x if o['type'] !~ /#{type.to_s}/}
  vals.size
end

.create(job, exception) ⇒ Object

creates a Failure object.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kthxbye/failure.rb', line 28

def self.create(job, exception)
  failed_attempts = (Failure.find(job.id)['attempts'].to_i + 1) if redis.hexists( :failed, job.id )

  error = {
    :type => exception.class.to_s,
    :error => exception.to_s,
    :job => job.id,
    :queue => job.queue,
    :time => Time.now,
    :backtrace => Array( exception.backtrace ),
    :attempts => (failed_attempts || 1)
  }
  
  redis.hset( :failed, job.id, encode( error ) )

  job.dequeue
end

.fails_for_job(id) ⇒ Object



51
52
53
54
# File 'lib/kthxbye/failure.rb', line 51

def self.fails_for_job(id)
  failure = decode( redis.hget( :failed, id ) )
  return failure ? failure['attempts'] : 0
end

.find(id) ⇒ Object

returns a specified failed job data



11
12
13
# File 'lib/kthxbye/failure.rb', line 11

def self.find(id)
  decode( redis.hget( :failed, id ) )
end

.rerun(id) ⇒ Object



46
47
48
49
# File 'lib/kthxbye/failure.rb', line 46

def self.rerun(id)
  failure = Failure.find(id)
  Job.find(id, failure['queue']).rerun
end