Skip to content

Commit

Permalink
Add clear all jobs and cast alarms to jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
nwehrhan committed Dec 2, 2024
1 parent dfec054 commit 8372c83
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/job-scheduler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export interface JobScheduler {
*/
removeJob(jobId: string): Promise<void>;

/**
* Un-schedules all jobs
*/
removeAllJobs(): Promise<void>;

/**
* Listen for a job to finish successfully.
*/
Expand Down Expand Up @@ -235,8 +240,10 @@ export function defineJobScheduler(options?: JobSchedulerConfig): JobScheduler {
}

async function listJobs() {
logger?.debug('Listing jobs: ');
return await browser.alarms.getAll();
logger?.debug('Listing jobs');
const alarms = await browser.alarms.getAll();

return alarms.map(alarm => jobs[alarm.name]);
}

/**
Expand Down Expand Up @@ -270,6 +277,10 @@ export function defineJobScheduler(options?: JobSchedulerConfig): JobScheduler {
await browser.alarms.clear(jobId);
},

async removeAllJobs() {
await browser.alarms.clearAll();
},

on(event, callback) {
const listeners = event === 'success' ? successListeners : errorListeners;
listeners.push(callback);
Expand Down

0 comments on commit 8372c83

Please sign in to comment.