///
import Admin from "./admin";
import { RedisConnection } from "./redis";
import { EventEmitter } from "events";
import { ObjectID } from "bson";
import { Db } from "mongodb";
/** A job is a scheduled task that runs in the context of an admin. */
export interface Job {
/** The schedule for this job. */
schedule: JobSchedule;
/** The name of this scheduled job. */
name: string;
/** The type of the job, defaults to normal */
type?: JobType;
/** Runs the job. */
run(context: JobContext): Promise;
}
/** Contains the context when running a job. */
export declare class JobContext extends EventEmitter {
/** The redis database in this context. */
redis: RedisConnection;
/** The mongo database in this context. */
mongo: Db;
/** The data in this context. */
private data;
/** Construct given the context data. */
constructor(data: JobContextData);
/** Adds a message to the job result. */
message(text: string): this;
/** Opens the context. */
open(): Promise;
/** Closes the context's database connections. */
close(): void;
}
export declare interface JobContext {
/** Emitted when the job sends a message. */
on(event: "message", handler: (text: string) => void): any;
}
/** Contains the actual (serializable) data for the job context. */
export interface JobContextData {
redisUrl: string;
mongoUrl: string;
}
/** Runs a job at its given schedule. */
export declare class JobRunner {
/** The job this runner is running. */
readonly job: Job;
/** The path to the job module of this job runner. */
private jobPath;
/** The admin that owns this job runner. */
private admin;
/** The timeout id of the job runner task. */
private timeout;
/** The date that this job last ran. */
private lastRunDate;
/** Construct given the job to run. */
constructor(jobPath: string, admin: Admin);
/** Schedules this runner to run at the top of the next hour. */
schedule(): void;
/**
* Executes the job this is running.
* @returns a promise for the id of the job-log document inserted for this run.
*/
execute(): Promise;
/** Stops the job from running. */
stop(): JobRunner;
}
/** The types of jobs */
export declare enum JobType {
Normal = "normal",
Manual = "manual"
}
/** Describes how often a job should be run. */
export interface JobSchedule {
/**
* The month in which this job should run (jan=1, feb=1, ..., dec=12).
* If left null or set to "*" then this job will run every month.
*/
month?: Month | '*';
/**
* The day of the week the job should run (sun=1, mon=2, ..., sat=7).
* If left null or set to "*" then this job will run every day of the week.
*/
day?: Day | '*';
/**
* The hour of the day the job should run at (12:00 AM = 0, 1:00 AM = 1, ..., 12:00 PM = 12, ..., 11:00 PM = 23).
* If left null or set to "*" then this job will run every hour of the day.
*/
hour?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | "*";
}
/** The months available for scheduling jobs. */
export declare enum Month {
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}
/** The weekdays available for scheduling jobs. */
export declare enum Day {
Sunday = 1,
Monday = 2,
Tuesday = 3,
Wednesday = 4,
Thursday = 5,
Friday = 6,
Saturday = 7
}
/** The possible job statuses. */
export declare enum JobStatus {
Running = "running",
Complete = "complete",
Error = "error"
}
/** A job executor is responsible for running a job. */
export declare abstract class JobExecutor extends EventEmitter {
/** The data in this job's context. */
protected data: JobContextData;
/** The path to the job module to execute. */
protected jobPath: string;
/** Construct given the context data. */
constructor(jobPath: string, data: JobContextData);
/** Runs the job. */
abstract run(): Promise;
}
export declare interface JobExecutor {
/** Event when a message from the job is to be logged. */
on(event: "message", listener: (message: string) => void): any;
}
/** A job executor that forks to run jobs. */
export declare class ForkingExecutor extends JobExecutor {
/** The path to the job runtime. */
private static RUNTIME_PATH;
/** Runs the job by forking. */
run(): Promise;
}