taskforcesh / bullmq

BullMQ - Message Queue and Batch processing for NodeJS and Python based on Redis
https://bullmq.io
MIT License
6.26k stars 410 forks source link

[Bug]: Date transformed into string when queued #2771

Open Holbanner opened 2 months ago

Holbanner commented 2 months ago

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

manast commented 2 months ago

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

Holbanner commented 2 months ago

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

manast commented 2 months ago

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

bredar commented 1 month ago

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 (https://github.com/taskforcesh/bullmq/issues/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.