Module: Resque::Plugins::Queue::Status
- Defined in:
- lib/resque/plugins/queue/status.rb,
lib/resque/plugins/queue/status/version.rb
Overview
Resque::Plugins::Queue::Status. It provides adding simple queue statuses for your jobs. You can specify your own key for your queues and check the status.
You can use it doing extend Resque::Plugins::Queue::Status
For example
class ExampleJob
extend Resque::Plugins::Queue::Status
def self.perform()
puts 'hoge'
end
end
Resque.enqueue(ExampleJob, queue_status_key: 'hoge')
ExampleJob.current_queue_status('hoge')
The queue status key lasts 24 hours to expire
Constant Summary collapse
- IN_PROGESS =
'IN_PROGESS'
- COMPLETED =
'COMPLETED'
- FAILED =
'FAILED'
- STATUSES =
[IN_PROGESS, COMPLETED, FAILED].freeze
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #_namespaced_queue_status(queue_status_key) ⇒ Object
- #_prefix ⇒ Object
- #_queue_status_key(args) ⇒ Object
- #_set_status(args) ⇒ Object
- #after_perform_queue_status(args) ⇒ Object
- #all_queue_statuses ⇒ Object
- #before_enqueue_queue_status(args) ⇒ Object
- #clear_all_queue_statuses ⇒ Object
- #current_queue_status(queue_status_key) ⇒ Object
- #on_failure_queue_status(err, args) ⇒ Object
Instance Method Details
#_namespaced_queue_status(queue_status_key) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/resque/plugins/queue/status.rb', line 78 def _namespaced_queue_status(queue_status_key) return if queue_status_key.nil? queue_status_key_name = Resque::Job.decode( Resque::Job.encode(queue_status_key) ) "#{_prefix}:#{queue_status_key_name}" end |
#_prefix ⇒ Object
100 101 102 |
# File 'lib/resque/plugins/queue/status.rb', line 100 def _prefix "queuestatus:#{name}" end |
#_queue_status_key(args) ⇒ Object
74 75 76 |
# File 'lib/resque/plugins/queue/status.rb', line 74 def _queue_status_key(args) args['queue_status_key'] || args[:queue_status_key] end |
#_set_status(args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resque/plugins/queue/status.rb', line 87 def _set_status(args) queue_status = _namespaced_queue_status(args[:queue_status_key]) return if queue_status.nil? Resque.redis.set( queue_status, args.slice(:status, :meta).to_json, ex: 24 * 60 * 60 ) queue_status end |
#after_perform_queue_status(args) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/resque/plugins/queue/status.rb', line 44 def after_perform_queue_status(args) _set_status( queue_status_key: _queue_status_key(args), status: COMPLETED ) end |
#all_queue_statuses ⇒ Object
66 67 68 |
# File 'lib/resque/plugins/queue/status.rb', line 66 def all_queue_statuses Resque.redis.keys("#{_prefix}:*") end |
#before_enqueue_queue_status(args) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/resque/plugins/queue/status.rb', line 37 def before_enqueue_queue_status(args) _set_status( queue_status_key: _queue_status_key(args), status: IN_PROGESS ) end |
#clear_all_queue_statuses ⇒ Object
70 71 72 |
# File 'lib/resque/plugins/queue/status.rb', line 70 def clear_all_queue_statuses Resque.redis.del(*all_queue_statuses) unless all_queue_statuses.empty? end |
#current_queue_status(queue_status_key) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/resque/plugins/queue/status.rb', line 59 def current_queue_status(queue_status_key) JSON.parse( Resque.redis.get(_namespaced_queue_status(queue_status_key)) || '{}', symbolize_names: true ) end |
#on_failure_queue_status(err, args) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/resque/plugins/queue/status.rb', line 51 def on_failure_queue_status(err, args) _set_status( queue_status_key: _queue_status_key(args), status: FAILED, meta: err.to_yaml ) end |