Skip to content
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

Subscriber is not stable #7156

Open
minhchu opened this issue Apr 26, 2024 · 4 comments
Open

Subscriber is not stable #7156

minhchu opened this issue Apr 26, 2024 · 4 comments

Comments

@minhchu
Copy link

minhchu commented Apr 26, 2024

Describe the bug

Sometimes subscriber does not work.

I create a subscriber:

  Order,
  OrderService,
  type SubscriberArgs,
  type SubscriberConfig,
} from "@medusajs/medusa";
import { render } from "@react-email/render";
import { Mailer } from "src/types/mail-service";

export default async function sendEmailWhenOrderPlaced({
  data,
  container,
}: SubscriberArgs<Record<string, string>>) {
  const mailService: Mailer = container.resolve("mailService")

  const orderService: OrderService = container.resolve("orderService");

  const order: Order = await orderService.retrieve(data.id, {
    relations: ["shipping_address", "billing_address"],
  });
  
  mailer.send .... 
}

export const config: SubscriberConfig = {
  event: OrderService.Events.PLACED,
  context: {
    subscriberId: "send-email-when-order-placed",
  },
};

It works at first, but after some time, it stops working.
This issue occurs not only on my local machine but also on the production server (docker + k8s).
To resolve the issue, I need to delete the node_modules folder and then reinstall everything.

System information

Medusa version (including plugins): 1.20.4

    "@medusajs/admin": "7.1.11",
    "@medusajs/cache-inmemory": "^1.8.9",
    "@medusajs/cache-redis": "^1.8.9",
    "@medusajs/event-bus-local": "^1.9.8",
    "@medusajs/event-bus-redis": "^1.8.11",
    "@medusajs/file-local": "^1.0.3",
    "@medusajs/medusa": "^1.20.4",
    "@medusajs/ui": "^2.4.1",

Node.js version: v18.17.1
Database: pgsql 16.2
Operating system: Ubuntu 20.04
Browser (if relevant):

Steps to reproduce the behavior

It is hard to reproduce. Sometimes it happens.

Expected behavior

Subscriber must work stably.

@adevinwild
Copy link
Contributor

Quick question but are you using Redis in prod ?

@minhchu
Copy link
Author

minhchu commented Apr 27, 2024

@adevinwild yes. I'm using Redis in local and prod

@som-greetwell
Copy link

som-greetwell commented Apr 30, 2024

We are facing the same issue while trying order placed subscriber.

We tested redis on local, railway and redis website. However same problem.

In our case medusa prod deployment on railway often fails to trigger the subscribers whereas local deployment of medusa generally works (not always).

Attaching the log when it doesn't trigger the subscriber. There is no error and no mention of the order.placed subscriber. When it works successfully I get the following logs

Processing cart.updated which has 0 subscribers
Processing product-variant.updated which has 0 subscribers
Processing payment.updated which has 0 subscribers
Processing order.placed which has 3 subscribers

Updating all the package versions helped. Earlier prod was not working at all when event-bus-redis is enabled. It was only working 60-70% of the time with event-bus-local. Here is current dependencies in my package.json

    "@medusajs/admin": "latest",
    "@medusajs/cache-inmemory": "latest",
    "@medusajs/cache-redis": "latest",
    "@medusajs/event-bus-local": "latest",
    "@medusajs/event-bus-redis": "latest",
    "@medusajs/file-local": "latest",
    "@medusajs/medusa": "latest",
    "@tanstack/react-query": "4.22.0",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "16.3.1",
    "express": "^4.17.2",
    "medusa-fulfillment-manual": "latest",
    "medusa-interfaces": "latest",
    "medusa-payment-manual": "latest",
    "medusa-payment-stripe": "latest",
    "medusa-plugin-sendgrid": "latest",
    "prism-react-renderer": "^2.0.4",
    "typeorm": "^0.3.16"

Please share any thoughts on fixing this. Currently our migration to medusa is blocked on this.

Thank you,
Som

railway.txt

@minhchu
Copy link
Author

minhchu commented May 1, 2024

Forgot to mention. FLUSH ALL in redis then restart medusa server fix the problem. It is a destructive command, only run it in local env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants