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

Feat: Add background events #2941

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

Feat: Add background events #2941

wants to merge 15 commits into from

Conversation

hmalik88
Copy link
Contributor

This PR adds a new feature: background events, per SIP-28. A summary of the changes made:

  1. The CronjobController was updated to now include logic for handling and storing background events.
  2. snap_scheduleBackgroundEvent RPC method was added to schedule an event.
  3. snap_cancelBackgroundEvent RPC method was added to cancel an event.
  4. snap_getBackgroundEvents RPC method was added to get a snap's background events (not outlined in the SIP, but will be added as an addendum soon).

};

const subscriptionMap = new WeakMap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to keep a valid reference to the subscriptions, otherwise tests start breaking with subscription not found errors.

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 97.40260% with 4 lines in your changes missing coverage. Please review.

Project coverage is 94.52%. Comparing base (51ab913) to head (663f4fb).

Files with missing lines Patch % Lines
...snaps-controllers/src/cronjob/CronjobController.ts 95.50% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2941      +/-   ##
==========================================
+ Coverage   94.49%   94.52%   +0.03%     
==========================================
  Files         487      490       +3     
  Lines       10451    10583     +132     
  Branches     1604     1613       +9     
==========================================
+ Hits         9876    10004     +128     
- Misses        575      579       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hmalik88 hmalik88 marked this pull request as ready for review December 11, 2024 00:12
@hmalik88 hmalik88 requested a review from a team as a code owner December 11, 2024 00:12
package.json Outdated Show resolved Hide resolved
};

const subscriptionMap = new WeakMap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not a fan of this, there has to be a better way to handle teardown of controllers 🫠

I'll note again that the teardown might not be important regardless due to the client life-cycle. E.g. controllers aren't destroyed unless the extension is being shut down entirely anyway.

Copy link
Contributor Author

@hmalik88 hmalik88 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I know, I mostly added it in because it seemed like we were already testing destroy.

* @param snap - Basic Snap information.
*/
private _handleSnapDisabledEvent(snap: TruncatedSnap) {
this.unregister(snap.id, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following the logic here, unregister is called already for Snaps that are disabled or uninstalled. Why do we need a separate handler and this boolean flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't want to remove background event state when disabling, a snap can become enabled again and have unexpired events.

Copy link
Member

@FrederikBolding FrederikBolding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an example RPC method to the cronjob Snap that uses this API!

@hmalik88
Copy link
Contributor Author

Let's add an example RPC method to the cronjob Snap that uses this API!

Opened an issue for it! :)

@FrederikBolding
Copy link
Member

Let's add an example RPC method to the cronjob Snap that uses this API!

Opened an issue for it! :)

IMO it would be great to add it to this PR for ease of testing when we merge this!

@hmalik88
Copy link
Contributor Author

Let's add an example RPC method to the cronjob Snap that uses this API!

Opened an issue for it! :)

IMO it would be great to add it to this PR for ease of testing when we merge this!

Added in this PR.

Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected] None 0 120 kB types

View full report↗︎

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