Skip to content

Commit c81d711

Browse files
fix: Clear cronjobs when installing a Snap
1 parent 0e13483 commit c81d711

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/snaps-controllers/src/cronjob/CronjobController.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,22 @@ describe('CronjobController', () => {
498498

499499
const cronjobController = new CronjobController({
500500
messenger: controllerMessenger,
501+
state: {
502+
events: {
503+
[`cronjob-${MOCK_SNAP_ID}-0`]: {
504+
id: `cronjob-${MOCK_SNAP_ID}-0`,
505+
recurring: true,
506+
date: '2022-01-01T00:01:00.000Z',
507+
schedule: '* * * * *',
508+
scheduledAt: '2022-01-01T00:00:00.000Z',
509+
snapId: MOCK_SNAP_ID,
510+
request: {
511+
method: 'exampleMethodTwo',
512+
params: ['p1'],
513+
},
514+
},
515+
},
516+
},
501517
});
502518

503519
cronjobController.init();

packages/snaps-controllers/src/cronjob/CronjobController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ export class CronjobController extends BaseController<
521521
* @param snap - Basic Snap information.
522522
*/
523523
readonly #handleSnapInstalledEvent = (snap: TruncatedSnap) => {
524+
// In case of local Snaps, they may already have cronjobs that should be cleared.
525+
this.unregister(snap.id);
524526
this.register(snap.id);
525527
};
526528

0 commit comments

Comments
 (0)