Class: SidekiqUniqueJobs::OnConflict::Reject
- Includes:
- Timing
- Defined in:
- lib/sidekiq_unique_jobs/on_conflict/reject.rb
Overview
Strategy to send jobs to dead queue
Instance Attribute Summary
Attributes inherited from Strategy
Instance Method Summary collapse
-
#call ⇒ Object
Send jobs to dead queue.
-
#deadset ⇒ Sidekiq::Deadset
private
An instance of Sidekiq::Deadset.
-
#deadset_kill ⇒ void
private
Use Sidekiqs built in Sidekiq::DeadSet#kill to get rid of the job.
-
#deadset_kill? ⇒ true, false
private
Sidekiq version compatibility check.
-
#kill_job_with_options ⇒ void
private
Executes the kill instructions with arguments.
-
#kill_job_without_options ⇒ void
private
Executes the kill instructions without arguments.
-
#kill_with_options? ⇒ true, false
private
Sidekiq version compatibility check.
-
#payload ⇒ String
The Sidekiq job hash as JSON.
-
#push_to_deadset ⇒ void
Used for compatibility with older Sidekiq versions.
Methods included from Timing
clock_stamp, now_f, time_source, timed
Methods inherited from Strategy
Methods included from Script::Caller
call_script, debug_lua, do_call, extract_args, max_history, now_f, redis_version
Methods included from Logging
#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context
Methods included from JSON
dump_json, load_json, safe_load_json
Constructor Details
This class inherits a constructor from SidekiqUniqueJobs::OnConflict::Strategy
Instance Method Details
#call ⇒ Object
Send jobs to dead queue
12 13 14 15 16 17 18 19 20 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 12 def call log_info { "Adding dead #{item[CLASS]} job #{item[JID]}" } if deadset_kill? deadset_kill else push_to_deadset end end |
#deadset ⇒ Sidekiq::Deadset
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An instance of Sidekiq::Deadset
87 88 89 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 87 def deadset @deadset ||= Sidekiq::DeadSet.new end |
#deadset_kill ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Use Sidekiqs built in Sidekiq::DeadSet#kill
to get rid of the job
41 42 43 44 45 46 47 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 41 def deadset_kill if else end end |
#deadset_kill? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sidekiq version compatibility check
29 30 31 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 29 def deadset_kill? deadset.respond_to?(:kill) end |
#kill_job_with_options ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Executes the kill instructions with arguments
77 78 79 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 77 def deadset.kill(payload, notify_failure: false) end |
#kill_job_without_options ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Executes the kill instructions without arguments
67 68 69 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 67 def deadset.kill(payload) end |
#kill_with_options? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sidekiq version compatibility check
57 58 59 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 57 def Sidekiq::DeadSet.instance_method(:kill).arity > 1 end |
#payload ⇒ String
The Sidekiq job hash as JSON
113 114 115 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 113 def payload @payload ||= dump_json(item) end |
#push_to_deadset ⇒ void
This method returns an undefined value.
Used for compatibility with older Sidekiq versions
97 98 99 100 101 102 103 104 105 |
# File 'lib/sidekiq_unique_jobs/on_conflict/reject.rb', line 97 def push_to_deadset redis do |conn| conn.multi do |pipeline| pipeline.zadd("dead", now_f, payload) pipeline.zremrangebyscore("dead", "-inf", now_f - Sidekiq::DeadSet.timeout) pipeline.zremrangebyrank("dead", 0, -Sidekiq::DeadSet.max_jobs) end end end |