Forcing Workers to only run on Primary machine

Hi everyone. My situation is I have my app running on 2 machines which are in the same region, using LiteFS as storage, and a self-hosted Redis machine. In my app there’s a worker using Bull to create notifications. My problem is that when my Worker select a machine to process a job, it will occasionally choose the replica machine which then produce the error:

<time> app[id] hkg [info] Process job 1763

<time> app[id] hkg [info] level=INFO msg="fuse: create(): cannot create journal: read only replica"

<time> app[id] hkg [info] job add notification 1763 failed with error: Error: {"name":"PrismaClientUnknownRequestError","clientVersion":"5.6.0"}

How can I prevent this error? Is there a way to ensure that Bull always assigns jobs to the primary machine for processing?

Added litefs, nodejs

Not at all familiar with the Bull library but with LiteFS there is a file called .primary in the LiteFS FUSE directory. If it’s absent; the localhost is the primary; if it’s present, then the localhost is not primary but the file contains the hostname of the primary node. On the Fly Platform, this will be the primary node’s Machine ID, which means you can then send your request to <machine_id>.vm.<appname>.internal.

Hope this helps.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.