Skip to content

Instantly share code, notes, and snippets.

@kinnalru
Last active October 28, 2020 08:29
Show Gist options
  • Save kinnalru/2ebb83e4faa2fa3ef4dd60091bc15d5b to your computer and use it in GitHub Desktop.
Save kinnalru/2ebb83e4faa2fa3ef4dd60091bc15d5b to your computer and use it in GitHub Desktop.
class DelayedJobPlugin
attr_reader :limiter, :dj
def initialize(limiter_klass:, **opts)
@limiter = limiter_klass.new(opts)
end
# Delayed::Worker вызовет new без агрументов у каждого плагина
def new(*_args)
configure_lifecycle(Delayed::Worker.lifecycle)
end
def configure_lifecycle lifecycle
lifecycle.after(:perform) do |worker, *_args|
worker.stop if limiter.check
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment