Skip to content

Commit

Permalink
chore: scope of work listner improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed May 25, 2024
1 parent 1fe59f9 commit 449d32f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"cors": "^2.8.5",
"document-drive": "1.0.0-alpha.57",
"document-model": "1.2.0",
"document-model-libs": "^1.53.1",
"document-model-libs": "^1.54.0-experimental",
"dotenv": "^16.4.5",
"esbuild": "^0.21.2",
"ethers": "^5.7.2",
Expand Down Expand Up @@ -74,4 +74,4 @@
"typescript": "^5.4.5",
"vitest-mock-extended": "^1.3.1"
}
}
}
14 changes: 7 additions & 7 deletions api/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions api/src/modules/scope-of-work/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getChildLogger } from "../../logger";
import { Prisma } from "@prisma/client";
import { Octokit } from "@octokit/rest";

const GITHUB_REPO_OWNER = "powerhouse";
const GITHUB_REPO_NAME = "rwa";
const GITHUB_REPO_OWNER = "powerhouse-inc";
const GITHUB_REPO_NAME = "powerhouse-mirror";
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
Expand Down Expand Up @@ -48,22 +48,20 @@ async function handleScopeOfWorkDocument(strand: InternalTransmitterUpdate<Scope

async function updateDeliverableInDb(driveId: string, documentId: string, deliverableId: string, prisma: Prisma.TransactionClient) {
try {
await prisma.scopeOfWorkDeliverable.findUnique({
await prisma.scopeOfWorkDeliverable.findFirstOrThrow({
where: {
id_driveId_documentId: {
id: deliverableId,
driveId: driveId,
documentId: documentId,
}
id: deliverableId,
driveId: driveId,
documentId: documentId
}
})
return false;
return true;
} catch (e) {
console.log("deliverable not found in db")
logger.info("deliverable not found in db")
}

try {
await createGitHubIssue("New Deliverable Created", "A new deliverable has been created in the scope of work document")

await prisma.scopeOfWorkDeliverable.create({
data: {
id: deliverableId,
Expand All @@ -75,8 +73,10 @@ async function updateDeliverableInDb(driveId: string, documentId: string, delive
githubCreated: true
}
})

await createGitHubIssue("New Deliverable Created", "A new deliverable has been created in the scope of work document")
} catch (e) {
console.log(" Error creating github issue")
console.log("Error creating github issue")
}
}

Expand All @@ -89,7 +89,7 @@ async function createGitHubIssue(title: string, body: string) {
body: body,
});
} catch (error) {
logger.error("Error creating GitHub issue:", error);
logger.error({msg: "Error creating GitHub issue:", error});
throw error;
}
}
8 changes: 8 additions & 0 deletions api/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import logger from "./logger"

export const logMemory = (name?: string) => {

logger.info({
msg: `${name ? name : "Memory"}: ${Math.round(process.memoryUsage().rss / 1024 / 1024 * 100) / 100} MB`
})
}

0 comments on commit 449d32f

Please sign in to comment.