MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / runJob

Method runJob

packages/backend/src/connectionManager.ts:158–290  ·  view source on GitHub ↗
(job: Job<JobPayload>)

Source from the content-addressed store, hash-verified

156 }
157
158 private async runJob(job: Job<JobPayload>): Promise<JobResult> {
159 const { jobId, connectionName } = job.data;
160 const logger = createJobLogger(jobId);
161 logger.debug(`Running connection sync job ${jobId} for connection ${connectionName} (id: ${job.data.connectionId})`);
162
163 const currentStatus = await this.db.connectionSyncJob.findUniqueOrThrow({
164 where: {
165 id: jobId,
166 },
167 select: {
168 status: true,
169 }
170 });
171
172 // Fail safe: if the job is not PENDING (first run) or IN_PROGRESS (retry), it indicates the job
173 // is in an invalid state and should be skipped.
174 if (currentStatus.status !== ConnectionSyncJobStatus.PENDING && currentStatus.status !== ConnectionSyncJobStatus.IN_PROGRESS) {
175 throw new Error(`Job ${jobId} is not in a valid state. Expected: ${ConnectionSyncJobStatus.PENDING} or ${ConnectionSyncJobStatus.IN_PROGRESS}. Actual: ${currentStatus.status}. Skipping.`);
176 }
177
178 this.promClient.pendingConnectionSyncJobs.dec({ connection: connectionName });
179 this.promClient.activeConnectionSyncJobs.inc({ connection: connectionName });
180
181 const { connection: { config: rawConnectionConfig, orgId } } = await this.db.connectionSyncJob.update({
182 where: {
183 id: jobId,
184 },
185 data: {
186 status: ConnectionSyncJobStatus.IN_PROGRESS,
187 },
188 select: {
189 connection: {
190 select: {
191 config: true,
192 orgId: true,
193 }
194 }
195 },
196 });
197
198 const config = rawConnectionConfig as unknown as ConnectionConfig;
199
200 const result = await (async () => {
201 switch (config.type) {
202 case 'github': {
203 return await compileGithubConfig(config, job.data.connectionId, this.abortController.signal);
204 }
205 case 'gitlab': {
206 return await compileGitlabConfig(config, job.data.connectionId);
207 }
208 case 'gitea': {
209 return await compileGiteaConfig(config, job.data.connectionId);
210 }
211 case 'gerrit': {
212 return await compileGerritConfig(config, job.data.connectionId);
213 }
214 case 'bitbucket': {
215 return await compileBitbucketConfig(config, job.data.connectionId);

Callers

nothing calls this directly

Calls 8

compileGithubConfigFunction · 0.85
compileGitlabConfigFunction · 0.85
compileGiteaConfigFunction · 0.85
compileGerritConfigFunction · 0.85
compileBitbucketConfigFunction · 0.85
compileAzureDevOpsConfigFunction · 0.85
createJobLoggerFunction · 0.70

Tested by

no test coverage detected