-
Notifications
You must be signed in to change notification settings - Fork 122
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
Changes from 2 commits
0148ad8
1e57d1a
742a5f5
4c08b02
3b01ffe
673aa05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { format } from "date-fns/format"; | ||
import { QueryTypes } from "sequelize"; | ||
import { Op, QueryTypes } from "sequelize"; | ||
|
||
import type { Workspace } from "@app/lib/models"; | ||
import { AgentConfiguration, Conversation, DataSource } from "@app/lib/models"; | ||
|
||
import { frontSequelize } from "./resources/storage"; | ||
|
||
|
@@ -94,3 +97,28 @@ export async function unsafeGetUsageData( | |
|
||
return csvHeader + csvContent; | ||
} | ||
|
||
/** | ||
* Check if a workspace is active during a trial based on the following conditions: | ||
* - Existence of a connected data source | ||
* - Existence of a custom assistant | ||
* - A conversation occurred within the past 7 days | ||
*/ | ||
export async function checkWorkspaceActivity(workspace: Workspace) { | ||
const sevenDaysAgo = new Date(); | ||
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); | ||
|
||
const hasConnectedDataSource = await DataSource.findOne({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Connection and folder do create a data source 🙃. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seen IRL, fixed. |
||
where: { workspaceId: workspace.id }, | ||
}); | ||
|
||
const hasCreatedAssistant = await AgentConfiguration.findOne({ | ||
where: { workspaceId: workspace.id }, | ||
}); | ||
|
||
const hasRecentConversation = await Conversation.findOne({ | ||
where: { workspaceId: workspace.id, updatedAt: { [Op.gte]: sevenDaysAgo } }, | ||
}); | ||
|
||
return hasConnectedDataSource || hasCreatedAssistant || hasRecentConversation; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.