Skip to content

Commit 5e7da34

Browse files
committed
feat: in case of any error, avoid crashing the worker
1 parent 56b7811 commit 5e7da34

File tree

4 files changed

+53
-93
lines changed

4 files changed

+53
-93
lines changed

apps/workers/src/app/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Module } from '@nestjs/common';
22

3-
import { StarsController } from './stars.controller';
43
import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/database.module';
54
import { TrendingService } from '@gitroom/nestjs-libraries/services/trending.service';
65
import { PostsController } from '@gitroom/workers/app/posts.controller';
@@ -10,7 +9,6 @@ import { PlugsController } from '@gitroom/workers/app/plugs.controller';
109
@Module({
1110
imports: [DatabaseModule, BullMqModule],
1211
controllers: [
13-
...(!process.env.IS_GENERAL ? [StarsController] : []),
1412
PostsController,
1513
PlugsController,
1614
],

apps/workers/src/app/plugs.controller.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export class PlugsController {
1414
totalRuns: number;
1515
currentRun: number;
1616
}) {
17-
return this._integrationService.processPlugs(data);
17+
try {
18+
return await this._integrationService.processPlugs(data);
19+
} catch (err) {
20+
console.log(
21+
"Unhandled error, let's avoid crashing the plugs worker",
22+
err
23+
);
24+
}
1825
}
1926

2027
@EventPattern('internal-plugs', Transport.REDIS)
@@ -27,6 +34,13 @@ export class PlugsController {
2734
delay: number;
2835
information: any;
2936
}) {
30-
return this._integrationService.processInternalPlug(data);
37+
try {
38+
return await this._integrationService.processInternalPlug(data);
39+
} catch (err) {
40+
console.log(
41+
"Unhandled error, let's avoid crashing the internal plugs worker",
42+
err
43+
);
44+
}
3145
}
3246
}

apps/workers/src/app/posts.controller.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,59 @@ export class PostsController {
1818
try {
1919
return await this._postsService.post(data.id);
2020
} catch (err) {
21-
console.log('Unhandled error, let\'s avoid crashing the worker', err);
21+
console.log("Unhandled error, let's avoid crashing the post worker", err);
2222
}
2323
}
2424

2525
@EventPattern('submit', Transport.REDIS)
2626
async payout(data: { id: string; releaseURL: string }) {
27-
return this._postsService.payout(data.id, data.releaseURL);
27+
try {
28+
return await this._postsService.payout(data.id, data.releaseURL);
29+
} catch (err) {
30+
console.log(
31+
"Unhandled error, let's avoid crashing the submit worker",
32+
err
33+
);
34+
}
2835
}
2936

3037
@EventPattern('sendDigestEmail', Transport.REDIS)
3138
async sendDigestEmail(data: { subject: string; org: string; since: string }) {
32-
return this._postsService.sendDigestEmail(
33-
data.subject,
34-
data.org,
35-
data.since
36-
);
39+
try {
40+
return await this._postsService.sendDigestEmail(
41+
data.subject,
42+
data.org,
43+
data.since
44+
);
45+
} catch (err) {
46+
console.log(
47+
"Unhandled error, let's avoid crashing the digest worker",
48+
err
49+
);
50+
}
3751
}
3852

3953
@EventPattern('webhooks', Transport.REDIS)
4054
async webhooks(data: { org: string; since: string }) {
41-
return this._webhooksService.fireWebhooks(data.org, data.since);
55+
try {
56+
return await this._webhooksService.fireWebhooks(data.org, data.since);
57+
} catch (err) {
58+
console.log(
59+
"Unhandled error, let's avoid crashing the webhooks worker",
60+
err
61+
);
62+
}
4263
}
4364

4465
@EventPattern('cron', Transport.REDIS)
4566
async cron(data: { id: string }) {
46-
return this._autopostsService.startAutopost(data.id);
67+
try {
68+
return await this._autopostsService.startAutopost(data.id);
69+
} catch (err) {
70+
console.log(
71+
"Unhandled error, let's avoid crashing the autopost worker",
72+
err
73+
);
74+
}
4775
}
4876
}

apps/workers/src/app/stars.controller.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)