Skip to content

Commit

Permalink
dispatch github scan google
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Aug 27, 2024
1 parent af0c03f commit a14a280
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 544 deletions.
24 changes: 15 additions & 9 deletions apps/event-worker/src/target-scan/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { TargetScanEvent } from "@ctrlplane/validators/events";
import { Queue, Worker } from "bullmq";
import ms from "ms";
import { Job, Queue, Worker } from "bullmq";

import { eq, takeFirstOrNull } from "@ctrlplane/db";
import { db } from "@ctrlplane/db/client";
Expand All @@ -17,8 +16,10 @@ import { getGkeTargets } from "./gke.js";
import { upsertTargets } from "./upsert.js";

const targetScanQueue = new Queue(Channel.TargetScan, { connection: redis });
const requeue = (data: any, delay: number) =>
targetScanQueue.add(Channel.TargetScan, data, { delay });
const removeTargetJob = (job: Job) =>
job.repeatJobKey != null
? targetScanQueue.removeRepeatableByKey(job.repeatJobKey)
: null;

export const createTargetScanWorker = () =>
new Worker<TargetScanEvent>(
Expand All @@ -36,7 +37,11 @@ export const createTargetScanWorker = () =>
eq(targetProvider.id, targetProviderGoogle.targetProviderId),
)
.then(takeFirstOrNull);
if (tp == null) return;

if (tp == null) {
await removeTargetJob(job);
return;
}

logger.info(
`Received scanning request for "${tp.target_provider.name}" (${targetProviderId}).`,
Expand All @@ -51,9 +56,10 @@ export const createTargetScanWorker = () =>

await upsertTargets(db, tp.workspace.id, gkeTargets);
}

await requeue(job.data, ms("5m"));
//
},
{ connection: redis, concurrency: 10 },
{
connection: redis,
removeOnComplete: { age: 0, count: 0 },
concurrency: 10,
},
);
3 changes: 0 additions & 3 deletions apps/target-provider/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions apps/target-provider/eslint.config.js

This file was deleted.

34 changes: 0 additions & 34 deletions apps/target-provider/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions apps/target-provider/src/config.ts

This file was deleted.

215 changes: 0 additions & 215 deletions apps/target-provider/src/google.ts

This file was deleted.

41 changes: 0 additions & 41 deletions apps/target-provider/src/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions apps/target-provider/src/targets.ts

This file was deleted.

Loading

0 comments on commit a14a280

Please sign in to comment.