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

Introduce middleware for job error handling #2502

Closed
wants to merge 3 commits into from

Conversation

pshycodr
Copy link

@pshycodr pshycodr commented Feb 11, 2025

Fixes #2475

Introduce default error logging middleware for jobs to avoid server crashes.

  • Add errorLoggingMiddleware function in waspc/data/Generator/templates/sdk/wasp/server/middleware/globalMiddleware.ts to log errors and prevent job crashes.
  • Update mage/src/server/jobs/checkForPendingApps.ts to wrap the checkForPendingApps job handler with errorLoggingMiddleware.
  • Update mage/src/server/jobs/failStaleGenerations.ts to wrap the failStaleGenerations job handler with errorLoggingMiddleware.
  • Update documentation in web/docs/advanced/jobs.md to include information about the new default error logging middleware for jobs.

Fixes wasp-lang#2475

Introduce default error logging middleware for jobs to avoid server crashes.

* Add `errorLoggingMiddleware` function in `waspc/data/Generator/templates/sdk/wasp/server/middleware/globalMiddleware.ts` to log errors and prevent job crashes.
* Update `mage/src/server/jobs/checkForPendingApps.ts` to wrap the `checkForPendingApps` job handler with `errorLoggingMiddleware`.
* Update `mage/src/server/jobs/failStaleGenerations.ts` to wrap the `failStaleGenerations` job handler with `errorLoggingMiddleware`.
* Update documentation in `web/docs/advanced/jobs.md` to include information about the new default error logging middleware for jobs.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/wasp-lang/wasp/issues/2475?shareId=XXXX-XXXX-XXXX-XXXX).
@infomiho
Copy link
Contributor

Thanks for the contribution, did you test this locally successfully?

@pshycodr
Copy link
Author

Yes, I have tested these changes locally.
There were only a few minor Typescript errors on the mage/src/server/jobs/checkForPendingApps.ts file, which i resolved. Beyond those, I did not observe any further issues.

@infomiho
Copy link
Contributor

I'm closing this PR since it doesn't cover the full scope of the linked issue, primarily:

We should investigate the best way to provide some sort of default error logging (to avoid jobs crashing the server, I'd assume).

The research for this feature is missing and we want to probably build a job's middleware system with maybe some defaults (or not, I can't be sure without trying to build the API).

Ideally, we'd have a general enough middleware system for jobs like we do for APIs. We want to do something similar for operations as well #2396

If possible @pshycodr please ping us first on Discord when you'd like to work on issue so we can discuss the direction that makes sense :) thank you for your effort!

Locally testing this PR

Running Mage locally gives me errors which reveal that the errorLoggingMiddleware doesn't really work with Wasp's job types:
Screenshot 2025-02-28 at 11 56 17

The helper should be typed as a generic function so it's a "pass-through" function that keeps the input and output types of the job function.

@infomiho infomiho closed this Feb 28, 2025
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.

Introduce middleware for jobs (error handling)
2 participants