@penkov/tasks_queue
Version:
A lightweight PostgreSQL-backed task queue system with scheduling, retries, backoff strategies, and priority handling. Designed for efficiency and observability in modern Node.js applications.
29 lines (28 loc) • 933 B
JavaScript
import { option } from "scats";
export class ActiveChildState {
taskId;
allowFailure;
constructor(taskId, allowFailure = false) {
this.taskId = taskId;
this.allowFailure = allowFailure;
}
copy(o) {
return new ActiveChildState(option(o.taskId).map(Number).getOrElseValue(this.taskId), option(o.allowFailure).map(Boolean).getOrElseValue(this.allowFailure));
}
get toJson() {
const res = {
taskId: this.taskId,
};
option(this.allowFailure)
.filter((x) => x)
.foreach((allowFailure) => {
res["allowFailure"] = allowFailure;
});
return res;
}
static fromJson(j) {
return option(j)
.map((x) => x)
.flatMap((x) => option(x["taskId"]).map((taskId) => new ActiveChildState(Number(taskId), option(x["allowFailure"]).map(Boolean).getOrElseValue(false))));
}
}