sidequest
Version:
Sidequest is a modern, scalable background job processor for Node.js applications.
125 lines (122 loc) • 4.55 kB
TypeScript
import * as _sidequest_backend from '@sidequest/backend';
import * as _sidequest_engine from '@sidequest/engine';
import { JobClassType } from '@sidequest/core';
import { JobOperations } from './job.js';
import { QueueOperations } from './queue.js';
import { KnownDrivers, SidequestEngineConfig, SidequestConfig } from './types.js';
/**
* Main entry point for the Sidequest job processing system.
*
* The Sidequest class provides static methods to configure, start, and build jobs
* within the Sidequest ecosystem. It serves as a high-level interface that coordinates
* the underlying Engine and Dashboard components.
*
* @example
* ```typescript
* // Configure and start Sidequest with dashboard
* const engine = await Sidequest.start({
* // engine configuration
* dashboard: {
* // dashboard configuration
* }
* });
*
* // Build and execute a job
* const jobBuilder = Sidequest.build(MyJobClass);
* ```
*/
declare class Sidequest {
/**
* Static reference to the Engine instance used by Sidequest.
* This allows access to the underlying engine for advanced operations.
*/
private static engine;
/**
* Static reference to the SidequestDashboard instance.
* This provides access to the dashboard for monitoring and managing jobs and queues.
*/
private static dashboard;
/**
* Provides access to the singleton QueueOperations instance for managing queues.
*
* @example
* ```typescript
* const updatedQueue = await Sidequest.queue.pauseQueue("default");
* ```
*/
static readonly queue: QueueOperations;
/**
* Static reference to the JobOperations singleton instance.
* Provides access to job-related operations and management functionality.
*
* @example
* ```typescript
* const jobData = Sidequest.job.get(jobId);
* ```
*/
static readonly job: JobOperations;
/**
* Configures the Sidequest engine system with the provided configuration options.
* This method only initializes the engine and does not start the engine or dashboard.
* It is useful for when you want to set up the configuration without starting the job processing.
*
* @param config - Optional configuration object to customize Sidequest behavior
* @returns A Promise that resolves when the configuration is complete
*
* @example
* ```typescript
* await Sidequest.configure({
* // configuration options
* });
* ```
*/
static configure<TDriver extends string = KnownDrivers>(config?: SidequestEngineConfig<TDriver>): Promise<_sidequest_engine.NonNullableEngineConfig>;
/**
* Starts the Sidequest engine and dashboard with the provided configuration.
*
* @param config - Optional configuration object that includes engine settings and dashboard configuration
* @param config.dashboard - Dashboard-specific configuration, excluding backendConfig which is automatically provided
* based on the engine configuration.
* @returns A promise that resolves when the engine and dashboard are fully started.
*
* @example
* ```typescript
* const engine = await Sidequest.start({
* // engine config...
* dashboard: {
* port: 3000,
* // other dashboard options...
* }
* });
* ```
*/
static start<TDriver extends string = KnownDrivers>(config?: SidequestConfig<TDriver>): Promise<void>;
/**
* Stops the SideQuest instance by closing all active components.
*
* This method performs cleanup operations including:
* - Closing the engine
* - Clearing the job backend
* - Clearing the queue backend
* - Closing the dashboard
*
* @returns A promise that resolves when all cleanup operations are complete
*/
static stop(): Promise<void>;
/**
* Builds a job class using a JobBuilder.
*
* @param JobClass The job class constructor.
* @returns a JobBuilder that can be used to chain parameters and other job configurations.
*/
static build<T extends JobClassType>(JobClass: T): _sidequest_engine.JobBuilder<T>;
/**
* Gets the backend instance from the Sidequest engine.
* This is useful for advanced operations that require direct access to the backend.
*
* @returns The backend instance.
* @throws Error if the engine is not configured.
*/
static getBackend(): _sidequest_backend.Backend | undefined;
}
export { Sidequest };