Module: Kthxbye::Failure
Class Method Summary collapse
- .all ⇒ Object
-
.clear_exception(id) ⇒ Object
the only method allowed to clear exceptions out of the exception store.
-
.count ⇒ Object
gets count of all errors.
-
.count_type(type) ⇒ Object
gets count of all errors of a specific type.
-
.create(job, exception) ⇒ Object
creates a Failure object.
- .fails_for_job(id) ⇒ Object
-
.find(id) ⇒ Object
returns a specified failed job data.
- .rerun(id) ⇒ Object
Methods included from Helper
Class Method Details
.all ⇒ Object
6 7 8 |
# File 'lib/kthxbye/failure.rb', line 6 def self.all redis.hvals( :failed ).sort.map{|x| decode( x )} 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 |
.count ⇒ Object
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 |