@webext-core/job-schedulerCronJobinterface CronJob extends cron.ParserOptions<false> {
id: string;
type: "cron";
expression: string;
execute: ExecuteFn;
}
A job that is executed based on a CRON expression. Backed by cron-parser.
cron.ParserOptions includes options like timezone.
id: stringtype: 'cron'expression: stringcron-parser's supported expressionsexecute: ExecuteFndefineJobSchedulerfunction defineJobScheduler(options?: JobSchedulerConfig): JobScheduler {
// ...
}
Requires the
alarmspermission.
Creates a JobScheduler backed by the
alarms API.
options?: JobSchedulerConfigA JobScheduler that can be used to schedule and manage jobs.
ExecuteFntype ExecuteFn = () => Promise<any> | any;
Function ran when executing the job. Errors are automatically caught and will trigger the
"error" event. If a value is returned, the result will be available in the "success" event.
IntervalJobinterface IntervalJob {
id: string;
type: "interval";
duration: number;
immediate?: boolean;
execute: ExecuteFn;
}
A job that executes on a set interval, starting when the job is scheduled for the first time.
id: stringtype: 'interval'duration: numberimmediate?: boolean (default: false)false, it will
execute for the first time after duration. This has no effect when updating an existing job.execute: ExecuteFnJobtype Job = IntervalJob | CronJob | OnceJob;
JobSchedulerinterface JobScheduler {
scheduleJob(job: Job): Promise<void>;
removeJob(jobId: string): Promise<void>;
on(
event: "success",
callback: (job: Job, result: any) => void,
): RemoveListenerFn;
on(
event: "error",
callback: (job: Job, error: unknown) => void,
): RemoveListenerFn;
}
JobSchedulerConfiginterface JobSchedulerConfig {
logger?: Logger | null;
}
Configures how the job scheduler behaves.
logger?: Logger | null (default: console)null to disable logging.Loggerinterface Logger {
debug(...args: any[]): void;
log(...args: any[]): void;
warn(...args: any[]): void;
error(...args: any[]): void;
}
Interface used to log text to the console when creating and executing jobs.
OnceJobinterface OnceJob {
id: string;
type: "once";
date: Date | string | number;
execute: ExecuteFn;
}
Runs a job once, at a specific date/time.
id: stringtype: 'once'date: Date | string | numberexecute: ExecuteFnAPI reference generated by docs/generate-api-references.ts