11import * as Sentry from '@sentry/node' ;
2- import { PrismaClient , Repo , RepoJobStatus , RepoJobType } from "@sourcebot/db" ;
2+ import { PrismaClient , Repo , RepoIndexingJobStatus , RepoIndexingJobType } from "@sourcebot/db" ;
33import { createLogger , Logger } from "@sourcebot/logger" ;
44import { existsSync } from 'fs' ;
55import { readdir , rm } from 'fs/promises' ;
@@ -97,7 +97,7 @@ export class RepoIndexManager {
9797 some : {
9898 AND : [
9999 {
100- type : RepoJobType . INDEX ,
100+ type : RepoIndexingJobType . INDEX ,
101101 } ,
102102 {
103103 OR : [
@@ -108,8 +108,8 @@ export class RepoIndexManager {
108108 {
109109 status : {
110110 in : [
111- RepoJobStatus . PENDING ,
112- RepoJobStatus . IN_PROGRESS ,
111+ RepoIndexingJobStatus . PENDING ,
112+ RepoIndexingJobStatus . IN_PROGRESS ,
113113 ]
114114 } ,
115115 } ,
@@ -123,7 +123,7 @@ export class RepoIndexManager {
123123 // Don't schedule if there are recent failed jobs (within the threshold date).
124124 {
125125 AND : [
126- { status : RepoJobStatus . FAILED } ,
126+ { status : RepoIndexingJobStatus . FAILED } ,
127127 { completedAt : { gt : thresholdDate } } ,
128128 ]
129129 }
@@ -139,7 +139,7 @@ export class RepoIndexManager {
139139 } ) ;
140140
141141 if ( reposToIndex . length > 0 ) {
142- await this . createJobs ( reposToIndex , RepoJobType . INDEX ) ;
142+ await this . createJobs ( reposToIndex , RepoIndexingJobType . INDEX ) ;
143143 }
144144 }
145145
@@ -161,13 +161,13 @@ export class RepoIndexManager {
161161 some : {
162162 AND : [
163163 {
164- type : RepoJobType . CLEANUP ,
164+ type : RepoIndexingJobType . CLEANUP ,
165165 } ,
166166 {
167167 status : {
168168 in : [
169- RepoJobStatus . PENDING ,
170- RepoJobStatus . IN_PROGRESS ,
169+ RepoIndexingJobStatus . PENDING ,
170+ RepoIndexingJobStatus . IN_PROGRESS ,
171171 ]
172172 } ,
173173 } ,
@@ -184,15 +184,15 @@ export class RepoIndexManager {
184184 } ) ;
185185
186186 if ( reposToCleanup . length > 0 ) {
187- await this . createJobs ( reposToCleanup , RepoJobType . CLEANUP ) ;
187+ await this . createJobs ( reposToCleanup , RepoIndexingJobType . CLEANUP ) ;
188188 }
189189 }
190190
191- private async createJobs ( repos : Repo [ ] , type : RepoJobType ) {
191+ private async createJobs ( repos : Repo [ ] , type : RepoIndexingJobType ) {
192192 // @note : we don't perform this in a transaction because
193193 // we want to avoid the situation where a job is created and run
194194 // prior to the transaction being committed.
195- const jobs = await this . db . repoJob . createManyAndReturn ( {
195+ const jobs = await this . db . repoIndexingJob . createManyAndReturn ( {
196196 data : repos . map ( repo => ( {
197197 type,
198198 repoId : repo . id ,
@@ -222,12 +222,12 @@ export class RepoIndexManager {
222222 logger . info ( `Running ${ job . data . type } job ${ id } for repo ${ job . data . repoName } (id: ${ job . data . repoId } ) (attempt ${ job . attempts + 1 } / ${ job . maxAttempts } )` ) ;
223223
224224
225- const { repo, type : jobType } = await this . db . repoJob . update ( {
225+ const { repo, type : jobType } = await this . db . repoIndexingJob . update ( {
226226 where : {
227227 id,
228228 } ,
229229 data : {
230- status : RepoJobStatus . IN_PROGRESS ,
230+ status : RepoIndexingJobStatus . IN_PROGRESS ,
231231 } ,
232232 select : {
233233 type : true ,
@@ -253,9 +253,9 @@ export class RepoIndexManager {
253253 process . on ( 'SIGINT' , signalHandler ) ;
254254
255255 try {
256- if ( jobType === RepoJobType . INDEX ) {
256+ if ( jobType === RepoIndexingJobType . INDEX ) {
257257 await this . indexRepository ( repo , logger , abortController . signal ) ;
258- } else if ( jobType === RepoJobType . CLEANUP ) {
258+ } else if ( jobType === RepoIndexingJobType . CLEANUP ) {
259259 await this . cleanupRepository ( repo , logger ) ;
260260 }
261261 } finally {
@@ -370,15 +370,15 @@ export class RepoIndexManager {
370370 private onJobCompleted = async ( job : Job < JobPayload > ) =>
371371 groupmqLifecycleExceptionWrapper ( 'onJobCompleted' , logger , async ( ) => {
372372 const logger = createJobLogger ( job . data . jobId ) ;
373- const jobData = await this . db . repoJob . update ( {
373+ const jobData = await this . db . repoIndexingJob . update ( {
374374 where : { id : job . data . jobId } ,
375375 data : {
376- status : RepoJobStatus . COMPLETED ,
376+ status : RepoIndexingJobStatus . COMPLETED ,
377377 completedAt : new Date ( ) ,
378378 }
379379 } ) ;
380380
381- if ( jobData . type === RepoJobType . INDEX ) {
381+ if ( jobData . type === RepoIndexingJobType . INDEX ) {
382382 const repo = await this . db . repo . update ( {
383383 where : { id : jobData . repoId } ,
384384 data : {
@@ -388,7 +388,7 @@ export class RepoIndexManager {
388388
389389 logger . info ( `Completed index job ${ job . data . jobId } for repo ${ repo . name } (id: ${ repo . id } )` ) ;
390390 }
391- else if ( jobData . type === RepoJobType . CLEANUP ) {
391+ else if ( jobData . type === RepoIndexingJobType . CLEANUP ) {
392392 const repo = await this . db . repo . delete ( {
393393 where : { id : jobData . repoId } ,
394394 } ) ;
@@ -405,10 +405,10 @@ export class RepoIndexManager {
405405 const wasLastAttempt = attempt >= job . opts . attempts ;
406406
407407 if ( wasLastAttempt ) {
408- const { repo } = await this . db . repoJob . update ( {
408+ const { repo } = await this . db . repoIndexingJob . update ( {
409409 where : { id : job . data . jobId } ,
410410 data : {
411- status : RepoJobStatus . FAILED ,
411+ status : RepoIndexingJobStatus . FAILED ,
412412 completedAt : new Date ( ) ,
413413 errorMessage : job . failedReason ,
414414 } ,
@@ -428,10 +428,10 @@ export class RepoIndexManager {
428428 private onJobStalled = async ( jobId : string ) =>
429429 groupmqLifecycleExceptionWrapper ( 'onJobStalled' , logger , async ( ) => {
430430 const logger = createJobLogger ( jobId ) ;
431- const { repo } = await this . db . repoJob . update ( {
431+ const { repo } = await this . db . repoIndexingJob . update ( {
432432 where : { id : jobId } ,
433433 data : {
434- status : RepoJobStatus . FAILED ,
434+ status : RepoIndexingJobStatus . FAILED ,
435435 completedAt : new Date ( ) ,
436436 errorMessage : 'Job stalled' ,
437437 } ,
0 commit comments