taskforcesh/bullmq

[Bug]: Date transformed into string when queued

Opened this issue · 4 comments

Version

v5.8.2

Platform

NodeJS

What happened?

When adding an object with a key typed as a date in following format : 2024-09-13T15:00:00.000Z the worker gets it back as a string, logicaly loosing all date methods

How to reproduce.

Add an item with at least one js date key to the queue, then check the date in a worker. It is now a string

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Yeah, this is the way JSON.stringify/parse works. We would need another serialisation scheme to support dates.

So the "proper" way to deal with this would be to rebuild the dates in the workers?

Yes, you need to recreate the date objects when you need them.

We are facing similar problems using date objects in our jobs. A nice solution could be to use superjson (https://github.com/flightcontrolhq/superjson) (or similar) to serialize and deserialize job data. This would automatically handle date objects and also bigint (#447) or map.
I think it should not be very difficult to implement. For us, as we use a lot of workers, it would be helpful to have a global option to always use superjson for all jobs.