@wireapp/core 42.9.1 → 42.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,11 +39,11 @@ const addTask = ({ key, firingDate, task, intervalDelay }) => {
39
39
  const tasks = (_a = intervals[intervalDelay]) === null || _a === void 0 ? void 0 : _a.tasks;
40
40
  if ((tasks === null || tasks === void 0 ? void 0 : tasks.length) !== 0) {
41
41
  for (const taskData of tasks) {
42
- if (nowTime >= firingDate) {
42
+ if (nowTime >= taskData.firingDate) {
43
43
  const { task, key } = taskData;
44
44
  logger.info(`Executing task with key "${key}"`);
45
- task();
46
45
  cancelTask({ intervalDelay, key });
46
+ task();
47
47
  }
48
48
  }
49
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RecurringTaskScheduler.d.ts","sourceRoot":"","sources":["../../../src/util/RecurringTaskScheduler/RecurringTaskScheduler.ts"],"names":[],"mappings":"AA0BA,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,qBAAqB,CAAC,EAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAC,EAAE,UAAU,QAoBnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,QAGlD"}
1
+ {"version":3,"file":"RecurringTaskScheduler.d.ts","sourceRoot":"","sources":["../../../src/util/RecurringTaskScheduler/RecurringTaskScheduler.ts"],"names":[],"mappings":"AA0BA,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,qBAAqB,CAAC,EAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAC,EAAE,UAAU,QAqBnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,QAIlD"}
@@ -24,13 +24,13 @@ const RecurringTaskScheduler_store_1 = require("./RecurringTaskScheduler.store")
24
24
  const LowPrecisionTaskScheduler_1 = require("../LowPrecisionTaskScheduler");
25
25
  const TaskScheduler_1 = require("../TaskScheduler");
26
26
  function registerRecurringTask({ every, task, key }) {
27
- var _a;
28
- const lastFireDate = (_a = (0, RecurringTaskScheduler_store_1.loadState)(key)) !== null && _a !== void 0 ? _a : Date.now();
27
+ const firingDate = (0, RecurringTaskScheduler_store_1.loadState)(key) || Date.now() + every;
28
+ (0, RecurringTaskScheduler_store_1.saveState)(key, firingDate);
29
29
  const taskConfig = {
30
- firingDate: lastFireDate + every,
30
+ firingDate,
31
31
  key,
32
- task() {
33
- (0, RecurringTaskScheduler_store_1.saveState)(key, Date.now());
32
+ task: () => {
33
+ (0, RecurringTaskScheduler_store_1.deleteState)(key);
34
34
  task();
35
35
  registerRecurringTask({ every, task, key });
36
36
  },
@@ -46,6 +46,7 @@ function registerRecurringTask({ every, task, key }) {
46
46
  }
47
47
  exports.registerRecurringTask = registerRecurringTask;
48
48
  function cancelRecurringTask(taskKey) {
49
+ (0, RecurringTaskScheduler_store_1.deleteState)(taskKey);
49
50
  TaskScheduler_1.TaskScheduler.cancelTask(taskKey);
50
51
  LowPrecisionTaskScheduler_1.LowPrecisionTaskScheduler.cancelTask({ intervalDelay: commons_1.TimeUtil.TimeInMillis.MINUTE, key: taskKey });
51
52
  }
@@ -36,6 +36,20 @@ describe('RecurringTaskScheduler', () => {
36
36
  jest.advanceTimersByTime(commons_1.TimeUtil.TimeInMillis.MINUTE + 1);
37
37
  expect(task).toHaveBeenCalledTimes(2);
38
38
  });
39
+ it('resumes a task after re-registering a recurring task', () => {
40
+ const task = jest.fn();
41
+ // it should fire in a minute
42
+ (0, RecurringTaskScheduler_1.registerRecurringTask)({ every: commons_1.TimeUtil.TimeInMillis.MINUTE, task, key: 'test-task2' });
43
+ jest.advanceTimersByTime(commons_1.TimeUtil.TimeInMillis.MINUTE / 2);
44
+ // re-register the task
45
+ (0, RecurringTaskScheduler_1.registerRecurringTask)({ every: commons_1.TimeUtil.TimeInMillis.MINUTE, task, key: 'test-task2' });
46
+ // only 30s have passed, so the task should not have fired yet
47
+ expect(task).toHaveBeenCalledTimes(0);
48
+ // advance the timer by another 30s (so we have 1 minute in total)
49
+ jest.advanceTimersByTime(commons_1.TimeUtil.TimeInMillis.MINUTE / 2);
50
+ // the task should have fired once after a minute from the beginning even if we re-registered it
51
+ expect(task).toHaveBeenCalledTimes(1);
52
+ });
39
53
  it('cancel a task before it is run', () => {
40
54
  const task = jest.fn();
41
55
  const testKey = 'test-task-1';
package/package.json CHANGED
@@ -60,6 +60,6 @@
60
60
  "test:coverage": "jest --coverage",
61
61
  "watch": "tsc --watch"
62
62
  },
63
- "version": "42.9.1",
64
- "gitHead": "f5b75f463f8b59a270e195176905d12f6eaa23c7"
63
+ "version": "42.9.2",
64
+ "gitHead": "8c7762276ee1d4563f2cfd02d0017fb8ad3f95a3"
65
65
  }