1
1
import type { Job } from "bullmq" ;
2
2
import type { SchedulerJobData } from "@wei/probot-scheduler" ;
3
- import type { Probot } from "probot" ;
3
+ import type { Logger , Probot , ProbotOctokit } from "probot" ;
4
4
import logger from "@/src/utils/logger.ts" ;
5
5
import { getPullConfig } from "@/src/utils/get-pull-config.ts" ;
6
6
import { Pull } from "@/src/processor/pull.ts" ;
7
7
8
+ const TIMEOUT = 60 * 1000 ;
9
+
10
+ function createTimeoutPromise ( log : Logger ) {
11
+ return new Promise ( ( _ , reject ) => {
12
+ setTimeout ( ( ) => {
13
+ log . warn ( "⏰ Job timed out after 1 minute" ) ;
14
+ reject ( new Error ( "Job timed out after 1 minute" ) ) ;
15
+ } , TIMEOUT ) ;
16
+ } ) ;
17
+ }
18
+
19
+ async function processRepo (
20
+ octokit : ProbotOctokit ,
21
+ jobData : SchedulerJobData ,
22
+ log : Logger ,
23
+ ) {
24
+ const { owner, repo } = jobData ;
25
+
26
+ const config = await getPullConfig ( octokit , log , jobData ) ;
27
+ if ( ! config ) {
28
+ log . info ( `⚠️ No config found, skipping` ) ;
29
+ return ;
30
+ }
31
+
32
+ const pull = new Pull ( octokit , { owner, repo, logger : log } , config ) ;
33
+ await pull . routineCheck ( ) ;
34
+ }
35
+
8
36
export function getRepoProcessor ( probot : Probot ) {
9
37
return async function RepoJobProcessor ( job : Job < SchedulerJobData > ) {
10
38
const log = logger . child ( {
@@ -14,23 +42,18 @@ export function getRepoProcessor(probot: Probot) {
14
42
15
43
log . info ( "🏃 Processing repo job" ) ;
16
44
17
- const { installation_id, owner, repo } = job . data ;
18
-
19
45
try {
20
- const octokit = await probot . auth ( installation_id ) ;
21
-
22
- const config = await getPullConfig ( octokit , log , job . data ) ;
23
- if ( ! config ) {
24
- log . info ( `⚠️ No config found, skipping` ) ;
25
- return ;
26
- }
46
+ const octokit = await probot . auth ( job . data . installation_id ) ;
27
47
28
- const pull = new Pull ( octokit , { owner, repo, logger : log } , config ) ;
29
- await pull . routineCheck ( ) ;
48
+ await Promise . race ( [
49
+ processRepo ( octokit , job . data , log ) ,
50
+ createTimeoutPromise ( log ) ,
51
+ ] ) ;
30
52
31
- log . info ( `✅ Repo job ${ job . id } processed successfully` ) ;
53
+ log . info ( `✅ Repo job processed successfully` ) ;
32
54
} catch ( error ) {
33
- log . error ( error , "❌ Repo job failed" ) ;
55
+ const message = error instanceof Error ? error . message : "Unknown error" ;
56
+ log . error ( error , `❌ Repo job failed: ${ message } ` ) ;
34
57
}
35
58
} ;
36
59
}
0 commit comments