UNPKG

agendash

Version:

Dashboard for Agenda job scheduler

76 lines (75 loc) 2.79 kB
import type { Agenda, AgendaStatus, StateNotificationHandler } from 'agenda'; import type { AgendashController as IAgendashController, ApiQueryParams, ApiResponse, CreateJobRequest, CreateJobResponse, DeleteResponse, RequeueResponse, RetryResponse, PauseResponse, ResumeResponse, LogsQueryParams, LogsResponse } from './types.js'; /** * Agendash Controller - Core logic for dashboard operations * * Uses the database-agnostic Agenda API (v6) for all operations: * - agenda.queryJobs() for filtering, pagination, state computation * - agenda.getJobsOverview() for statistics * - agenda.cancel() for deletion */ export declare class AgendashController implements IAgendashController { private agenda; constructor(agenda: Agenda); /** * Transform a job from the new API format to the frontend format */ private transformJob; /** * Transform overview from new API format to frontend format */ private transformOverview; /** * Get jobs with overview and filtering */ getJobs(params: ApiQueryParams): Promise<ApiResponse>; /** * Requeue jobs by creating new instances */ requeueJobs(ids: string[]): Promise<RequeueResponse>; /** * Retry jobs by setting their nextRunAt to now (reuses existing job) */ retryJobs(ids: string[]): Promise<RetryResponse>; /** * Delete jobs by ID */ deleteJobs(ids: string[]): Promise<DeleteResponse>; /** * Create a new job */ createJob(options: CreateJobRequest): Promise<CreateJobResponse>; /** * Get running stats from the Agenda processor */ getStats(fullDetails?: boolean): Promise<AgendaStatus>; /** * Pause jobs by ID (disables them so they won't run) */ pauseJobs(ids: string[]): Promise<PauseResponse>; /** * Resume jobs by ID (re-enables them so they can run) */ resumeJobs(ids: string[]): Promise<ResumeResponse>; /** * Check if state notifications are available */ hasStateNotifications(): boolean; /** * Create a subscription to job state notifications for real-time updates (SSE). * This subscribes directly to the notification channel, bypassing the event re-emitting. * * @param onNotification - Callback function called for each state notification * @returns Unsubscribe function to stop receiving notifications * @throws Error if notification channel doesn't support state subscriptions */ createStateStream(onNotification: StateNotificationHandler): () => void; /** * Check if persistent job logging is enabled */ hasLogging(): boolean; /** * Get job log entries with filtering and pagination */ getLogs(params: LogsQueryParams): Promise<LogsResponse>; }