-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f0f8bf
commit 31cdb50
Showing
7 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Cron, CronExpression } from '@nestjs/schedule'; | ||
import { | ||
dbGetTaskGroupUsers, | ||
dbGetTaskGroupsToCreateForCurrentInterval, | ||
} from './db/functions/task-group'; | ||
import { dbGetAssignmentsForTaskGroup } from './db/functions/assignment-task-group'; | ||
|
||
@Injectable() | ||
export class AssignmentSchedulerService { | ||
@Cron(CronExpression.EVERY_5_SECONDS) | ||
async handleCron() { | ||
const taskGroupsToCreateAssignmentsFor = | ||
await dbGetTaskGroupsToCreateForCurrentInterval(); | ||
for (const { taskGroupId } of taskGroupsToCreateAssignmentsFor) { | ||
const users = await dbGetTaskGroupUsers(taskGroupId); | ||
const assignments = await dbGetAssignmentsForTaskGroup( | ||
taskGroupId, | ||
users.length, | ||
); | ||
console.log({ assignments }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AssignmentSchedulerService } from './assignment-scheduler.service'; | ||
|
||
@Module({ | ||
providers: [AssignmentSchedulerService], | ||
}) | ||
export class AssignmentsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { desc, eq } from 'drizzle-orm'; | ||
import { db } from '..'; | ||
import { taskGroupAssignmentTable } from '../schema'; | ||
|
||
export async function dbGetAssignmentsForTaskGroup( | ||
taskGroupId: number, | ||
limit?: number, | ||
) { | ||
const result = db | ||
.select() | ||
.from(taskGroupAssignmentTable) | ||
.where(eq(taskGroupAssignmentTable.taskGroupId, taskGroupId)) | ||
.orderBy(desc(taskGroupAssignmentTable.createdAt)); | ||
if (limit === undefined) { | ||
return await result; | ||
} | ||
return await result.limit(limit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters