Class: Fanforce::Worker::Errors

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/fanforce/worker/errors.rb

Constant Summary collapse

@@redis =
nil

Class Method Summary collapse

Methods included from Utils

included, #iron_queue_id, #log

Class Method Details

.add(queue_id, e, job_data, worker_env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fanforce/worker/errors.rb', line 37

def self.add(queue_id, e, job_data, worker_env)
  error_id = UUIDTools::UUID.random_create.to_s
  error = {
      error_id: error_id,
      class: Fanforce::Worker,
      exception: e.class.name,
      http_code: (e.code if e.respond_to?(:code)),
      message: e.message,
      backtrace: e.backtrace.to_json,
      errored_at: Time.now,
      queue_id: queue_id,
      raw_json: job_data[:params].to_json,
      env_vars: worker_env.to_json,
      retries: job_data[:retries],
      curl_command: (e.curl_command if e.respond_to?(:curl_command)),
      iron_token: Fanforce::Worker.iron_token,
      iron_project_id: Fanforce::Worker.iron_project_id
  }
  redis.multi do
    redis.rpush("ERRORS:#{queue_id}", error_id)
    redis.hmset("ERRORS:#{queue_id}:#{error_id}", error.flatten)
  end
rescue => e
  log.fatal '-----------------------------------------------------'
  log.fatal 'WORKER ERROR WHILE RECOVERING FROM JOB ERROR:'
  log.fatal '-----------------------------------------------------'
  error.each {|k,v| log.fatal "#{k}: #{v}" }
  log.fatal '-----------------------------------------------------'
  raise
end

.delete_all(queue_id, error_ids) ⇒ Object



29
30
31
# File 'lib/fanforce/worker/errors.rb', line 29

def self.delete_all(queue_id, error_ids)
  Fanforce::Worker::ErrorList.new(queue_id, error_ids).delete
end

.find(queue_id, error_id) ⇒ Object



13
14
15
# File 'lib/fanforce/worker/errors.rb', line 13

def self.find(queue_id, error_id)
  Fanforce::Worker::Error.new(queue_id, error_id)
end

.list(queue_id, from_num = 0, to_num = 100, reverse = false) ⇒ Object



17
18
19
20
21
# File 'lib/fanforce/worker/errors.rb', line 17

def self.list(queue_id, from_num=0, to_num=100, reverse=false)
  error_ids = redis.lrange("ERRORS:#{queue_id}", from_num, to_num)
  error_ids.reverse! if reverse
  Fanforce::Worker::ErrorList.new(queue_id, error_ids)
end

.list_summaries(queue_id, from_num = 0, to_num = 100, reverse = false) ⇒ Object



23
24
25
26
27
# File 'lib/fanforce/worker/errors.rb', line 23

def self.list_summaries(queue_id, from_num=0, to_num=100, reverse=false)
  error_ids = redis.lrange("ERRORS:#{queue_id}", from_num, to_num)
  error_ids.reverse! if reverse
  Fanforce::Worker::ErrorList.new(queue_id, error_ids).summaries
end

.redisObject



9
10
11
# File 'lib/fanforce/worker/errors.rb', line 9

def self.redis
  @@redis ||= Redis.new(url: Fanforce::Worker.redis_url_errorlog)
end

.retry_all(queue_id, error_ids) ⇒ Object



33
34
35
# File 'lib/fanforce/worker/errors.rb', line 33

def self.retry_all(queue_id, error_ids)
  Fanforce::Worker::ErrorList.new(queue_id, error_ids).retry
end