Skip to content

Commit

Permalink
added changes
Browse files Browse the repository at this point in the history
  • Loading branch information
YuvRaj6392 committed Oct 15, 2024
1 parent 05502e5 commit 028e768
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 14 deletions.
Binary file added Screenshot 2024-10-15 180911.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BACKEND_URL="http://localhost:3000"
export const HOOKS_URL="https://localhost:3002"
export const HOOKS_URL="http://localhost:3002"
5 changes: 0 additions & 5 deletions frontend/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export default function Page() {
const [email,setEmail]=useState("");
const [password,setPassword]=useState("");
const router=useRouter();
useEffect(()=>{
if(localStorage.getItem("token")){
router.push("/dashboard")
}
},[])
return (
<div>
<Appbar />
Expand Down
2 changes: 1 addition & 1 deletion hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "tsc -b && node dist/index.js"
"dev": "tsc -b && node dist/index.js"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion primaryBackend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "tsc -b && node dist/index.js"
"dev": "tsc -b && node dist/index.js"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion processor/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function main() {
topic: TOPIC_NAME,
messages: pendingRows.map(r => {
return {
value: r.zapRunId
value: JSON.stringify({ zapRunId: r.zapRunId, stage: 0 })
};
})
});
Expand Down
2 changes: 1 addition & 1 deletion processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "tsc -b && node dist/index.js"
"dev": "tsc -b && node dist/index.js"
},
"keywords": [],
"author": "",
Expand Down
3 changes: 3 additions & 0 deletions worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
56 changes: 54 additions & 2 deletions worker/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const kafkajs_1 = require("kafkajs");
const client_1 = require("@prisma/client");
const prismaClient = new client_1.PrismaClient();
const TOPIC_NAME = "zap-events";
const kafka = new kafkajs_1.Kafka({
clientId: "outbox-processor",
Expand All @@ -21,18 +23,68 @@ function main() {
groupId: "main-worker",
});
yield consumer.connect();
const producer = kafka.producer();
yield producer.connect();
yield consumer.subscribe({ topic: TOPIC_NAME, fromBeginning: true });
yield consumer.run({
autoCommit: false,
eachMessage: (_a) => __awaiter(this, [_a], void 0, function* ({ topic, partition, message }) {
var _b;
var _b, _c, _d, _e, _f;
console.log({
partition,
offset: message.offset,
value: (_b = message.value) === null || _b === void 0 ? void 0 : _b.toString(),
});
//
if (!((_c = message.value) === null || _c === void 0 ? void 0 : _c.toString())) {
return;
}
const parsedValue = JSON.parse((_d = message.value) === null || _d === void 0 ? void 0 : _d.toString());
const zapRunId = parsedValue.zapRunId;
const stage = parsedValue.stage;
const zapRunDetails = yield prismaClient.zapRun.findFirst({
where: {
id: zapRunId
},
include: {
zap: {
include: {
actions: {
include: {
type: true
}
}
}
}
}
});
const currentAction = zapRunDetails === null || zapRunDetails === void 0 ? void 0 : zapRunDetails.zap.actions.find(x => x.sortingOrder === stage);
if (!currentAction) {
console.log('Current action not found');
return;
}
console.log(currentAction);
if (currentAction.type.id === 'email') {
console.log('Sending out an email');
//parse out the email to send
}
if (currentAction.type.id === 'send-sol') {
console.log('Sending out solana');
//parse out the address and the amount to send
}
yield new Promise((r) => setTimeout(r, 500));
const zapId = (_e = message === null || message === void 0 ? void 0 : message.value) === null || _e === void 0 ? void 0 : _e.toString();
const lastStage = (((_f = zapRunDetails === null || zapRunDetails === void 0 ? void 0 : zapRunDetails.zap.actions) === null || _f === void 0 ? void 0 : _f.length) || 1) - 1;
if (lastStage !== stage) {
yield producer.send({
topic: TOPIC_NAME,
messages: [{
value: JSON.stringify({
stage: stage + 1,
zapRunId
})
}]
});
}
console.log('processing done');
//you can do your action operation here!
//
Expand Down
88 changes: 88 additions & 0 deletions worker/node_modules/.package-lock.json

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

107 changes: 107 additions & 0 deletions worker/package-lock.json

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

6 changes: 5 additions & 1 deletion worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "tsc -b && node dist/index.js"
"dev": "tsc -b && node dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@prisma/client": "^5.20.0",
"kafkajs": "^2.2.4"
},
"devDependencies": {
"prisma": "^5.20.0"
}
}
Loading

0 comments on commit 028e768

Please sign in to comment.