mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
5610df5a26
* chore: Reduce no-explicit-any warnings in server directory Tightens types across test response bodies, decorator signatures, the TestServer wrapper, base class generics, and presenter Record types. Where any is genuinely load-bearing (Sequelize model generics, PropertyDescriptor decorator returns, plugin-registered template classes, Fix mixin), keeps any with a targeted eslint-disable plus reason rather than masking the constraint. Cuts server-only no-explicit-any warnings from 162 to 70. * fix: groups test asserts on first response instead of second Caught by Copilot review on the no-explicit-any cleanup. Also fixes the pre-existing getChangsetSkipped → getChangesetSkipped typo surfaced while reviewing nearby decorator code.
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import type { Job, JobOptions } from "bull";
|
|
import { taskQueue } from "../../";
|
|
|
|
export enum TaskPriority {
|
|
Background = 40,
|
|
Low = 30,
|
|
Normal = 20,
|
|
High = 10,
|
|
}
|
|
|
|
export abstract class BaseTask<T extends object> {
|
|
/**
|
|
* Schedule this task type to be processed asynchronously by a worker.
|
|
*
|
|
* @param props Properties to be used by the task
|
|
* @param options Job options such as priority and retry strategy, as defined by Bull.
|
|
* @returns A promise that resolves once the job is placed on the task queue
|
|
*/
|
|
public schedule(props: T, options?: JobOptions): Promise<Job> {
|
|
return taskQueue().add(
|
|
{
|
|
name: this.constructor.name,
|
|
props,
|
|
},
|
|
{ ...options, ...this.options }
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Execute the task.
|
|
*
|
|
* @param props Properties to be used by the task
|
|
* @returns A promise that resolves once the task has completed.
|
|
*/
|
|
public abstract perform(props: T): Promise<unknown>;
|
|
|
|
/**
|
|
* Handle failure when all attempts are exhausted for the task.
|
|
*
|
|
* @param props Properties to be used by the task
|
|
* @returns A promise that resolves once the task handles the failure.
|
|
*/
|
|
// oxlint-disable-next-line @typescript-eslint/no-unused-vars
|
|
public onFailed(props: T): Promise<void> {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
/**
|
|
* Job options such as priority and retry strategy.
|
|
*/
|
|
public get options(): JobOptions {
|
|
return {
|
|
priority: TaskPriority.Normal,
|
|
attempts: 5,
|
|
backoff: {
|
|
type: "exponential",
|
|
delay: 60 * 1000,
|
|
},
|
|
};
|
|
}
|
|
}
|