Skip to content

Commit bf8c415

Browse files
committed
Add job to complete incomplete unboardings before releasing the new onboarding
We need to make sure all current users have the onboarding completed before removing the feature flag, else they will go through it when they already know how to use the app.
1 parent f598f41 commit bf8c415

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

apps/workers/src/workers/schedule.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ export async function setupSchedules() {
5151
{ pattern: '0 0 1 * * *' },
5252
{ opts: { attempts: 1 } },
5353
)
54+
55+
// Every day at 9 PM to add smth - This will be deleted after its run once
56+
await maintenanceQueue.upsertJobScheduler(
57+
'fillOnboardingsAsCompletedJob',
58+
{ pattern: '0 0 21 * * *' },
59+
{ opts: { attempts: 1 } },
60+
)
5461
}

apps/workers/src/workers/worker-definitions/maintenanceWorker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const jobMappings = {
1616
requestDocumentSuggestionsJob: jobs.requestDocumentSuggestionsJob,
1717
scaleDownMcpServerJob: jobs.scaleDownMcpServerJob,
1818
updateMcpServerLastUsedJob: jobs.updateMcpServerLastUsedJob,
19+
fillOnboardingsAsCompletedJob: jobs.fillOnboardingsAsCompletedJob,
1920
}
2021

2122
export function startMaintenanceWorker() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Job } from 'bullmq'
2+
import { Result } from '../../../lib/Result'
3+
import { workspaceOnboarding } from '../../../schema/models/workspaceOnboarding'
4+
import { database } from '../../../client'
5+
import { isNull } from 'drizzle-orm'
6+
7+
export type FillOnboardingsAsCompletedJobData = Record<string, never>
8+
9+
export const fillOnboardingsAsCompletedJob = async (
10+
_: Job<FillOnboardingsAsCompletedJobData>,
11+
) => {
12+
const updatedOnboardings = await database
13+
.update(workspaceOnboarding)
14+
.set({
15+
completedAt: new Date(),
16+
})
17+
.where(isNull(workspaceOnboarding.completedAt))
18+
.returning()
19+
20+
return Result.ok({
21+
success: true,
22+
updatedOnboardings: updatedOnboardings.length,
23+
})
24+
}

packages/core/src/jobs/job-definitions/maintenance/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './refreshProjectsStatsCacheJob'
44
export * from './refreshProjectStatsCacheJob'
55
export * from './scheduleWorkspaceCleanupJobs'
66
export * from './cleanupWorkspaceOldLogsJob'
7+
export * from './fillOnboardingsAsCompletedJob'

0 commit comments

Comments
 (0)