/[sudobot]/trunk/extensions/archiver/src/service/ArchiveProcess.ts
ViewVC logotype

Contents of /trunk/extensions/archiver/src/service/ArchiveProcess.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 632 - (show annotations)
Thu Oct 10 17:53:11 2024 UTC (5 months, 2 weeks ago) by rakinar2
File MIME type: application/typescript
File size: 1191 byte(s)
chore: synchronize

1 import { ArchiveMessagePayload } from "src/types/ArchiveMessagePayload";
2 import { MessageType } from "../types/MessageType";
3 import ArchiveService from "./ArchiveService";
4
5 if (!process.send) {
6 throw new Error("This script must be run as a child process");
7 }
8
9 process.send?.({
10 type: MessageType.Ping
11 });
12
13 async function main() {
14 const service = await ArchiveService.create();
15
16 process.on("message", async serializable => {
17 if (
18 !serializable ||
19 typeof serializable !== "object" ||
20 !("type" in serializable) ||
21 typeof serializable.type !== "string"
22 ) {
23 return;
24 }
25
26 const message = serializable as Record<string, unknown>;
27
28 switch (message.type) {
29 case MessageType.Archive:
30 await service.archive(message as ArchiveMessagePayload);
31 break;
32 case MessageType.Ping:
33 process.send?.({
34 type: MessageType.Acknowledgement
35 });
36 break;
37 }
38 });
39
40 service.startServer();
41 process.on("beforeExit", () => service.close());
42 }
43
44 main().catch(console.error);

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26