Skip to content

Commit

Permalink
init refactor (#225)
Browse files Browse the repository at this point in the history
Co-authored-by: Aditya Choudhari <[email protected]>
  • Loading branch information
jsbroks and adityachoudhari26 authored Nov 22, 2024
1 parent cd5c075 commit c4f2532
Show file tree
Hide file tree
Showing 16 changed files with 732 additions and 640 deletions.
3 changes: 2 additions & 1 deletion apps/pty-proxy/src/controller/agent-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class AgentSocket {
"name" | "version" | "kind" | "identifier" | "workspaceId"
>,
) {
const [res] = await upsertResources(db, [
const { updated } = await upsertResources(db, [
{
...resource,
name: this.name,
Expand All @@ -136,6 +136,7 @@ export class AgentSocket {
updatedAt: new Date(),
},
]);
const res = updated.at(0);
if (res == null) throw new Error("Failed to create resource");
this.resource = res;
agents.set(res.id, { lastSync: new Date(), agent: this });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export const PATCH = request()
{ status: 404 },
);

const t = await upsertResources(db, [_.merge(resource, body)]);

return NextResponse.json(t[0]);
const { updated } = await upsertResources(db, [_.merge(resource, body)]);
const res = updated.at(0);
if (res == null) throw new Error("Failed to update resource");
return NextResponse.json(res);
});

export const DELETE = request()
Expand Down
2 changes: 1 addition & 1 deletion apps/webservice/src/app/api/v1/resources/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ export const POST = request()
})),
);

return NextResponse.json({ count: resources.length });
return NextResponse.json({ count: resources.all.length });
},
);
4 changes: 2 additions & 2 deletions packages/api/src/router/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
updateEnvironment,
} from "@ctrlplane/db/schema";
import {
dispatchJobsForNewResources,
dispatchJobsForAddedResources,
getEventsForEnvironmentDeleted,
handleEvent,
} from "@ctrlplane/job-dispatch";
Expand Down Expand Up @@ -324,7 +324,7 @@ export const environmentRouter = createTRPCRouter({
}

if (newResources.length > 0) {
await dispatchJobsForNewResources(
await dispatchJobsForAddedResources(
ctx.db,
newResources.map((r) => r.id),
input.id,
Expand Down
2 changes: 0 additions & 2 deletions packages/job-dispatch/src/events/triggers/resource-deleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { ResourceFilterType } from "@ctrlplane/validators/resources";

/**
* Get events for a resource that has been deleted.
* NOTE: Because we may need to do inner joins on resource metadata for the filter,
* this actually needs to be called before the resource is actually deleted.
* @param resource
*/
export const getEventsForResourceDeleted = async (
Expand Down
3 changes: 1 addition & 2 deletions packages/job-dispatch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export * from "./policy-checker.js";
export * from "./policy-create.js";
export * from "./release-sequencing.js";
export * from "./gradual-rollout.js";
export * from "./new-resource.js";
export * from "./resource.js";
export * from "./lock-checker.js";
export * from "./queue.js";

Expand All @@ -24,3 +22,4 @@ export * from "./policies/release-window.js";
export * from "./environment-creation.js";
export * from "./pending-job-checker.js";
export * from "./events/index.js";
export * from "./resource/index.js";
80 changes: 0 additions & 80 deletions packages/job-dispatch/src/new-resource.ts

This file was deleted.

Loading

0 comments on commit c4f2532

Please sign in to comment.