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

[FLASK] Add snap cronjobs #16239

Merged
merged 6 commits into from
Nov 9, 2022
Merged

[FLASK] Add snap cronjobs #16239

merged 6 commits into from
Nov 9, 2022

Conversation

david0xd
Copy link
Contributor

@david0xd david0xd commented Oct 20, 2022

Explanation

This PR will integrate CronjobController into the MetaMask Flask.

Cronjob controller will listen for specific Snap events and register or unregister CRON jobs specified through the Snap's permissions.

Cronjob represents periodically executed job as specified in the cron expression using cron syntax. Jobs are executed by calling RPC methods. (e.g. Calling specified RPC method periodically, like every minute or so.)

More Information

Fixes: MetaMask/snaps#353

Following PR is required to be merged and package published: MetaMask/snaps#651

Manual Testing Steps

  • Create a Snap that has Cronjob endowment with proper specification. Install/run Snap and wait for periodical RPC method call. (i.e. '* * * * *' - will execute a cronjob every minute)

Permission example:

  "initialPermissions": {
    "snap_confirm": {},
    "endowment:cronjob": {
      "jobs": [
        {
          "expression": "* * * * *",
          "request": {
            "method": "cronjobMethod",
            "params": [
              "cronjob_param"
            ]
          }
        }
      ]
    }
  }

Catching cronjob events in a snap:

export const onCronjob: OnRpcRequestHandler = ({ origin, request }) => {
  switch (request.method) {
    case 'cronjobMethod':
      console.log('cronjobMethod fired');
      break;
    default:
      throw new Error('Method not found.');
  }
};

Page with new permission request when installing Snap:
Screenshot 2022-11-08 at 16 46 28

Pre-Merge Checklist

  • Snaps Controllers package is released with: Add snap cronjobs snaps#651
  • Snaps Controllers package is updated to new version
  • PR template is filled out
  • PR is linked to the appropriate GitHub issue
  • PR has been added to the appropriate release Milestone

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [738ab04]
Page Load Metrics (2578 ± 247 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1001130187219105
domContentLoaded186143592546518249
load186143592578515247
domInteractive186143592546518249

highlights:

storybook

@david0xd david0xd marked this pull request as ready for review November 8, 2022 11:42
@david0xd david0xd requested a review from a team as a code owner November 8, 2022 11:42
@david0xd david0xd requested a review from danjm November 8, 2022 11:42
@FrederikBolding FrederikBolding changed the title [FLASK] Add Cronjob controller configuration [FLASK] Add snap cronjobs Nov 8, 2022
@metamaskbot
Copy link
Collaborator

Builds ready [c1ef093]
Page Load Metrics (2468 ± 182 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint95953197244117
domContentLoaded188135482430396190
load200435482468380182
domInteractive188135482430396190

highlights:

storybook

@david0xd david0xd merged commit 5e746dc into develop Nov 9, 2022
@david0xd david0xd deleted the dd/flask-cronjob branch November 9, 2022 12:18
@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cronjob permission (Q4)
4 participants