Created
August 26, 2014 18:11
-
-
Save smathy/5fb11a7b21a1ccc4e1e0 to your computer and use it in GitHub Desktop.
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 Cancelerizer | |
def cancel arg | |
Sidekiq::ScheduledSet.new.each do |job| | |
(klass, method, args) = YAML.load job.args.first | |
if self == klass and args.first == arg | |
job.delete | |
end | |
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
class SomeWorker | |
include Sidekiq::Worker | |
extend Cancelerizer | |
def self.delayed_something path | |
cancel path | |
delay_for( 2.minutes ).process path | |
end | |
def self.process path | |
puts "Processing #{path}" | |
end | |
end |
We do it in different layers too actually, we have that sort of short delay for our incoming FSEvents (so that the OSX drag-and-drop internals don't trigger our processing too soon, and also so our Editorial can change their minds and remove something they've added, or so they can correct a mistaken add/delete) and then we have a bigger 20.minutes
delay for a process that zips a directory of assets and uploads them to our CDN.
Editorial can spend hours adding files, and each new addition pushes the zip & upload out. We've basically estimated that 20 minute delay based on their work process, concluding that if there's been nothing for 20 minutes then they've finished adding assets for that zip.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very simple process, allows any worker to cancel all scheduled jobs for a given argument (the first argument). You can make this cancel more jobs by using a different first argument, eg. you could change the
self.process
to take a directory name as its first arg, then the specific path as its second - then the cancel could cancel all the scheduled jobs for a whole directory created bySomeWorker
.