Last active
June 7, 2016 10:11
-
-
Save bernstein7/e202e984993add636111e6a26379a5d4 to your computer and use it in GitHub Desktop.
Sidekiq::JidStorage
This file contains hidden or 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
| require 'active_support/concern' | |
| module Sidekiq::Cancelable | |
| extend ActiveSupport::Concern | |
| included do | |
| include Redis::Objects | |
| attr_accessor :id | |
| value :stored_jid | |
| def self.perform_at(timestamp, *args) | |
| stored_jid = super(timestamp, *args) | |
| worker = self.new | |
| worker.id = args.first.id | |
| worker.stored_jid = stored_jid | |
| end | |
| def self.cancel!(schedulable) | |
| worker = self.new | |
| worker.id = schedulable.id | |
| cancel_by_jid(worker.stored_jid) | |
| end | |
| def self.cancel_by_jid(jid) | |
| Sidekiq.redis { |c| c.setex("cancelled-#{jid}", 86400, 1) } | |
| end | |
| def cancelled? | |
| Sidekiq.redis { |c| c.exists("cancelled-#{jid}") } | |
| end | |
| end | |
| end |
This file contains hidden or 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
| Notifications::Scheduler.cancel!(job) |
This file contains hidden or 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
| module Notifications | |
| class Scheduler | |
| include Sidekiq::Worker | |
| include Sidekiq::Cancelable | |
| sidekiq_options retry: false, queue: 'session_notifications' | |
| def perform(job_id) | |
| job = Job.find(job_id) | |
| Notification::SessionNotifier.send_reminder!(job) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment