Skip to content

Commit

Permalink
add new cron jobs and change cron expression (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
portuu3 authored Jan 9, 2024
1 parent ffc05f8 commit f957962
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { WebhookService } from './webhook.service';
export class WebhookController {
constructor(private readonly webhookService: WebhookService) {}
@Public()
@Get('/cron/launch')
public async processPendingCronJob(): Promise<any> {
await this.webhookService.processPendingCronJob();
@Get('/cron')
public async processPendingWebhooks(): Promise<any> {
await this.webhookService.processPendingWebhooks();
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe('WebhookService', () => {

const startCronJobMock = jest.spyOn(cronJobService, 'startCronJob');

await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(startCronJobMock).not.toHaveBeenCalled();
});
Expand All @@ -354,15 +354,15 @@ describe('WebhookService', () => {
.spyOn(cronJobService, 'startCronJob')
.mockResolvedValueOnce(cronJobEntityMock as any);

await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(cronJobService.startCronJob).toHaveBeenCalledWith(
CronJobType.ProcessPendingWebhook,
);
});

it('should send webhook for all of the pending webhooks', async () => {
await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(sendWebhookMock).toHaveBeenCalledTimes(2);
expect(sendWebhookMock).toHaveBeenCalledWith(webhookEntity1);
Expand All @@ -382,7 +382,7 @@ describe('WebhookService', () => {
it('should increase retriesCount by 1 if sending webhook fails', async () => {
sendWebhookMock.mockRejectedValueOnce(new Error());

await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(webhookRepository.updateOne).toHaveBeenCalledWith(
{ id: webhookEntity1.id },
Expand All @@ -398,7 +398,7 @@ describe('WebhookService', () => {

webhookEntity1.retriesCount = MOCK_MAX_RETRY_COUNT;

await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(webhookRepository.updateOne).toHaveBeenCalledWith(
{ id: webhookEntity1.id },
Expand All @@ -411,7 +411,7 @@ describe('WebhookService', () => {
.spyOn(cronJobService, 'completeCronJob')
.mockResolvedValueOnce(cronJobEntityMock as any);

await (webhookService as any).processPendingCronJob();
await (webhookService as any).processPendingWebhooks();

expect(cronJobService.completeCronJob).toHaveBeenCalledWith(
cronJobEntityMock as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class WebhookService {
* @returns {Promise<void>} - Returns a promise that resolves when the operation is complete.
*/
@Cron(CronExpression.EVERY_10_MINUTES)
public async processPendingCronJob(): Promise<void> {
public async processPendingWebhooks(): Promise<void> {
const isCronJobRunning = await this.cronJobService.isCronJobRunning(
CronJobType.ProcessPendingWebhook,
);
Expand Down
18 changes: 15 additions & 3 deletions packages/apps/job-launcher/server/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@
],
"crons": [
{
"path": "/job/cron/launch",
"schedule": "*/1 * * * *"
"path": "/job/cron/create-escrow",
"schedule": "*/10 * * * *"
},
{
"path": "/job/cron/setup-escrow",
"schedule": "*/10 * * * *"
},
{
"path": "/job/cron/fund-escrow",
"schedule": "*/10 * * * *"
},
{
"path": "/job/cron/cancel",
"schedule": "*/1 * * * *"
"schedule": "*/10 * * * *"
},
{
"path": "/webhook/cron",
"schedule": "*/10 * * * *"
}
],
"ignoreCommand": "git diff HEAD^ HEAD --quiet ."
Expand Down

1 comment on commit f957962

@vercel
Copy link

@vercel vercel bot commented on f957962 Jan 9, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.