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

fix: assign scheduled job worker to JobSchedulerService class #8891

Conversation

u11d-bartlomiej-galezowski
Copy link

@u11d-bartlomiej-galezowski u11d-bartlomiej-galezowski commented Aug 30, 2024

What - Enhance the JobSchedulerService by making the scheduler jobs worker available for proper shutdown procedures.
Why - Currently, when the Medusa server is shut down, workers are not properly closed, increasing the risk of jobs being marked as stalled. If a worker is terminated without completing its jobs, these jobs are automatically marked as stalled and will be reprocessed when new workers come online, typically after a delay of about 30 seconds. To minimize the occurrence of stalled jobs, it is crucial to gracefully close workers during server shutdown, as recommended by the BullMQ documentation.
How - The worker is currently created but not assigned to the JobSchedulerService class. This update ensures that the worker is properly attached to the JobSchedulerService, allowing for a graceful shutdown process.
Test - The changes were tested by linking the package to an existing Medusa project. The worker shutdown process was verified by adding jobSchedulerService.worker_.close(); to the function handling SIGTERM and SIGINT signals, then starting and stopping the server process to confirm proper worker closure.

Copy link

changeset-bot bot commented Aug 30, 2024

⚠️ No Changeset found

Latest commit: 3b281cd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Aug 30, 2024

@u11d-bartlomiej-galezowski is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@u11d-bartlomiej-galezowski
Copy link
Author

u11d-bartlomiej-galezowski commented Aug 30, 2024

Can I rerun integration tests? because it looks like missing connection

  FAIL __tests__/price-lists/admin/price-lists.spec.ts (11.413 s)
    ●  › Admin: Price Lists API › POST /admin/price-lists/:id/prices/batch › should add, remove and delete price list prices in batch successfully
  
      Request failed with status code 500
  
        at createError (../../node_modules/axios/lib/core/createError.js:16:15)
        at settle (../../node_modules/axios/lib/core/settle.js:17:12)
        at IncomingMessage.handleStreamEnd (../../node_modules/axios/lib/adapters/http.js:269:11)
  
  Summary of all failing tests
  FAIL __tests__/price-lists/admin/price-lists.spec.ts (11.413 s)
    ●  › Admin: Price Lists API › POST /admin/price-lists/:id/prices/batch › should add, remove and delete price list prices in batch successfully
  
      Request failed with status code 500
  
        at createError (../../node_modules/axios/lib/core/createError.js:16:15)
        at settle (../../node_modules/axios/lib/core/settle.js:17:12)
        at IncomingMessage.handleStreamEnd (../../node_modules/axios/lib/adapters/http.js:269:11)

@olivermrbl olivermrbl merged commit 6b720dc into medusajs:v1.x Sep 1, 2024
19 of 26 checks passed
@olivermrbl
Copy link
Contributor

Thanks, will be part of a release next week :)

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

Successfully merging this pull request may close these issues.

4 participants