@@ -4,13 +4,12 @@ import { createLogger } from "./logger.js";
44import { Connection , PrismaClient , Repo , RepoToConnection , RepoIndexingStatus , StripeSubscriptionStatus } from "@sourcebot/db" ;
55import { GithubConnectionConfig , GitlabConnectionConfig , GiteaConnectionConfig } from '@sourcebot/schemas/v3/connection.type' ;
66import { AppContext , Settings } from "./types.js" ;
7- import { captureEvent } from "./posthog.js" ;
87import { getRepoPath , getTokenFromConfig , measure , getShardPrefix } from "./utils.js" ;
98import { cloneRepository , fetchRepository } from "./git.js" ;
109import { existsSync , rmSync , readdirSync } from 'fs' ;
1110import { indexGitRepository } from "./zoekt.js" ;
1211import os from 'os' ;
13- import { BackendException } from "@sourcebot/error" ;
12+ import { PromClient } from './promClient.js' ;
1413
1514interface IRepoManager {
1615 blockingPollLoop : ( ) => void ;
@@ -34,6 +33,7 @@ export class RepoManager implements IRepoManager {
3433 private db : PrismaClient ,
3534 private settings : Settings ,
3635 redis : Redis ,
36+ private promClient : PromClient ,
3737 private ctx : AppContext ,
3838 ) {
3939 this . queue = new Queue < JobPayload > ( QUEUE_NAME , {
@@ -280,6 +280,7 @@ export class RepoManager implements IRepoManager {
280280 repoIndexingStatus : RepoIndexingStatus . INDEXING ,
281281 }
282282 } ) ;
283+ this . promClient . activeRepoIndexingJobs . inc ( ) ;
283284
284285 let indexDuration_s : number | undefined ;
285286 let fetchDuration_s : number | undefined ;
@@ -295,6 +296,7 @@ export class RepoManager implements IRepoManager {
295296 break ;
296297 } catch ( error ) {
297298 attempts ++ ;
299+ this . promClient . repoIndexingErrors . inc ( ) ;
298300 if ( attempts === maxAttempts ) {
299301 this . logger . error ( `Failed to sync repository ${ repo . id } after ${ maxAttempts } attempts. Error: ${ error } ` ) ;
300302 throw error ;
@@ -313,7 +315,9 @@ export class RepoManager implements IRepoManager {
313315
314316 private async onIndexJobCompleted ( job : Job < JobPayload > ) {
315317 this . logger . info ( `Repo index job ${ job . id } completed` ) ;
316-
318+ this . promClient . activeRepoIndexingJobs . dec ( ) ;
319+ this . promClient . repoIndexingSuccesses . inc ( ) ;
320+
317321 await this . db . repo . update ( {
318322 where : {
319323 id : job . data . repo . id ,
@@ -328,6 +332,9 @@ export class RepoManager implements IRepoManager {
328332 private async onIndexJobFailed ( job : Job < JobPayload > | undefined , err : unknown ) {
329333 this . logger . info ( `Repo index job failed (id: ${ job ?. id ?? 'unknown' } ) with error: ${ err } ` ) ;
330334 if ( job ) {
335+ this . promClient . activeRepoIndexingJobs . dec ( ) ;
336+ this . promClient . repoIndexingFails . inc ( ) ;
337+
331338 await this . db . repo . update ( {
332339 where : {
333340 id : job . data . repo . id ,
0 commit comments