-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split calculator into two separate (#474)
* Split calculator into two separate Also kills a lot of duplication in using temporary configuration. * Updates documentation * Lock down simplecov to last known working version
- Loading branch information
Showing
47 changed files
with
449 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,14 @@ module SidekiqUniqueJobs | |
# @author Mikael Henriksson <[email protected]> | ||
# | ||
class Cli < Thor | ||
# :nodoc: | ||
def self.banner(command, _namespace = nil, _subcommand = false) | ||
"jobs #{@package_name} #{command.usage}" # rubocop:disable ThreadSafety/InstanceVariableInClassMethod | ||
end | ||
|
||
desc "list PATTERN", "list all unique digests and their expiry time" | ||
option :count, aliases: :c, type: :numeric, default: 1000, desc: "The max number of digests to return" | ||
# :nodoc: | ||
def list(pattern = "*") | ||
entries = digests.entries(pattern: pattern, count: options[:count]) | ||
say "Found #{entries.size} digests matching '#{pattern}':" | ||
|
@@ -24,6 +26,7 @@ def list(pattern = "*") | |
desc "del PATTERN", "deletes unique digests from redis by pattern" | ||
option :dry_run, aliases: :d, type: :boolean, desc: "set to false to perform deletion" | ||
option :count, aliases: :c, type: :numeric, default: 1000, desc: "The max number of digests to return" | ||
# :nodoc: | ||
def del(pattern) | ||
max_count = options[:count] | ||
if options[:dry_run] | ||
|
@@ -36,6 +39,7 @@ def del(pattern) | |
end | ||
|
||
desc "console", "drop into a console with easy access to helper methods" | ||
# :nodoc: | ||
def console | ||
say "Use `list '*', 1000 to display the first 1000 unique digests matching '*'" | ||
say "Use `del '*', 1000, true (default) to see how many digests would be deleted for the pattern '*'" | ||
|
@@ -46,10 +50,12 @@ def console | |
end | ||
|
||
no_commands do | ||
# :nodoc: | ||
def digests | ||
@digests ||= SidekiqUniqueJobs::Digests.new | ||
end | ||
|
||
# :nodoc: | ||
def console_class | ||
require "pry" | ||
Pry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,15 @@ module SidekiqUniqueJobs | |
# | ||
# @author Mauro Berlanda <[email protected]> | ||
class Config < ThreadSafeConfig | ||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available queued locks | ||
LOCKS_WHILE_ENQUEUED = { | ||
until_executing: SidekiqUniqueJobs::Lock::UntilExecuting, | ||
while_enqueued: SidekiqUniqueJobs::Lock::UntilExecuting, | ||
}.freeze | ||
|
||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available fulltime locks | ||
LOCKS_FROM_PUSH_TO_PROCESSED = { | ||
until_completed: SidekiqUniqueJobs::Lock::UntilExecuted, | ||
until_executed: SidekiqUniqueJobs::Lock::UntilExecuted, | ||
|
@@ -39,10 +43,14 @@ class Config < ThreadSafeConfig | |
until_successfully_completed: SidekiqUniqueJobs::Lock::UntilExecuted, | ||
}.freeze | ||
|
||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available locks without unlock | ||
LOCKS_WITHOUT_UNLOCK = { | ||
until_expired: SidekiqUniqueJobs::Lock::UntilExpired, | ||
}.freeze | ||
|
||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available runtime/client locks | ||
LOCKS_WHEN_BUSY = { | ||
around_perform: SidekiqUniqueJobs::Lock::WhileExecuting, | ||
while_busy: SidekiqUniqueJobs::Lock::WhileExecuting, | ||
|
@@ -51,13 +59,17 @@ class Config < ThreadSafeConfig | |
while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject, | ||
}.freeze | ||
|
||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available default locks | ||
LOCKS = | ||
LOCKS_WHEN_BUSY.dup | ||
.merge(LOCKS_WHILE_ENQUEUED.dup) | ||
.merge(LOCKS_WITHOUT_UNLOCK.dup) | ||
.merge(LOCKS_FROM_PUSH_TO_PROCESSED.dup) | ||
.freeze | ||
|
||
# | ||
# @return [Hash<Symbol, SidekiqUniqueJobs::OnConflict::Strategy] all available default strategies | ||
STRATEGIES = { | ||
log: SidekiqUniqueJobs::OnConflict::Log, | ||
raise: SidekiqUniqueJobs::OnConflict::Raise, | ||
|
@@ -66,18 +78,44 @@ class Config < ThreadSafeConfig | |
reschedule: SidekiqUniqueJobs::OnConflict::Reschedule, | ||
}.freeze | ||
|
||
# | ||
# @return ['uniquejobs'] by default we use this prefix | ||
PREFIX = "uniquejobs" | ||
# | ||
# @return [0] by default don't wait for locks | ||
LOCK_TIMEOUT = 0 | ||
# | ||
# @return [nil] | ||
LOCK_TTL = nil | ||
# | ||
# @return [true] by default the gem is enabled | ||
ENABLED = true | ||
# | ||
# @return [false] by default we don't debug the lua scripts because it is slow | ||
DEBUG_LUA = false | ||
# | ||
# @return [1_000] use a changelog history of 1_000 entries by default | ||
MAX_HISTORY = 1_000 | ||
REAPER = :ruby # The type of cleanup to run. Possible values are [:ruby, :lua] | ||
# | ||
# @return [:ruby] prefer the ruby reaper by default since the lua reaper still has problems | ||
REAPER = :ruby | ||
# | ||
# @return [1_000] reap 1_000 orphaned locks at a time by default | ||
REAPER_COUNT = 1_000 | ||
REAPER_INTERVAL = 600 # Every 10 minutes | ||
REAPER_TIMEOUT = 10 # 10 seconds | ||
# | ||
# @return [600] reap locks every 10 minutes | ||
REAPER_INTERVAL = 600 | ||
# | ||
# @return [10] stop reaper after 10 seconds | ||
REAPER_TIMEOUT = 10 | ||
# | ||
# @return [false] while useful it also adds overhead so disable lock_info by default | ||
USE_LOCK_INFO = false | ||
# | ||
# @return [false] by default we don't raise validation errors for workers | ||
RAISE_ON_CONFIG_ERROR = false | ||
# | ||
# @return [0.0.0] default redis version is only to avoid NoMethodError on nil | ||
REDIS_VERSION = "0.0.0" | ||
|
||
# | ||
|
@@ -185,6 +223,12 @@ def add_strategy(name, klass) | |
self.strategies = new_strategies | ||
end | ||
|
||
# | ||
# The current version of redis | ||
# | ||
# | ||
# @return [String] a version string eg. `5.0.1` | ||
# | ||
def redis_version | ||
self.current_redis_version = SidekiqUniqueJobs.fetch_redis_version if current_redis_version == REDIS_VERSION | ||
current_redis_version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ def initialize(lock_config) | |
# | ||
# @author Mikael Henriksson <[email protected]> | ||
class InvalidUniqueArguments < UniqueJobsError | ||
def initialize(**options) | ||
def initialize(options) | ||
given = options[:given] | ||
worker_class = options[:worker_class] | ||
unique_args_method = options[:unique_args_method] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.