-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Periodical support and jitter #23
Comments
I actually almost like this idea too:
|
Under the hood previous_mailing.send_at + params[:every] # e.g. 2.weeks Which, is already pretty close to being jitter-able, but currently |
Ah, and one other note about your API thought there ^ (a separate issue we should open) is that calling drip :welcome, repeat: true, at: :set_time
drip :welcome, repeat: 5, at: :set_time
drip :welcome, repeat: :repeat?, at: :set_time Would effectively ignore/skip the first two calls and only that third |
I think the ideal periodical API ought to support a dynamic # these wouldn't be used together, they're just examples
drip :follow_up, every: 2.weeks, until: 10.weeks.from_now
drip :follow_up, every: -> { 2.weeks + rand(0..2).days + rand(0..100).minutes }, start: -> { recipient.next_appropriate_messageable_time }
drip :follow_up, every: -> { recipient.drip_frequency }, until: -> { recipient.out_of_drips? } (Note that There's enough difference here from the standard drip :initial_follow_up, class_name: UserMailer, delay: 10.minutes
periodic_drip :new_post_round_up, class_name: UserMailer, every: -> { recipient.summary_email_frequency } but I'm not sure if that's better or worse 😛 |
Ah, to my last idea, I think that's already the case. I didn't realize it before but I think that while the class SomeDripper
drip :initial_follow_up, class_name: UserMailer, at: 10.minutes.from_now
periodical :new_post_round_up, class_name: UserMailer, every: 10.days
end That's a big note! 😅 |
Ah, sorry — should clarify: that was just one example for Do you have any instance where you have a mix of periodic and regular one-off drips in a Dripper? |
I don't know that my app has that at the moment, but it's definitely something I could see us doing |
I'm starting down the track of supporting a # lib/caffeinate/schedule_evaluator.rb
if periodical?
start = mailing.instance_exec(&options[:start])
start += options[:every] if mailing.caffeinate_campaign_subscription.caffeinate_mailings.count.positive?
date = start.from_now
elsif options[:on]
date = OptionEvaluator.new(options[:on], self, mailing).call
else
date = OptionEvaluator.new(options[:delay], self, mailing).call
if date.respond_to?(:from_now)
date = date.from_now
end
end And the idea that I have a dripper setup like so: periodical :round_up, every: 5.days, start: -> { 3.hours } Let's say I subscribe the user to the dripper at 9am on 2/1/23. But then we skip ahead to 12:05pm — the message is sent. The I think that's unexpected? 🤔 I'd expect the That said, technically, that means we can already introduce 'jitter' by using periodical :round_up, every: 14.days, start: -> { rand(0..2).days + rand(0..60).minutes } In the above, we setup a "jitter amount" of 0-2 days + 0-1 hours. The first message will send after the random jitter amount, then every subsequent message will send (2 weeks + the jitter amount) later — which is the goal! 😆 Interesting. |
Discussion continued from #21 (comment)
This is an interesting use case I didn't quite fully think through!
I wonder if it would make sense to support something like:
I can't quite remember where/how periodical determines time. It's poorly documented (if that) because I haven't quite used it yet myself... hehe. It could also probably be reworked to hook into the callbacks as well if it's not already.
@jon-sully thoughts?
The text was updated successfully, but these errors were encountered: