Self Hosting PM2 Variables and Flows

I have recently implemented on a self hosted version of directus multiple PM2 instances using the PM2_INSTANCES env variable, since then though directus flows that have on a scheduled chron-job are running multiple times in each instance which is causing all sorts of duplicate data.

Does anyone know a way to force flows to run in just one instance of the app when using PM2 in cluster mode with multiple instances?

1 Like

Make sure that you Redis running, connected, and configured correctly.

Please see the Synchronization config here.

The SYNCHRONIZATION_STORE defaults to memory vs redis so you have to make sure you’re setting that explicitly.

We were facing the same problem as we were syncing products from Shopify, so we moved it away from the Directus to a different inhouse NestJs service

If you still want to use Directus then you will have to move it into custom hooks, and their use Redis based locking

Do you have Redis enabled and configured correctly?

Directus will always try to execute a cron but they have made a cron locking mechanism that relies on Redis. This will prevent multiple cronjobs from executing at the same time.

Thanks both! I had set cache: redis using just the default config but appears I have completely missed this part of setting Redis up. I will look into this guide and get that up and running