Skip to content

Instantly share code, notes, and snippets.

@smathy
Created August 26, 2014 18:11
Show Gist options
  • Save smathy/5fb11a7b21a1ccc4e1e0 to your computer and use it in GitHub Desktop.
Save smathy/5fb11a7b21a1ccc4e1e0 to your computer and use it in GitHub Desktop.
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
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
@smathy
Copy link
Author

smathy commented Aug 26, 2014

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