node-cron
node-cron copied to clipboard
Serializing cronJob object is not working because of a circular reference
Hi there, I am trying to serialize the cronJob object and then save the data into Redis so I can read all the jobs from there in the future but since the cronJob object has a circular reference I am unable to save it to Redis. is there a recommended way of serializing and parse cronJob object with circular reference?
What I have tried:
- serialized the object with Node's util.inspect() but can't parse it back.
- deep cloned the object, but this method removes all the cronTime reference which I don't wanna lose.
Here is what the returned cron job object looks like:
<ref *1> CronJob {
context: [Circular *1],
_callbacks: [ [AsyncFunction (anonymous)] ],
onComplete: null,
cronTime: {
source: Moment<2020-08-12T22:35:00+03:00>,
second: {},
minute: {},
hour: {},
dayOfMonth: {},
month: {},
dayOfWeek: {},
realDate: true
},
unrefTimeout: undefined,
runOnce: true,
running: true,
_timeout: Timeout {
_idleTimeout: 86363978,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 11613,
_onTimeout: [Function: callbackWrapper],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(refed)]: true,
[Symbol(asyncId)]: 158,
[Symbol(triggerId)]: 0
}
}