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

Proactively cancel inactive trials 3 days before end #4553

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

flvndvd
Copy link
Contributor

@flvndvd flvndvd commented Apr 3, 2024

Description

Fixes https://github.com/dust-tt/tasks/issues/608.

This PR introduces a listener for Stripe's customer.subscription.trial_will_end event, which is triggered 3 days before a trial ends. On this event, we assess whether the trial has been active, based on the following criteria:

  • The presence of a connected data source
  • The existence of a custom assistant
  • A conversation that occurred within the past 7 days

If none of the above criteria are met, we will proactively cancel the subscription.

⚠️ However, this does not apply to trials that will end in less than 3 days, as those will be canceled manually.

We will also send an email when proactively canceling a trial, this will be done in a follow up PR.

Risk

Deploy Plan

@flvndvd flvndvd marked this pull request as ready for review April 3, 2024 14:46
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);

const hasConnectedDataSource = await DataSource.findOne({
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to consider as active if there's a Connection or if there's a Connection or a Folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Connection and folder do create a data source 🙃.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seen IRL, fixed.

/**
* Proactively cancel inactive trials.
*/
export async function maybeCancelInactiveTrials(
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT suggestion: Since this will I believe not be reusable anywhere else I would kill and do that directly on the webhook. ff we want to keep here I would just rename to be clearer -> cancelSubscriptionIfInactiveTrial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to use it in a script to cancel the trials that won't be captured by this change.

Copy link
Contributor

@lasryaric lasryaric left a comment

Choose a reason for hiding this comment

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

Would be nice to add visibility on that event by sending a message on our #user_workspace-event-logs.
Example here: github

Copy link
Contributor

@lasryaric lasryaric left a comment

Choose a reason for hiding this comment

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

LGTM

@flvndvd flvndvd merged commit b5a5d13 into main Apr 4, 2024
5 checks passed
@flvndvd flvndvd deleted the flav/proactively-cancel-inactive-trials branch April 4, 2024 08:51
flvndvd added a commit that referenced this pull request May 26, 2024
* Proactively cancel inactive trials 3 days before end

* ✂️

* ✨

* Send email when canceling trial proactively

* ✂️

* Log in Slack
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.

3 participants