Class: SidekiqUniqueJobs::Changelog
- Inherits:
-
Redis::SortedSet
- Object
- Redis::Entity
- Redis::SortedSet
- SidekiqUniqueJobs::Changelog
- Defined in:
- lib/sidekiq_unique_jobs/changelog.rb
Overview
Class Changelogs provides access to the changelog entries
Constant Summary
Constants inherited from Redis::SortedSet
Redis::SortedSet::DEFAULT_COUNT, Redis::SortedSet::SCAN_PATTERN
Instance Attribute Summary
Attributes inherited from Redis::Entity
Instance Method Summary collapse
-
#add(message:, digest:, job_id:, script:) ⇒ void
Adds a new changelog entry.
-
#entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) ⇒ Array<Hash>
The change log entries.
-
#initialize ⇒ Changelog
constructor
A new instance of Changelog.
-
#page(cursor: 0, pattern: "*", page_size: 100) ⇒ Array<Integer, Integer, Array<Hash>] the total size, next cursor and changelog entries
Paginate the changelog entries.
Methods inherited from Redis::SortedSet
Methods inherited from Redis::Entity
#count, #exist?, #expires?, #pttl, #ttl
Methods included from Timing
clock_stamp, now_f, time_source, timed
Methods included from JSON
dump_json, load_json, safe_load_json
Methods included from Script::Caller
call_script, debug_lua, do_call, extract_args, max_history, normalize_argv, 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
Constructor Details
#initialize ⇒ Changelog
Returns a new instance of Changelog.
10 11 12 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 10 def initialize super(CHANGELOGS) end |
Instance Method Details
#add(message:, digest:, job_id:, script:) ⇒ void
This method returns an undefined value.
Adds a new changelog entry
24 25 26 27 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 24 def add(message:, digest:, job_id:, script:) = dump_json(message: , digest: digest, job_id: job_id, script: script) redis { |conn| conn.zadd(key, now_f, ) } end |
#entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) ⇒ Array<Hash>
The change log entries
37 38 39 40 41 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 37 def entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) redis do |conn| conn.zscan(key, match: pattern, count: count).to_a.map { |entry| load_json(entry[0]) } end end |
#page(cursor: 0, pattern: "*", page_size: 100) ⇒ Array<Integer, Integer, Array<Hash>] the total size, next cursor and changelog entries
Paginate the changelog entries
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 52 def page(cursor: 0, pattern: "*", page_size: 100) redis do |conn| total_size, result = conn.multi do |pipeline| pipeline.zcard(key) pipeline.zscan(key, cursor, match: pattern, count: page_size) end # NOTE: When debugging, check the last item in the returned array. [ total_size.to_i, result[0].to_i, # next_cursor result[1].map { |entry| load_json(entry) }.select { |entry| entry.is_a?(Hash) }, ] end end |