Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 6 apps/wss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ async function main() {

triggerServer.listen();

triggerServers.set(keyPart, triggerServer);
triggerServers.set(triggerServer.id, triggerServer);

triggerServer.onClose.attach(() => {
console.log(
`Trigger server for key ${keyPart} closed. Removing it from the map.`
`Trigger server id ${triggerServer.id} closed. Removing it from the map.`
);

triggerServers.delete(keyPart);
triggerServers.delete(triggerServer.id);
});
});

Expand Down
23 changes: 12 additions & 11 deletions 23 apps/wss/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class TriggerServer {
#runControllers = new Map<string, WorkflowRunController>();
#closedByServer = false;
onClose: Evt<void>;
id: string;

constructor(
socket: WebSocket,
Expand All @@ -51,10 +52,11 @@ export class TriggerServer {
this.#logger = new Logger("trigger.dev server");
this.onClose = new Evt();
this.#commandPublisher = publisher;
this.id = v4();
}

async listen(instanceId?: string) {
await this.#initializeConnection(instanceId);
async listen() {
await this.#initializeConnection();
this.#initializeRPC();
this.#initializeServer();
}
Expand All @@ -80,12 +82,12 @@ export class TriggerServer {
this.onClose.post();
}

async #initializeConnection(instanceId?: string) {
const id = instanceId ?? v4();
async #initializeConnection() {
this.#logger.debug("Initializing connection...", this.id);

this.#logger.debug("Initializing connection...", id);

const connection = new TriggerServerConnection(this.#socket, { id });
const connection = new TriggerServerConnection(this.#socket, {
id: this.id,
});

connection.onClose.attach(async ([code, reason]) => {
if (!this.#isConnected) {
Expand All @@ -94,7 +96,7 @@ export class TriggerServer {

this.#closedByServer = false;

this.#logger.log(`Connection with host was closed (${code})`, id);
this.#logger.log(`Connection with host was closed (${code})`, this.id);

if (reason) {
this.#logger.error(reason);
Expand All @@ -103,7 +105,7 @@ export class TriggerServer {
await this.close();
});

this.#logger.debug("Connection initialized", id);
this.#logger.debug("Connection initialized", this.id);

this.#connection = connection;
this.#isConnected = true;
Expand Down Expand Up @@ -350,13 +352,12 @@ export class TriggerServer {
client: pulsarClient,
config: {
topic: Topics.triggers,
subscription: `websocketserver-workflow-${this.#workflowId}`,
subscription: `websocketserver-${this.#workflowId}-${this.#apiKey}`,
subscriptionType: "Shared",
subscriptionInitialPosition: "Earliest",
},
handlers: {
TRIGGER_WORKFLOW: async (id, data, properties, messageAttributes) => {
this.#logger.debug("Received trigger", id, data, properties);
// If the API keys don't match, then we should ignore it
// This ensures the workflow is triggered for the correct environment
if (properties["x-api-key"] !== this.#apiKey) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.