fix Date objects getting mangled by JSON
This commit is contained in:
parent
7716292c78
commit
7ca90502d1
2 changed files with 36 additions and 5 deletions
|
|
@ -136,6 +136,15 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
{
|
||||
onError: this.onQueueError,
|
||||
concurrency: 2, // Low concurrency, this table is slow for some reason
|
||||
redisParser: data => ({
|
||||
...data,
|
||||
latestRequestReceivedAt: data.latestRequestReceivedAt != null
|
||||
? new Date(data.latestRequestReceivedAt)
|
||||
: data.latestRequestReceivedAt,
|
||||
notRespondingSince: data.notRespondingSince != null
|
||||
? new Date(data.notRespondingSince)
|
||||
: data.notRespondingSince,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -161,6 +170,12 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
{
|
||||
onError: this.onQueueError,
|
||||
concurrency: 4, // High concurrency - this queue gets a lot of activity
|
||||
redisParser: data => ({
|
||||
...data,
|
||||
updatedAt: data.updatedAt != null
|
||||
? new Date(data.updatedAt)
|
||||
: data.updatedAt,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -197,6 +212,10 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
{
|
||||
onError: this.onQueueError,
|
||||
concurrency: 2,
|
||||
redisParser: data => ({
|
||||
...data,
|
||||
lastUsedAt: new Date(data.lastUsedAt),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -215,6 +234,12 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
{
|
||||
onError: this.onQueueError,
|
||||
concurrency: 4,
|
||||
redisParser: data => ({
|
||||
...data,
|
||||
lastUsedAt: data.lastUsedAt != null
|
||||
? new Date(data.lastUsedAt)
|
||||
: data.lastUsedAt,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -245,15 +270,15 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
private onUserDeleted(data: { id: string, isDeleted: boolean }) {
|
||||
private async onUserDeleted(data: { id: string, isDeleted: boolean }) {
|
||||
if (data.isDeleted) {
|
||||
this.updateUserQueue.delete(data.id);
|
||||
await this.updateUserQueue.delete(data.id);
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private onAntennaDeleted(data: MiAntenna) {
|
||||
this.updateAntennaQueue.delete(data.id);
|
||||
private async onAntennaDeleted(data: MiAntenna) {
|
||||
await this.updateAntennaQueue.delete(data.id);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { TimeService, type TimerHandle } from '@/global/TimeService.js';
|
|||
import promiseLimit from 'promise-limit';
|
||||
import { InternalEventService } from '@/core/InternalEventService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { Serialized } from '@/types.js';
|
||||
|
||||
type Job<V> = {
|
||||
value: V;
|
||||
|
|
@ -39,6 +40,7 @@ export class CollapsedQueue<V> {
|
|||
private readonly opts?: {
|
||||
onError?: (queue: CollapsedQueue<V>, error: unknown) => void | Promise<void>,
|
||||
concurrency?: number,
|
||||
redisParser?: (data: Serialized<V>) => V,
|
||||
},
|
||||
) {
|
||||
if (opts?.concurrency) {
|
||||
|
|
@ -149,7 +151,11 @@ export class CollapsedQueue<V> {
|
|||
|
||||
// Only enqueue if not deferred
|
||||
if (!this.deferredKeys.has(data.key)) {
|
||||
await this.enqueue(data.key, data.value as V);
|
||||
const value = this.opts?.redisParser
|
||||
? this.opts.redisParser(data.value as Serialized<V>)
|
||||
: data.value as V;
|
||||
|
||||
await this.enqueue(data.key, value);
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue