@wmfs/tymly-schedule-plugin 1.6.0 → 1.6.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.
- package/.version +1 -1
- package/CHANGELOG.md +25 -0
- package/lib/components/services/schedule/index.js +6 -6
- package/lib/components/services/schedule/utils/datetime-to-rule.js +3 -0
- package/lib/components/services/schedule/utils/rule-to-datetime.js +2 -3
- package/package.json +4 -4
- package/plugin.json +1 -1
- package/test/rule-to-datetime-tests.js +25 -38
- package/test/schedule-tests.js +3 -2
package/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION=1.6.
|
|
1
|
+
VERSION=1.6.1
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
## [1.6.1](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.6.0...v1.6.1) (2023-06-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🐛 Bug Fixes
|
|
5
|
+
|
|
6
|
+
* better utc handling with consequent test updates ([d15c042](https://github.com/wmfs/tymly-schedule-plugin/commit/d15c042987ebb61fb382eedb057413d718e825ea))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🛠 Builds
|
|
10
|
+
|
|
11
|
+
* **deps-dev:** update dependency [@wmfs](https://github.com/wmfs)/tymly-pg-plugin to v1.283.0 ([3322021](https://github.com/wmfs/tymly-schedule-plugin/commit/332202187f248defb6a68403dec428e9176efdbb))
|
|
12
|
+
* **deps-dev:** update dependency semantic-release to v21.0.3 ([b2da7ba](https://github.com/wmfs/tymly-schedule-plugin/commit/b2da7babde8a45e0d899870ee5b4021c8a662d3b))
|
|
13
|
+
* **deps-dev:** update dependency standard to v17.1.0 ([f7def04](https://github.com/wmfs/tymly-schedule-plugin/commit/f7def04f6abdb127fb0aa6ad02cc7b069480dee9))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 📦 Code Refactoring
|
|
17
|
+
|
|
18
|
+
* renamed vars to improve clarity ([4ed331c](https://github.com/wmfs/tymly-schedule-plugin/commit/4ed331c0edbbd3740e72b18961122d2710ce4e39))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🚨 Tests
|
|
22
|
+
|
|
23
|
+
* minor change from let to const for standard ([e81e5de](https://github.com/wmfs/tymly-schedule-plugin/commit/e81e5dec130e9d35ad9460a316a3bce42ea9fcfc))
|
|
24
|
+
* restored tests that were inadvertantly removed ([843e6d5](https://github.com/wmfs/tymly-schedule-plugin/commit/843e6d5e0ddd9e5046e39df8ff068e489e7fdfd7))
|
|
25
|
+
|
|
1
26
|
# [1.6.0](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.5.0...v1.6.0) (2023-06-06)
|
|
2
27
|
|
|
3
28
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const INSTIGATING_CLIENT_DOMAIN = 'tymly-schedule-plugin'
|
|
2
2
|
|
|
3
3
|
const nodeSchedule = require('node-schedule')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const ruleToUTCDateTime = require('./utils/rule-to-datetime')
|
|
5
|
+
const localDateTimeToUTCRule = require('./utils/datetime-to-rule')
|
|
6
6
|
const { v4: uuidv4 } = require('uuid')
|
|
7
7
|
|
|
8
8
|
class CronService {
|
|
@@ -45,7 +45,7 @@ class CronService {
|
|
|
45
45
|
if (scheduleType === 'interval') {
|
|
46
46
|
jobOptions.rule = interval
|
|
47
47
|
} else if (scheduleType === 'datetime') {
|
|
48
|
-
const rule =
|
|
48
|
+
const rule = localDateTimeToUTCRule(datetime)
|
|
49
49
|
|
|
50
50
|
Object
|
|
51
51
|
.entries(rule)
|
|
@@ -58,7 +58,7 @@ class CronService {
|
|
|
58
58
|
task.job = nodeSchedule.scheduleJob(
|
|
59
59
|
jobOptions,
|
|
60
60
|
() => {
|
|
61
|
-
console.log(`Running scheduled state machine ${stateMachineName}`)
|
|
61
|
+
console.log(`Running scheduled state machine ${stateMachineName} at ${new Date()}`)
|
|
62
62
|
const executionOptions = {
|
|
63
63
|
instigatingClient: {
|
|
64
64
|
appName: 'tymly',
|
|
@@ -145,7 +145,7 @@ class CronService {
|
|
|
145
145
|
config.datetime = null
|
|
146
146
|
} else if (typeof config.rule === 'object') {
|
|
147
147
|
config.scheduleType = 'datetime'
|
|
148
|
-
config.datetime =
|
|
148
|
+
config.datetime = ruleToUTCDateTime(config.rule)
|
|
149
149
|
config.interval = null
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -219,7 +219,7 @@ class CronService {
|
|
|
219
219
|
this.scheduledTasks[key].scheduleType = 'interval'
|
|
220
220
|
} else if (typeof rule === 'object') {
|
|
221
221
|
this.scheduledTasks[key].interval = null
|
|
222
|
-
this.scheduledTasks[key].datetime =
|
|
222
|
+
this.scheduledTasks[key].datetime = ruleToUTCDateTime(rule)
|
|
223
223
|
this.scheduledTasks[key].scheduleType = 'datetime'
|
|
224
224
|
}
|
|
225
225
|
|
|
@@ -12,7 +12,6 @@ module.exports = function (rule = {}) {
|
|
|
12
12
|
)
|
|
13
13
|
// note that rule does not specify a timezone, so we have to assume that
|
|
14
14
|
// the timestamp provided is a local timestamp - as such, we have to convert
|
|
15
|
-
// to UTC
|
|
16
|
-
|
|
17
|
-
return moment(date).add(now.getTimezoneOffset(), 'minutes').toDate()
|
|
15
|
+
// to UTC
|
|
16
|
+
return moment(date).utc().toDate()
|
|
18
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wmfs/tymly-schedule-plugin",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Provides state machine scheduling for the Tymly framework",
|
|
5
5
|
"homepage": "https://github.com/wmfs/tymly-schedule-plugin#readme",
|
|
6
6
|
"author": "West Midlands Fire Service",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@semantic-release/exec": "6.0.3",
|
|
32
32
|
"@semantic-release/git": "10.0.1",
|
|
33
33
|
"@wmfs/tymly": "1.242.0",
|
|
34
|
-
"@wmfs/tymly-pg-plugin": "1.
|
|
34
|
+
"@wmfs/tymly-pg-plugin": "1.283.0",
|
|
35
35
|
"@wmfs/tymly-test-helpers": "1.22.2",
|
|
36
36
|
"chai": "4.3.7",
|
|
37
37
|
"codecov": "3.8.3",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"dirty-chai": "2.0.1",
|
|
41
41
|
"mocha": "10.2.0",
|
|
42
42
|
"nyc": "15.1.0",
|
|
43
|
-
"semantic-release": "21.0.
|
|
44
|
-
"standard": "17.
|
|
43
|
+
"semantic-release": "21.0.3",
|
|
44
|
+
"standard": "17.1.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"lint": "standard",
|
package/plugin.json
CHANGED
|
@@ -8,10 +8,9 @@ const datetimeToRule = require('../lib/components/services/schedule/utils/dateti
|
|
|
8
8
|
|
|
9
9
|
describe('Rule to datetime tests', function () {
|
|
10
10
|
it('No options, should default to now (UTC)', () => {
|
|
11
|
-
|
|
12
|
-
now = moment(now).add(now.getTimezoneOffset(), 'minutes').toDate()
|
|
13
|
-
const datetime = ruleToDatetime()
|
|
11
|
+
const now = moment().utc().toDate()
|
|
14
12
|
|
|
13
|
+
const datetime = ruleToDatetime()
|
|
15
14
|
expect(datetime.getFullYear()).to.eql(now.getFullYear())
|
|
16
15
|
expect(datetime.getMonth()).to.eql(now.getMonth())
|
|
17
16
|
expect(datetime.getDate()).to.eql(now.getDate())
|
|
@@ -22,7 +21,7 @@ describe('Rule to datetime tests', function () {
|
|
|
22
21
|
|
|
23
22
|
it('Year only, the rest defaults to now', () => {
|
|
24
23
|
let now = new Date()
|
|
25
|
-
now = moment(now).
|
|
24
|
+
now = moment(now).utc().toDate()
|
|
26
25
|
const year = now.getFullYear() + 2
|
|
27
26
|
|
|
28
27
|
const datetime = ruleToDatetime({ year })
|
|
@@ -48,7 +47,7 @@ describe('Rule to datetime tests', function () {
|
|
|
48
47
|
|
|
49
48
|
const datetime = ruleToDatetime(rule)
|
|
50
49
|
|
|
51
|
-
const utcTimestamp = moment(now).
|
|
50
|
+
const utcTimestamp = moment(now).utc().toDate()
|
|
52
51
|
|
|
53
52
|
expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
|
|
54
53
|
expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
|
|
@@ -71,7 +70,7 @@ describe('Rule to datetime tests', function () {
|
|
|
71
70
|
|
|
72
71
|
const datetime = ruleToDatetime(rule)
|
|
73
72
|
|
|
74
|
-
const utcTimestamp = moment(now).
|
|
73
|
+
const utcTimestamp = moment(now).utc().toDate()
|
|
75
74
|
|
|
76
75
|
expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
|
|
77
76
|
expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
|
|
@@ -83,8 +82,8 @@ describe('Rule to datetime tests', function () {
|
|
|
83
82
|
})
|
|
84
83
|
|
|
85
84
|
describe('Datetime to rule tests', function () {
|
|
86
|
-
it('No options, should default to now', () => {
|
|
87
|
-
const now = moment()
|
|
85
|
+
it('No options, should default to now (UTC)', () => {
|
|
86
|
+
const now = moment().utc()
|
|
88
87
|
const rule = datetimeToRule()
|
|
89
88
|
|
|
90
89
|
expect(rule.year).to.eql(now.year())
|
|
@@ -95,47 +94,35 @@ describe('Datetime to rule tests', function () {
|
|
|
95
94
|
expect(rule.second).to.eql(now.second())
|
|
96
95
|
})
|
|
97
96
|
|
|
98
|
-
it('Specific year, the rest should default to now', () => {
|
|
99
|
-
let datetime = new Date()
|
|
100
|
-
const year = datetime.getFullYear() + 2
|
|
101
|
-
datetime.setFullYear(year)
|
|
102
|
-
|
|
103
|
-
const rule = datetimeToRule(datetime)
|
|
104
|
-
datetime = moment(datetime)
|
|
105
|
-
|
|
106
|
-
expect(rule.year).to.eql(year)
|
|
107
|
-
expect(rule.month).to.eql(datetime.month())
|
|
108
|
-
expect(rule.date).to.eql(datetime.date())
|
|
109
|
-
expect(rule.hour).to.eql(datetime.hour())
|
|
110
|
-
expect(rule.minute).to.eql(datetime.minute())
|
|
111
|
-
expect(rule.second).to.eql(datetime.second())
|
|
112
|
-
})
|
|
113
|
-
|
|
114
97
|
it('DST test, should change time by +1 hour', () => {
|
|
115
|
-
const
|
|
98
|
+
const lastMinuteOfGMT = new Date('Sunday March 27 2022 00:59:00')
|
|
99
|
+
console.log(`last minute of GMT: ${lastMinuteOfGMT}`)
|
|
116
100
|
|
|
117
|
-
|
|
118
|
-
|
|
101
|
+
let startOfBSTDateTime = moment(lastMinuteOfGMT).add(1, 'minutes').toDate()
|
|
102
|
+
console.log(`start of BST: ${startOfBSTDateTime}`)
|
|
119
103
|
|
|
120
104
|
// adding 1 min and setting as Date object
|
|
121
|
-
const rule = datetimeToRule(new Date(
|
|
105
|
+
const rule = datetimeToRule(new Date(lastMinuteOfGMT.getTime() + (60 * 1000)))
|
|
122
106
|
|
|
123
|
-
|
|
124
|
-
expect(rule.
|
|
125
|
-
expect(rule.
|
|
107
|
+
startOfBSTDateTime = moment(startOfBSTDateTime).utc()
|
|
108
|
+
expect(rule.date).to.eql(startOfBSTDateTime.date())
|
|
109
|
+
expect(rule.hour).to.eql(startOfBSTDateTime.hour())
|
|
110
|
+
expect(rule.minute).to.eql(startOfBSTDateTime.minute())
|
|
126
111
|
})
|
|
127
112
|
|
|
128
113
|
it('DST test, should change time by -1 hour', () => {
|
|
129
|
-
const
|
|
114
|
+
const lastMinuteOfBST = new Date('Sunday October 30 2022 01:59:00')
|
|
115
|
+
console.log(`last minute of BST: ${lastMinuteOfBST}`)
|
|
130
116
|
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
let startOfGMTDateTime = moment(lastMinuteOfBST).add(1, 'minutes').toDate()
|
|
118
|
+
console.log(`start of GMT: ${startOfGMTDateTime}`)
|
|
133
119
|
|
|
134
120
|
// adding 1 min and setting as Date object
|
|
135
|
-
const rule = datetimeToRule(new Date(
|
|
121
|
+
const rule = datetimeToRule(new Date(lastMinuteOfBST.getTime() + (60 * 1000)))
|
|
136
122
|
|
|
137
|
-
|
|
138
|
-
expect(rule.
|
|
139
|
-
expect(rule.
|
|
123
|
+
startOfGMTDateTime = moment(startOfGMTDateTime).utc()
|
|
124
|
+
expect(rule.date).to.eql(startOfGMTDateTime.date())
|
|
125
|
+
expect(rule.hour).to.eql(startOfGMTDateTime.hour())
|
|
126
|
+
expect(rule.minute).to.eql(startOfGMTDateTime.minute())
|
|
140
127
|
})
|
|
141
128
|
})
|
package/test/schedule-tests.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const expect = require('chai').expect
|
|
4
4
|
const tymly = require('@wmfs/tymly')
|
|
5
5
|
const path = require('path')
|
|
6
|
+
const moment = require('moment')
|
|
6
7
|
|
|
7
8
|
const scheduleKey = 'tymlyTest_twoSecondCatUpdates'
|
|
8
9
|
|
|
@@ -100,8 +101,8 @@ describe('Tymly schedule tests', function () {
|
|
|
100
101
|
})
|
|
101
102
|
|
|
102
103
|
it('update task to specific date/time', async () => {
|
|
103
|
-
const datetime =
|
|
104
|
-
|
|
104
|
+
const datetime = moment().utc().add(10, 'seconds').toDate()
|
|
105
|
+
console.log(`scheduled: ${datetime}`)
|
|
105
106
|
|
|
106
107
|
await scheduleService.stopAndUpdateTaskSchedule(
|
|
107
108
|
scheduleKey,
|