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 collapse
- DEFAULT_COUNT =
Returns the number of matches to return by default.
1_000
- SCAN_PATTERN =
Returns the default pattern to use for matching.
"*"
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, 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.
17 18 19 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 17 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
31 32 33 34 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 31 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 44 def entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) = {} [:match] = pattern [:count] = count redis do |conn| conn.zscan_each(key, **).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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sidekiq_unique_jobs/changelog.rb', line 63 def page(cursor: 0, pattern: "*", page_size: 100) redis do |conn| total_size, result = conn.multi do conn.zcard(key) conn.zscan(key, cursor, match: pattern, count: page_size) end [ total_size.to_i, result[0].to_i, # next_cursor result[1].map { |entry| load_json(entry[0]) }, # entries ] end end |