Skip to content

Add Workers example to patterns #2240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bensleveritt opened this issue May 15, 2025 · 0 comments
Open

Add Workers example to patterns #2240

bensleveritt opened this issue May 15, 2025 · 0 comments

Comments

@bensleveritt
Copy link
Collaborator

https://discord.com/channels/1139617727565271160/1371088155851100221/1372290802797117644

import { startWorker } from "jazz-nodejs";
import { WorkerAccount } from "./schema";

let jazz: Awaited<ReturnType<typeof startWorker>>;

export const getJazzWorker = async () => {
  if (jazz) {
    console.log("Jazz worker check connection");
    await jazz.waitForConnection();
    console.log("Jazz worker connected");
    return jazz.worker as WorkerAccount;
  }
  console.log("Starting jazz worker");
  const res = await startWorker({
    AccountSchema: WorkerAccount,
    accountID: process.env.JAZZ_ACCOUNT_ID,
    accountSecret: process.env.JAZZ_ACCOUNT_SECRET,
  });

  jazz = res;

  return res.worker as WorkerAccount;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant