forked from planetarium/Corvette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.ts
40 lines (37 loc) · 1.13 KB
/
control.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { getLogger } from "std/log/mod.ts";
import type { AmqpChannel } from "amqp/mod.ts";
import {
type EmitterControlMessages,
type ObserverControlMessages,
serializeControlMessage,
} from "./ControlMessage.ts";
import {
ControlEmitterRoutingKey,
ControlExchangeName,
ControlObserverRoutingKey,
} from "./constants.ts";
import { ControlLoggerName } from "./logUtils.ts";
export function reload(
amqpChannel: AmqpChannel,
destination:
| typeof ControlEmitterRoutingKey
| typeof ControlObserverRoutingKey,
) {
const logger = getLogger(ControlLoggerName);
logger.info(`Sending reload message to control: ${destination}.`);
const { routingKey, reloadMessage }: {
routingKey: typeof ControlEmitterRoutingKey;
reloadMessage: EmitterControlMessages;
} | {
routingKey: typeof ControlObserverRoutingKey;
reloadMessage: ObserverControlMessages;
} = { routingKey: destination, reloadMessage: { action: "reload" } };
amqpChannel.publish(
{
exchange: ControlExchangeName,
routingKey,
},
{ contentEncoding: "application/octet-stream" },
serializeControlMessage(reloadMessage),
);
}