-
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
Expand Periodical API #41
Comments
And, just worth referencing, I wrote this PR some time ago: Which was based on this comment — explaining that start: -> do
if send_at.nil? # this is the first message in the sequence
(((subscriber.next_textable_time_after(Time.current) - Time.current)) / 1.minute).minutes # next afternoon delivery
else
0.minutes # don't offset on other messages; :every does that
end
end ... they're split because they have to figure out if they're running for the first mailing vs. all subsequent mailings. This just illustrating the issue that Second, and separate from the concept of "start should only be on the first message", we can see the hooks one must jump through in order to return a relative time rather than an absolute time when my helpers are more geared toward absolute times. That said, I've now realized that I can return absolute times in my There were some subtle changes in #26 that changed some expectations. I'd previously written my So... let me revise the above to a simpler version: start: -> do
if send_at.nil? # this is the first message in the sequence
subscriber.next_textable_time_after Time.current
else
Time.current # don't offset on other messages; :every does that
end
end This recognizes that def call
if periodical?
start = Caffeinate.config.now.call
if options[:start] # <== Doesn't check to see if this is the first message
start = OptionEvaluator.new(options[:start], self, mailing).call # <== so it always overrides `start`
end
start += OptionEvaluator.new(options[:every], self, mailing).call if mailing.caffeinate_campaign_subscription.caffeinate_mailings.size.positive?
date = start
elsif options[:on]
# ...
else
# ...
end
if date.respond_to?(:from_now)
date = date.from_now
end
# ...
date
end (Explanation of above) even on subsequent messages, the So wrapping this tangent up, BUT, now that periodical :unresponsive_perpetual_email, every: 0.minutes, start: -> { subscriber.next_textable_time_after Time.current } Since I also realized while digging here that we did add a boolean gate to the periodical, I just forgot about it! It's not periodical :unresponsive_perpetual_email, every: 1.hour, if: -> { subscriber.still_hasnt_paid? } ...With one careful caveat. periodical :unresponsive_perpetual_email, every: 1.hour, if: -> { subscriber.nag_count < 10 } I haven't played with it enough to have opinions yet but it feels like, since So.... yeah actually I think I'm good and maybe don't need to expand the time APIs for periodical? Probably will if we fix |
So, while I think I'm good for now, the simplest (and likely cleanest / best) path forward is probably to make |
Ah, one note for a future PR — if someone is using a periodical with the |
periodical
currently supportsevery:
andstart:
when it comes to parameters that control its time sequences. I think of these asBut sometimes these aren't the most ergonomic. Particularly in that both want a relative amount of time, not an absolute timestamp (which makes sense given their verbiage, 'start' and 'every'). But often times in models and systems it's easier to get to absolute timestamps.
In addition, I think it'd be a nice ergonomics win to add
:while
as a before-any-time-computations check as to whether or not the next periodical should even fire. I suppose this is no different than abefore_drip
check that.end!
's the subscription, but I feel like the ergonomics of having a:while
parameter that essentially only continues the sequence if it's given a proc that resolves to truthy is a good representation of most systems. I can imagine a lot of folks will use something likeSure, something like this is essentially equivalent:
But the ergonomics and expressiveness of the
:while
key directly on the periodical feels a lot cleaner... and I suppose it does allow you to have different:while
conditions for different periodicals within a single dripper. Thebefore_drip
approach would have to differentiate between multiple different periodicals manually in its logic (which would be icky!)In terms of the time APIs, I think we could add a
:next_at
keyword that expects to resolve to an absolute time:Now, all of that said, I just wanted to get my thoughts on paper here. I think we may already support some of this functionality and I've just missed it along the way. I'm going to begin this process by really looking over the options that are supported already with
periodical
and see if / how much would need to change to accomplish the above ideas 👍The text was updated successfully, but these errors were encountered: