UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

318 lines 9.65 kB
import { v4 as uuid } from 'uuid'; export class MessageState { uuid; publishedAt = null; processingStartedAt = null; lastProcessedAt = null; requeuedAt = null; requeueCount = 0; lastRequeuedAt = null; deadLetteredAt = null; acknowledgedAt = null; unacknowledgedAt = null; lastUnacknowledgedAt = null; scheduledAt = null; lastScheduledAt = null; lastRetriedAttemptAt = null; scheduledCronFired = false; attempts = 0; scheduledRepeatCount = 0; expired = false; effectiveScheduledDelay = 0; scheduledTimes = 0; scheduledMessageParentId = null; requeuedMessageParentId = null; constructor() { this.uuid = uuid(); } static fromJSON(state) { const instance = new MessageState(); instance.uuid = state.uuid; instance.publishedAt = state.publishedAt; instance.processingStartedAt = state.processingStartedAt; instance.requeuedAt = state.requeuedAt; instance.requeueCount = state.requeueCount; instance.lastRequeuedAt = state.lastRequeuedAt; instance.deadLetteredAt = state.deadLetteredAt; instance.acknowledgedAt = state.acknowledgedAt; instance.unacknowledgedAt = state.unacknowledgedAt; instance.lastUnacknowledgedAt = state.lastUnacknowledgedAt; instance.scheduledAt = state.scheduledAt; instance.lastScheduledAt = state.lastScheduledAt; instance.lastRetriedAttemptAt = state.lastRetriedAttemptAt; instance.scheduledCronFired = state.scheduledCronFired; instance.attempts = state.attempts; instance.scheduledRepeatCount = state.scheduledRepeatCount; instance.expired = state.expired; instance.effectiveScheduledDelay = state.effectiveScheduledDelay; instance.scheduledTimes = state.scheduledTimes; instance.scheduledMessageParentId = state.scheduledMessageParentId; instance.requeuedMessageParentId = state.requeuedMessageParentId; instance.lastProcessedAt = state.lastProcessedAt; return instance; } setId(id) { this.uuid = id; return this; } getId() { return this.uuid; } setPublishedAt(timestamp) { this.publishedAt = timestamp; return this; } getPublishedAt() { return this.publishedAt; } setProcessingStartedAt(timestamp) { this.processingStartedAt = timestamp; return this; } getProcessingStartedAt() { return this.processingStartedAt; } setLastProcessedAt(timestamp) { this.lastProcessedAt = timestamp; return this; } getLastProcessedAt() { return this.lastUnacknowledgedAt; } setRequeuedAt(timestamp) { this.requeuedAt = timestamp; return this; } getRequeuedAt() { return this.requeuedAt; } setRequeueCount(count) { this.requeueCount = count; return this; } getRequeueCount() { return this.requeueCount; } incrRequeueCount() { this.requeueCount += 1; return this; } setLastRequeuedAt(timestamp) { this.lastRequeuedAt = timestamp; return this; } getLastRequeuedAt() { return this.lastRequeuedAt; } setDeadLetteredAt(timestamp) { this.deadLetteredAt = timestamp; return this; } getDeadLetteredAt() { return this.deadLetteredAt; } setAcknowledgedAt(timestamp) { this.acknowledgedAt = timestamp; return this; } getAcknowledgedAt() { return this.acknowledgedAt; } setUnacknowledgedAt(timestamp) { this.unacknowledgedAt = timestamp; return this; } getUnacknowledgedAt() { return this.unacknowledgedAt; } setLastUnacknowledgedAt(timestamp) { this.lastUnacknowledgedAt = timestamp; return this; } getLastUnacknowledgedAt() { return this.lastUnacknowledgedAt; } setScheduledAt(timestamp) { this.scheduledAt = timestamp; return this; } getScheduledAt() { return this.scheduledAt; } setLastScheduledAt(timestamp) { this.lastScheduledAt = timestamp; return this; } getLastScheduledAt() { return this.lastScheduledAt; } setLastRetriedAttemptAt(timestamp) { this.lastRetriedAttemptAt = timestamp; return this; } getLastRetriedAttemptAt() { return this.lastRetriedAttemptAt; } setScheduledCronFired(fired) { this.scheduledCronFired = fired; return this; } isScheduledCronFired() { return this.scheduledCronFired; } setAttempts(attempts) { this.attempts = attempts; return this; } getAttempts() { return this.attempts; } setScheduledRepeatCount(count) { this.scheduledRepeatCount = count; return this; } getScheduledRepeatCount() { return this.scheduledRepeatCount; } incrScheduledRepeatCount() { this.scheduledRepeatCount += 1; return this.scheduledRepeatCount; } resetScheduledRepeatCount() { this.scheduledRepeatCount = 0; return this; } getSetExpired(ttl, createdAt) { if (ttl) { const curTime = new Date().getTime(); this.expired = createdAt + ttl - curTime <= 0; } return this.expired; } setExpired(expired) { this.expired = expired; return this; } getExpired() { return this.expired; } setEffectiveScheduledDelay(delay) { this.effectiveScheduledDelay = delay; return this; } getEffectiveScheduledDelay() { return this.effectiveScheduledDelay; } getSetEffectiveScheduledDelay() { if (this.effectiveScheduledDelay > 0) { const delay = this.effectiveScheduledDelay; this.effectiveScheduledDelay = 0; return delay; } return 0; } hasDelay() { return this.effectiveScheduledDelay > 0; } setScheduledTimes(count) { this.scheduledTimes = count; return this; } getScheduledTimes() { return this.scheduledTimes; } incrScheduledTimes(count = 1) { this.scheduledTimes = this.scheduledTimes + count; return this; } setScheduledMessageParentId(messageId) { this.scheduledMessageParentId = messageId; return this; } getScheduledMessageParentId() { return this.scheduledMessageParentId; } setRequeuedMessageParentId(messageId) { this.requeuedMessageParentId = messageId; return this; } getRequeuedMessageParentId() { return this.requeuedMessageParentId; } reset() { this.publishedAt = null; this.processingStartedAt = null; this.requeuedAt = null; this.requeueCount = 0; this.lastRequeuedAt = null; this.deadLetteredAt = null; this.acknowledgedAt = null; this.unacknowledgedAt = null; this.lastUnacknowledgedAt = null; this.scheduledAt = null; this.lastScheduledAt = null; this.lastRetriedAttemptAt = null; this.attempts = 0; this.expired = false; this.effectiveScheduledDelay = 0; this.scheduledCronFired = false; this.scheduledRepeatCount = 0; this.scheduledTimes = 0; this.scheduledMessageParentId = null; this.requeuedMessageParentId = null; return this; } toJSON() { return { uuid: this.uuid, publishedAt: this.publishedAt, processingStartedAt: this.processingStartedAt, requeuedAt: this.requeuedAt, requeueCount: this.requeueCount, lastRequeuedAt: this.lastRequeuedAt, deadLetteredAt: this.deadLetteredAt, acknowledgedAt: this.acknowledgedAt, unacknowledgedAt: this.unacknowledgedAt, lastUnacknowledgedAt: this.lastUnacknowledgedAt, scheduledAt: this.scheduledAt, lastScheduledAt: this.lastScheduledAt, lastRetriedAttemptAt: this.lastRetriedAttemptAt, scheduledCronFired: this.scheduledCronFired, attempts: this.attempts, scheduledRepeatCount: this.scheduledRepeatCount, expired: this.expired, effectiveScheduledDelay: this.effectiveScheduledDelay, scheduledTimes: this.scheduledTimes, scheduledMessageParentId: this.scheduledMessageParentId, requeuedMessageParentId: this.requeuedMessageParentId, lastProcessedAt: this.lastProcessedAt, }; } getValues() { return [ this.uuid, this.publishedAt, this.processingStartedAt, this.requeuedAt, this.requeueCount, this.lastRequeuedAt, this.deadLetteredAt, this.acknowledgedAt, this.unacknowledgedAt, this.lastUnacknowledgedAt, this.scheduledAt, this.lastScheduledAt, this.lastRetriedAttemptAt, this.scheduledCronFired, this.attempts, this.scheduledRepeatCount, this.expired, this.effectiveScheduledDelay, this.scheduledTimes, this.scheduledMessageParentId, this.requeuedMessageParentId, this.lastProcessedAt, ]; } } //# sourceMappingURL=message-state.js.map