Class: Fanforce::Worker::Error

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

Constant Summary collapse

SUMMARY_FIELDS =
[:error_id, :exception, :message, :errored_at, :raw_json, :retries]
DETAIL_FIELDS =
[:error_id, :exception, :http_code, :message, :backtrace, :errored_at, :raw_json, :env_vars, :retries, :curl_command]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_id, error_id) ⇒ Error

Returns a new instance of Error.



74
75
76
77
# File 'lib/fanforce/worker/errors.rb', line 74

def initialize(queue_id, error_id)
  @queue_id = queue_id
  @error_id = error_id
end

Class Method Details

.delete(queue_id, error_id) ⇒ Object



106
107
108
109
# File 'lib/fanforce/worker/errors.rb', line 106

def self.delete(queue_id, error_id)
  redis.lrem("ERRORS:#{queue_id}", 0, error_id)
  redis.del("ERRORS:#{queue_id}:#{error_id}")
end

.format(error) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/fanforce/worker/errors.rb', line 119

def self.format(error)
  error.each do |k,v|
    error[k] = case k
      when :backtrace then MultiJson.load(v) rescue []
      when :env_vars then  MultiJson.load(v) rescue {}
      when :retries then v.to_i
      else v
    end
  end
end

.format_details(details) ⇒ Object



134
135
136
# File 'lib/fanforce/worker/errors.rb', line 134

def self.format_details(details)
  format(Hash[DETAIL_FIELDS.zip(details)])
end

.format_summary(summary) ⇒ Object



115
116
117
# File 'lib/fanforce/worker/errors.rb', line 115

def self.format_summary(summary)
  format(Hash[SUMMARY_FIELDS.zip(summary)])
end

.get_all(queue_id, error_id) ⇒ Object



138
139
140
# File 'lib/fanforce/worker/errors.rb', line 138

def self.get_all(queue_id, error_id)
  redis.hgetall("ERRORS:#{queue_id}:#{error_id}")
end

.get_details(queue_id, error_id) ⇒ Object



130
131
132
# File 'lib/fanforce/worker/errors.rb', line 130

def self.get_details(queue_id, error_id)
  redis.hmget("ERRORS:#{queue_id}:#{error_id}", *DETAIL_FIELDS)
end

.get_summary(queue_id, error_id) ⇒ Object



111
112
113
# File 'lib/fanforce/worker/errors.rb', line 111

def self.get_summary(queue_id, error_id)
  redis.hmget("ERRORS:#{queue_id}:#{error_id}", *SUMMARY_FIELDS)
end

.redisObject



104
# File 'lib/fanforce/worker/errors.rb', line 104

def self.redis; Fanforce::Worker::Errors.redis end

.retry(queue_id, raw_error) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/fanforce/worker/errors.rb', line 142

def self.retry(queue_id, raw_error)
  error = format(raw_error.symbolize_keys)
  payload = MultiJson.load(error[:raw_json], symbolize_keys: true) rescue {}
  Fanforce::Worker.set_config(iron_token: error[:iron_token], iron_project_id: error[:iron_project_id])
  Fanforce::Worker.enqueue(queue_id, payload, :retries => error[:retries] + 1)
  delete(queue_id, error[:error_id])
end

Instance Method Details

#deleteObject



79
80
81
82
# File 'lib/fanforce/worker/errors.rb', line 79

def delete
  self.class.delete(@queue_id, @error_id)
  return nil
end

#detailsObject



84
85
86
87
# File 'lib/fanforce/worker/errors.rb', line 84

def details
  v = self.class.get_details(@queue_id, @error_id)
  self.class.format_details(v)
end

#retryObject



94
95
96
97
# File 'lib/fanforce/worker/errors.rb', line 94

def retry
  v = Error.get_all(@queue_id, @error_id)
  Error.retry(@queue_id, v)
end

#summaryObject



89
90
91
92
# File 'lib/fanforce/worker/errors.rb', line 89

def summary
  v = self.class.get_summary(@queue_id, @error_id)
  self.class.format_summary(v)
end