#Services and Subscribers working unstable

1 messages · Page 1 of 1 (latest)

solar moon
#

Hi everyone,

I'm experiencing intermittent issues with custom services and subscribers in the Medusa backend, which sometimes work and sometimes don't. Despite following the official documentation consistently, the behavior remains unpredictable. I'm logging events and services to monitor triggers, but the console output is inconsistent.

Could this be an issue with how events and services are registered in Medusa.js? Is there a specific way to register these to ensure consistent recognition?

Here's an example of how I've implemented a product creation handler:

silk shuttle
#

I'm facing the same issue.

I have medusa deployed on Railway and a subscriber to listen to the order placed events. It sometimes trigger the event sometime it doesn't.

In the log it doesn't say anything about order.placed event. Only subscriber log I see is
Processing cart.updated which has 0 subscribers

This is a launch blocker for us as the subscriber event calls a bunch of Zpier webhooks which are needed for our use case.

Is there anything I can check to understand the problem?

Thanks in advance for helping to debug the issue and unblocking us.

-Som

fallen lantern
#

I have read in other places that this could be redis related if you want to give this a try.

silk shuttle
#

Thanks @fallen lantern you meant including redis?

I'm so far not using redis.

The subscriber is always working on my local machine. It is flaky only on the railway deployment.

I'll try using redis, but I'm looking to understand why it is flaky. It should either work or do not work.

spark star
#

Try using redis yeah

#

Fakeredis is a reimplementation of redis. It could operate differently than regular redis.

warped adder
#

You need to use redis in production

fallen lantern
silk shuttle
#

Thanks @warped adder and @fallen lantern

I have installed Redis on Railway and the subscriber is working fine with the redis on my local machine. It was working fine without the Redis as well.

However, on production the subscriber completely stopped working. Earlier the subscriber was working 50-60% of the time without Redis. I can see the order.placed event created in Redis but in the log I don't see any subscriber triggered.

Here is my medusja-config.js

const modules = {
eventBus: {
resolve: "@medusajs/event-bus-redis",
options: {
redisUrl: REDIS_URL
}
},
/*
cacheService: {
resolve: "@medusajs/cache-redis",
options: {
redisUrl: REDIS_URL
}
},*/
};

/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
const projectConfig = {
jwtSecret: process.env.JWT_SECRET,
cookieSecret: process.env.COOKIE_SECRET,
store_cors: STORE_CORS,
database_url: DATABASE_URL,
admin_cors: ADMIN_CORS,
// Uncomment the following lines to enable REDIS
redis_url: REDIS_URL
};

/** @type {import('@medusajs/medusa').ConfigModule} */
module.exports = {
projectConfig,
plugins,
modules,
};

Any suggestion how to get this work on Railway?

We are blocked on this. I thought it would be simple to setup order.placed subscriber notification on medusa.

Thank you so much
Som

#

One observation, could be unrelated but in case it gives any clue

After I run npm install @medusajs/event-bus-redis on my local machine it upgraded @medusajs/event-bus-redis to 1.8.12 and the subscriber stopped working on the local machine as well. I then reverted back to the version 1.8.11 on my local machine and everything started working again.

I don't know how to check the package version on Railway but hopefully it is 1.8.11 as that is the version in package.json. Also, don't understand why the newer version of @medusajs/event-bus-redis doesn't work.

Please let me know if any other details can help debugging this. Thank you for reviewing this.

fallen lantern
#

I am running everything on docker and it works fine. i think i have read numerous help posts here about redis and railway though. did you already do a search? to troubleshoot and take railway out of the equation, you can spin up a redis instance somewhere else and see if that helps.

warped adder
silk shuttle
#

Hi @fallen lantern and @warped adder Thanks for the pointers. We've tried numerous approaches without much success. The Medusa deployment on Railway is failing to trigger subscribers most of the time.

  1. We've updated medusa to the latest version and all the associated node packages, which has resulted in the Medusa deployment on Railway working intermittently, but it's still extremely unreliable and rarely triggers the subscribers.

  2. We've also experimented with different Redis installations - local, Railway, and Redis website deployment. While local Medusa deployment with any of those Redis setup works in most cases, the Railway deployment consistently fails to trigger the subscribers.

I've attached logs from both the successful local deployment and the unsuccessful Railway deployment. It will be really helpful if you could review the logs and suggest where we're going wrong. We are completely blocked on this.

Thank you,
Som

silk shuttle
fallen lantern
#

@silk shuttle Apologies, but I can't help you with that. There are just too many moving parts to consider. It could be anything, from a wrong peer dependency to the deployment environment, to the way the app is being built.. I just can tell you that I got it working more or less out of the box on coolify with a docker image built for the app and all other services required with original vendor images, even as a yarn project using workspaces.

#

As a hail mary approach since your under pressure, you might want to try a different environment to run this at, a VPS and a docker compose file and running everything on the same host to rule out the env.

#

If you have been updating medusa dependencies over many versions, it might be worth also to delete the lock file and have the package manager reevaluate things - helped me in the past to get things going that werent behaving as expected.

#

maybe its as simple as that. 🙂