Skip to content
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

Separate drip types #26

Merged
merged 12 commits into from
Apr 24, 2023
Merged

Separate drip types #26

merged 12 commits into from
Apr 24, 2023

Conversation

joshmn
Copy link
Owner

@joshmn joshmn commented Apr 18, 2023

PeriodicalDrip needs some love — I don't have the bandwidth right now to document it fully (I also don't use it!) but tests should pass. Feel free to pick up where I left off.

@codecov
Copy link

codecov bot commented Apr 18, 2023

Codecov Report

Patch coverage: 97.93% and project coverage change: -0.06 ⚠️

Comparison is base (30bf0ca) 98.64% compared to head (c0bedfe) 98.58%.

❗ Current head c0bedfe differs from pull request most recent head 0117dcc. Consider uploading reports for the commit 0117dcc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
- Coverage   98.64%   98.58%   -0.06%     
==========================================
  Files          98      101       +3     
  Lines        2502     2612     +110     
==========================================
+ Hits         2468     2575     +107     
- Misses         34       37       +3     
Impacted Files Coverage Δ
lib/caffeinate/dripper/callbacks.rb 97.14% <ø> (ø)
spec/caffeinate/drip_collection_spec.rb 100.00% <ø> (ø)
lib/caffeinate/periodical_drip.rb 89.47% <89.47%> (ø)
spec/caffeinate/periodical_drip_spec.rb 95.65% <95.65%> (ø)
app/models/caffeinate/campaign_subscription.rb 100.00% <100.00%> (ø)
app/models/caffeinate/mailing.rb 93.33% <100.00%> (ø)
lib/caffeinate.rb 95.45% <100.00%> (+0.21%) ⬆️
lib/caffeinate/drip.rb 97.67% <100.00%> (+2.67%) ⬆️
lib/caffeinate/dripper/drip.rb 100.00% <100.00%> (ø)
lib/caffeinate/dripper/drip_collection.rb 100.00% <100.00%> (ø)
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@joshmn joshmn marked this pull request as ready for review April 20, 2023 18:24
@@ -97,7 +97,7 @@ def user
# Assigns attributes to the Mailing from the Drip
def from_drip(drip)
self.send_at = drip.send_at(self)
self.mailer_class = drip.options[:mailer_class]
self.mailer_class = drip.options[:mailer_class] || drip.options[:action_class]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hate this. move to just assuming action_class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be too generic here, but what about just deliverer?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same idea. just need to get away from mailer_class in v3

@@ -97,7 +97,7 @@ def user
# Assigns attributes to the Mailing from the Drip
def from_drip(drip)
self.send_at = drip.send_at(self)
self.mailer_class = drip.options[:mailer_class]
self.mailer_class = drip.options[:mailer_class] || drip.options[:action_class]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be too generic here, but what about just deliverer?

Comment on lines +60 to +62
# @option options [Symbol|Proc|ActiveSupport::Duration] :every How often the mailing should be created
# @option options [Symbol|Proc] :if If the periodical should create another mailing
# @option options [Symbol|Proc] :start The offset time to start the clock (only used on the first mailing creation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this API 👍

  • :every a static value or proc that yields an amount of time that ought to be used for the 'next' message in the sequence
    • I wonder if this should also support using a specific time or date rather than an amount of time — we can probably just call .respond_to? :from_now to see if it's a specific date or just an ActiveSupport::Duration
  • :if a proc that, if yields false, ends the periodical altogether — probably should run before the actual send so that it doesn't send the message at hand if false
  • :start a static value or proc that yields an amount of time that will be added to 'right now' to set the firing date for the first message only.
    • Same note here to consider adding support for specific times/dates as well as durations

I wonder if we should add the until logic to this PR?

  • :until a proc that, if yields true, ends the periodical altogether (probably also before_drip)
    • Thinking that true == end because the usage will probably be like until: -> { subscriber.is_opted_out? } or until: -> { Date.current.year > 2023 }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't until the same as if?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: deliver_class — yeah, something like that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't until the same as if?

Ah, I suppose it is, just the ! of one another. The implementation under the hood here could be as simple as that too, but I think it'd be worth exposing both for the consumer; depending on their method names, one will read better than the other.

if :user_still_wants_emails

unless :user_opted_out_of_emails

Comment on lines 17 to 30
if (mailing.drip.action == action_name) && (thing = mailing.drip.options[:if])
if OptionEvaluator.new(thing, mailing.drip, mailing).call
if mailing.drip.action == action_name
next_mailing = mailing.dup
next_mailing.send_at = mailing.drip.send_at(mailing)
next_mailing.save!
end
end
else
if mailing.drip.action == action_name
next_mailing = mailing.dup
next_mailing.send_at = mailing.drip.send_at(mailing)
next_mailing.save!
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mailing.drip.action == action_name) && (thing = mailing.drip.options[:if])
if OptionEvaluator.new(thing, mailing.drip, mailing).call
if mailing.drip.action == action_name
next_mailing = mailing.dup
next_mailing.send_at = mailing.drip.send_at(mailing)
next_mailing.save!
end
end
else
if mailing.drip.action == action_name
next_mailing = mailing.dup
next_mailing.send_at = mailing.drip.send_at(mailing)
next_mailing.save!
end
if (mailing.drip.action == action_name)
return unless (thing = mailing.drip.options[:if]) && OptionEvaluator.new(thing, mailing.drip, mailing).call
next_mailing = mailing.dup
next_mailing.send_at = mailing.drip.send_at(mailing)
next_mailing.save!
end

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isn't required and we still want to queue things up, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, yeah, that

return unless (thing = mailing.drip.options[:if]) && OptionEvaluator.new(thing, mailing.drip, mailing).call

should be

return if (thing = mailing.drip.options[:if]) && !OptionEvaluator.new(thing, mailing.drip, mailing).call

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns break proc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah; I always forget about that. next works for those situations, but having the more verbose code is also fine 😛 either way!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah; I always forget about that. next works for those situations, but having the more verbose code is also fine 😛 either way!

@joshmn joshmn merged commit 7da8bb1 into master Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants