diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-10-25 01:07:00 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2022-10-25 15:19:33 +0200 |
commit | 1bfbfb0317263be46869150f6673f014e8ef0ae8 (patch) | |
tree | a91cd724c7492ebee3b87860cda0b5a9f7a1de98 /lib/argument_deduplication.rb | |
parent | 30453fab80d55fc10766f0e067c31d96753ccfda (diff) | |
download | mastodon-feature-argument-deduplication.tar mastodon-feature-argument-deduplication.tar.gz mastodon-feature-argument-deduplication.tar.bz2 mastodon-feature-argument-deduplication.zip |
Add deduplication for JSON payloads in job queuefeature-argument-deduplication
Diffstat (limited to 'lib/argument_deduplication.rb')
-rw-r--r-- | lib/argument_deduplication.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/argument_deduplication.rb b/lib/argument_deduplication.rb new file mode 100644 index 000000000..f271b6f96 --- /dev/null +++ b/lib/argument_deduplication.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require_relative './argument_deduplication/argument' +require_relative './argument_deduplication/server' +require_relative './argument_deduplication/client' + +module ArgumentDeduplication + class CorruptedArgumentError < ::RuntimeError; end + + PREFIX = 'argument_store' + + # The time-to-live is based on the maximum amount of time + # a job can possibly spend in the retry queue, assuming + # the exponential backoff algorithm and a maximum number + # of 16 retries. It is intended as a safe-guard against + # any arguments being orphaned due to interruptions. + TTL = 50.days.to_i + + DEATH_HANDLER = ->(job) { + Argument.new(job['args'][job['deduplicate_arguments']]).pop! if job['deduplicate_arguments'] + }.freeze + + def self.configure(config) + config.death_handlers << DEATH_HANDLER + end +end |