@nocobase/plugin-workflow 0.7.6-alpha.2 → 0.7.7-alpha.1

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.
@@ -244,6 +244,7 @@ class WorkflowPlugin extends _server().Plugin {
244
244
  }, {
245
245
  transaction
246
246
  });
247
+ console.log('workflow triggered:', new Date(), workflow.id, execution.id);
247
248
  const executed = yield workflow.countExecutions({
248
249
  transaction
249
250
  }); // NOTE: not to trigger afterUpdate hook here
@@ -49,14 +49,20 @@ const SCHEDULE_MODE = {
49
49
  };
50
50
  exports.SCHEDULE_MODE = SCHEDULE_MODE;
51
51
  const ScheduleModes = new Map();
52
+
53
+ function parseDateWithoutMs(date) {
54
+ return Math.floor(Date.parse(date) / 1000) * 1000;
55
+ }
56
+
52
57
  ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
53
58
  shouldCache(workflow, now) {
54
59
  const _workflow$config = workflow.config,
55
60
  startsOn = _workflow$config.startsOn,
56
61
  endsOn = _workflow$config.endsOn,
57
62
  repeat = _workflow$config.repeat;
58
- const timestamp = now.getTime();
59
- const startTime = Date.parse(startsOn);
63
+ const timestamp = now.getTime(); // NOTE: align to second start
64
+
65
+ const startTime = parseDateWithoutMs(startsOn);
60
66
 
61
67
  if (!startTime || startTime > timestamp + this.cacheCycle) {
62
68
  return false;
@@ -68,14 +74,14 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
68
74
  }
69
75
 
70
76
  if (endsOn) {
71
- const endTime = Date.parse(endsOn);
77
+ const endTime = parseDateWithoutMs(endsOn);
72
78
 
73
79
  if (!endTime || endTime <= timestamp) {
74
80
  return false;
75
81
  }
76
82
  }
77
83
  } else {
78
- if (startTime < timestamp) {
84
+ if (startTime <= timestamp) {
79
85
  return false;
80
86
  }
81
87
  }
@@ -88,8 +94,13 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
88
94
  startsOn = _workflow$config2.startsOn,
89
95
  endsOn = _workflow$config2.endsOn,
90
96
  repeat = _workflow$config2.repeat;
91
- const timestamp = now.getTime();
92
- const startTime = Math.floor(Date.parse(startsOn) / 1000) * 1000;
97
+ const timestamp = now.getTime(); // NOTE: align to second start
98
+
99
+ const startTime = parseDateWithoutMs(startsOn);
100
+
101
+ if (!startTime || startTime > timestamp) {
102
+ return;
103
+ }
93
104
 
94
105
  if (repeat) {
95
106
  if (typeof repeat === 'number') {
@@ -99,10 +110,10 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
99
110
  }
100
111
 
101
112
  if (endsOn) {
102
- const endTime = Date.parse(endsOn);
113
+ const endTime = parseDateWithoutMs(endsOn);
103
114
 
104
115
  if (!endTime || endTime < timestamp) {
105
- return false;
116
+ return;
106
117
  }
107
118
  }
108
119
  } else {
@@ -121,7 +132,7 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
121
132
  function getOnTimestampWithOffset(on, now) {
122
133
  switch (typeof on) {
123
134
  case 'string':
124
- return Date.parse(on);
135
+ return parseDateWithoutMs(on);
125
136
 
126
137
  case 'object':
127
138
  const field = on.field,
@@ -147,7 +158,7 @@ function getOnTimestampWithOffset(on, now) {
147
158
  function getDataOptionTime(data, on, dir = 1) {
148
159
  switch (typeof on) {
149
160
  case 'string':
150
- const time = Date.parse(on);
161
+ const time = parseDateWithoutMs(on);
151
162
  return time ? time : null;
152
163
 
153
164
  case 'object':
@@ -396,11 +407,6 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
396
407
  [_sequelize().Op.and]: conditions
397
408
  }
398
409
  });
399
-
400
- if (instances.length) {
401
- console.log(instances.length, 'rows trigger at', now);
402
- }
403
-
404
410
  instances.forEach(item => {
405
411
  _this3.plugin.trigger(workflow, {
406
412
  date: now,
@@ -543,6 +549,10 @@ class ScheduleTrigger extends _.Trigger {
543
549
  var _ref2 = _asyncToGenerator(function* (workflow) {
544
550
  const should = yield _this6.shouldCache(workflow, now);
545
551
 
552
+ if (should) {
553
+ console.log('caching schedule workflow:', workflow.id);
554
+ }
555
+
546
556
  _this6.setCache(workflow, !should);
547
557
  });
548
558
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-workflow",
3
- "version": "0.7.6-alpha.2",
3
+ "version": "0.7.7-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -10,17 +10,17 @@
10
10
  }
11
11
  ],
12
12
  "dependencies": {
13
- "@nocobase/actions": "0.7.6-alpha.2",
14
- "@nocobase/client": "0.7.6-alpha.2",
15
- "@nocobase/database": "0.7.6-alpha.2",
16
- "@nocobase/server": "0.7.6-alpha.2",
17
- "@nocobase/utils": "0.7.6-alpha.2",
13
+ "@nocobase/actions": "0.7.7-alpha.1",
14
+ "@nocobase/client": "0.7.7-alpha.1",
15
+ "@nocobase/database": "0.7.7-alpha.1",
16
+ "@nocobase/server": "0.7.7-alpha.1",
17
+ "@nocobase/utils": "0.7.7-alpha.1",
18
18
  "cron-parser": "4.4.0",
19
19
  "json-templates": "^4.2.0",
20
20
  "react-js-cron": "^1.4.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@nocobase/test": "0.7.6-alpha.2"
23
+ "@nocobase/test": "0.7.7-alpha.1"
24
24
  },
25
- "gitHead": "2cfccff9d3ff14c521bf317fa7ee4efa18444c92"
25
+ "gitHead": "f82374e6f9daaf71ba63eaf156468ea7ddc042da"
26
26
  }