Last active
August 29, 2015 14:05
-
-
Save ess/984ad5b2e0f0e7306491 to your computer and use it in GitHub Desktop.
This file contains 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
def all_delayed_timestamps | |
guess = 100 | |
current = [] | |
until (current = Resque.delayed_queue_peek(0, guess)).size < guess | |
guess = guess * guess | |
end | |
current | |
end | |
def all_delayed_jobs | |
all_delayed_timestamps.map {|timestamp| | |
Resque.delayed_timestamp_peek(timestamp, 0, Resque.delayed_timestamp_size(timestamp)) | |
}.flatten | |
end | |
def delayed_daily_broadcasts | |
all_delayed_jobs. | |
select {|job| job['class'] =~ /::DailyBroadcast/} | |
end | |
def delayed_wrapup_broadcasts | |
all_delayed_jobs. | |
select {|job| job['class'] =~ /::WrapupBroadcast/} | |
end | |
def active_subscription_ids | |
delayed_daily_broadcasts.map {|x| x['args'].first.to_i}.sort.uniq | |
end | |
def nuke_daily_broadcasts_for(subscription) | |
subscription.journey.days.each do |day| | |
puts "nuking subscription #{subscription.id} day #{day.number} job" | |
case subscription.type | |
when 'EmailSubscription' | |
Resque.remove_delayed(JourneyMailer::DailyBroadcast, subscription.id, day.id) | |
when 'SMSSubscription' | |
Resque.remove_delayed(SMS::DailyBroadcast, subscription.id, day.id) | |
end | |
puts Time.now | |
end | |
end | |
def randomly_nuke_subscriptions | |
until (sub_id = active_subscription_ids.sample).nil? | |
nuke_daily_broadcasts_for(Subscription.find(sub_id)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment