Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List all jobs and remove all jobs #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nwehrhan
Copy link

@nwehrhan nwehrhan commented Dec 2, 2024

Hey, I would like to use the Job scheduler, but it's a couple of functions from the API.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/alarms

I started to implement the getAll, but I wasn't sure how I should cast back Alarms to Job Types 🤔 . I would also like to add the clearAll function and clear. Is it okay to return the Alarm object from these functions? Or should I just use the alarm API directly for these functions

@nwehrhan nwehrhan changed the title List all jobs List all jobs and remove all jobs Dec 2, 2024
@nwehrhan
Copy link
Author

nwehrhan commented Dec 2, 2024

I added listJobs and removeAllJobs. I was having issues with running the tests locally.

 bun test packages/job-scheduler
bun test v1.1.38 (bf2f153f)

packages/job-scheduler/src/index.test.ts:

# Unhandled error between tests
-------------------------------
error: Cannot find module '@webext-core/fake-browser' from '/Users/nicholaswehrhan/projects/webext-core/packages/job-scheduler/src/index.test.ts'
-------------------------------


 0 pass
 1 fail
 1 error
Ran 1 tests across 1 files. [34.00ms]

@aklinker1
Copy link
Owner

aklinker1 commented Dec 3, 2024

I started to implement the getAll, but I wasn't sure how I should cast back Alarms to Job Types

There isn't a way, at least there's no way to tell what type of job it is. This API wasn't really designed for managing jobs, just for kicking off tasks in the background that need to run every once in a while (and adding cron support for that).

For things like uploading data or cleaning caches.

Not really sure why I even included the removeJob function.

To implement what you've mentioned probably requires a rather large refactor, or a completely new package. My recommendation is, unless you're using cron, just use the alarms API directly.

@aklinker1
Copy link
Owner

aklinker1 commented Dec 3, 2024

In theory, we could pack the type and other information into the alarm ID, though I'm not sure how large those are allowed to be. And that would be a breaking change, so we'd have to document the upgrade process for removing the old jobs. Not saying we shouldn't do it, but I'd like to refactor things a bit as well if we're making breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants