@wmfs/tymly-schedule-plugin 1.0.0 → 1.1.0
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 +33 -0
- package/lib/blueprints/schedule-blueprint/card-templates/create-scheduled-task.json +97 -0
- package/lib/blueprints/schedule-blueprint/card-templates/view-all-scheduled-tasks.json +36 -0
- package/lib/blueprints/schedule-blueprint/card-templates/view-scheduled-task.json +148 -0
- package/lib/blueprints/schedule-blueprint/categories/schedule.json +8 -0
- package/lib/blueprints/schedule-blueprint/functions/generate-key.js +16 -0
- package/lib/blueprints/schedule-blueprint/functions/get-available-state-machines.js +18 -0
- package/lib/blueprints/schedule-blueprint/models/task.json +0 -14
- package/lib/blueprints/schedule-blueprint/state-machines/create-scheduled-task.json +66 -0
- package/lib/blueprints/schedule-blueprint/state-machines/modify-scheduled-task.json +74 -0
- package/lib/blueprints/schedule-blueprint/state-machines/start-task.json +36 -0
- package/lib/blueprints/schedule-blueprint/state-machines/stop-task.json +36 -0
- package/lib/blueprints/schedule-blueprint/state-machines/view-all-scheduled-tasks.json +69 -0
- package/lib/blueprints/schedule-blueprint/state-machines/view-scheduled-task.json +46 -0
- package/lib/blueprints/schedule-blueprint/template-roles/schedule-admin.json +4 -0
- package/lib/components/services/schedule/index.js +78 -24
- package/lib/components/state-resources/create-scheduled-task/doc/example.json +8 -0
- package/lib/components/state-resources/create-scheduled-task/doc/index.js +4 -0
- package/lib/components/state-resources/create-scheduled-task/index.js +56 -0
- package/lib/components/state-resources/find-scheduled-executions/doc/example.json +8 -0
- package/lib/components/state-resources/find-scheduled-executions/doc/index.js +4 -0
- package/lib/components/state-resources/find-scheduled-executions/index.js +12 -0
- package/lib/components/state-resources/start-scheduled-task/doc/example.json +8 -0
- package/lib/components/state-resources/start-scheduled-task/doc/index.js +4 -0
- package/lib/components/state-resources/start-scheduled-task/index.js +12 -0
- package/lib/components/state-resources/stop-scheduled-task/doc/example.json +8 -0
- package/lib/components/state-resources/stop-scheduled-task/doc/index.js +4 -0
- package/lib/components/state-resources/stop-scheduled-task/index.js +12 -0
- package/lib/components/state-resources/update-scheduled-state-machine-config/doc/example.json +12 -0
- package/lib/components/state-resources/update-scheduled-state-machine-config/doc/index.js +4 -0
- package/lib/components/state-resources/update-scheduled-state-machine-config/index.js +35 -0
- package/lib/components/state-resources/update-scheduled-task/doc/example.json +13 -0
- package/lib/components/state-resources/update-scheduled-task/doc/index.js +4 -0
- package/lib/components/state-resources/update-scheduled-task/index.js +26 -0
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/test/schedule-tests.js +17 -14
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Comment": "View Scheduled State Machine",
|
|
3
|
+
"name": "View Scheduled State Machine",
|
|
4
|
+
"version": "1.0",
|
|
5
|
+
"categories": [
|
|
6
|
+
"schedule"
|
|
7
|
+
],
|
|
8
|
+
"StartAt": "FindTask",
|
|
9
|
+
"States": {
|
|
10
|
+
"FindTask": {
|
|
11
|
+
"Type": "Task",
|
|
12
|
+
"InputPath": "$.key",
|
|
13
|
+
"Resource": "module:findingById",
|
|
14
|
+
"ResourceConfig": {
|
|
15
|
+
"modelId": "schedule_task"
|
|
16
|
+
},
|
|
17
|
+
"ResultPath": "$",
|
|
18
|
+
"Next": "FindExecutions"
|
|
19
|
+
},
|
|
20
|
+
"FindExecutions": {
|
|
21
|
+
"Type": "Task",
|
|
22
|
+
"InputPath": "$.key",
|
|
23
|
+
"Resource": "module:findScheduledExecutions",
|
|
24
|
+
"ResultPath": "$.executions",
|
|
25
|
+
"Next": "View"
|
|
26
|
+
},
|
|
27
|
+
"View": {
|
|
28
|
+
"Type": "Task",
|
|
29
|
+
"Resource": "module:awaitingHumanInput",
|
|
30
|
+
"ResourceConfig": {
|
|
31
|
+
"uiType": "app",
|
|
32
|
+
"uiName": "schedule_viewScheduledTask",
|
|
33
|
+
"dataPath": "$"
|
|
34
|
+
},
|
|
35
|
+
"End": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"restrictions": [
|
|
39
|
+
{
|
|
40
|
+
"roleId": "schedule_scheduleAdmin",
|
|
41
|
+
"allows": [
|
|
42
|
+
"*"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const INSTIGATING_CLIENT_DOMAIN = 'tymly-schedule-plugin'
|
|
2
|
+
|
|
1
3
|
const nodeSchedule = require('node-schedule')
|
|
2
4
|
const ruleToDatetime = require('./utils/rule-to-datetime')
|
|
3
5
|
const datetimeToRule = require('./utils/datetime-to-rule')
|
|
@@ -6,6 +8,9 @@ class CronService {
|
|
|
6
8
|
async boot (options) {
|
|
7
9
|
this.statebox = options.bootedServices.statebox
|
|
8
10
|
this.taskModel = options.bootedServices.storage.models.schedule_task
|
|
11
|
+
this.executionModel = options.bootedServices.storage.models.tymly_execution
|
|
12
|
+
|
|
13
|
+
// todo: rename blueprint component to scheduled-tasks, blueprint component to have "type": "stateMachineName"
|
|
9
14
|
this.scheduledTasks = await this.findTasks(options.blueprintComponents.stateMachineSchedules)
|
|
10
15
|
|
|
11
16
|
for (const [key, task] of Object.entries(this.scheduledTasks)) {
|
|
@@ -54,11 +59,11 @@ class CronService {
|
|
|
54
59
|
jobOptions,
|
|
55
60
|
() => {
|
|
56
61
|
console.log(`Running scheduled state machine ${stateMachineName}`)
|
|
57
|
-
const startedAt = new Date()
|
|
58
62
|
const executionOptions = {
|
|
59
63
|
instigatingClient: {
|
|
60
64
|
appName: 'tymly',
|
|
61
|
-
domain:
|
|
65
|
+
domain: INSTIGATING_CLIENT_DOMAIN,
|
|
66
|
+
scheduleKey: key
|
|
62
67
|
},
|
|
63
68
|
sendResponse
|
|
64
69
|
}
|
|
@@ -66,7 +71,6 @@ class CronService {
|
|
|
66
71
|
if (err) {
|
|
67
72
|
console.log(`There was an error on execution of scheduled state machine ${stateMachineName}`)
|
|
68
73
|
}
|
|
69
|
-
await this.updateTaskOnExecution(key, executionDescription.executionName, startedAt)
|
|
70
74
|
}
|
|
71
75
|
this.statebox.startExecution(input, stateMachineName, executionOptions, cb)
|
|
72
76
|
}
|
|
@@ -74,7 +78,7 @@ class CronService {
|
|
|
74
78
|
|
|
75
79
|
this.scheduledTasks[key] = task
|
|
76
80
|
|
|
77
|
-
return this.updateTaskStatus(key, 'STARTED')
|
|
81
|
+
return this.updateTaskStatus(key, task.job === null ? 'STOPPED' : 'STARTED')
|
|
78
82
|
} // startTask
|
|
79
83
|
|
|
80
84
|
stopTask (key) {
|
|
@@ -105,7 +109,7 @@ class CronService {
|
|
|
105
109
|
setMissingPropertiesToNull: false
|
|
106
110
|
}
|
|
107
111
|
)
|
|
108
|
-
}
|
|
112
|
+
} // updateTaskStatus
|
|
109
113
|
|
|
110
114
|
stopTasks () {
|
|
111
115
|
return Promise.all(
|
|
@@ -113,7 +117,7 @@ class CronService {
|
|
|
113
117
|
)
|
|
114
118
|
} // stopTasks
|
|
115
119
|
|
|
116
|
-
async findTasks (blueprintTasks) {
|
|
120
|
+
async findTasks (blueprintTasks = {}) {
|
|
117
121
|
const tasks = {}
|
|
118
122
|
|
|
119
123
|
// From database
|
|
@@ -129,6 +133,11 @@ class CronService {
|
|
|
129
133
|
continue
|
|
130
134
|
}
|
|
131
135
|
|
|
136
|
+
const stateMachineOk = this.checkIfStateMachineExists(config.stateMachineName)
|
|
137
|
+
if (!stateMachineOk) {
|
|
138
|
+
continue
|
|
139
|
+
}
|
|
140
|
+
|
|
132
141
|
// todo: recurrence rules?
|
|
133
142
|
|
|
134
143
|
if (typeof config.interval === 'string') {
|
|
@@ -140,6 +149,10 @@ class CronService {
|
|
|
140
149
|
config.interval = null
|
|
141
150
|
}
|
|
142
151
|
|
|
152
|
+
config.input = typeof config.input === 'object'
|
|
153
|
+
? config.input
|
|
154
|
+
: {}
|
|
155
|
+
|
|
143
156
|
tasks[key] = config
|
|
144
157
|
|
|
145
158
|
await this.persistTask(key, config)
|
|
@@ -158,35 +171,44 @@ class CronService {
|
|
|
158
171
|
interval: config.interval,
|
|
159
172
|
datetime: config.datetime,
|
|
160
173
|
startOnBoot: config.startOnBoot,
|
|
161
|
-
lastRanStart: null,
|
|
162
|
-
lastRanEnd: null,
|
|
163
|
-
lastRanExecutionName: null,
|
|
164
|
-
totalRunCount: 0,
|
|
165
174
|
status: null
|
|
166
175
|
})
|
|
167
|
-
}
|
|
176
|
+
} // persistTask
|
|
168
177
|
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
checkIfStateMachineExists (stateMachineName) {
|
|
179
|
+
const [stateMachineOk, errStateMachineDesc] = this.statebox.checkIfStateMachineExists(stateMachineName)
|
|
180
|
+
|
|
181
|
+
if (!stateMachineOk) {
|
|
182
|
+
console.log('State machine error', errStateMachineDesc)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return stateMachineOk
|
|
186
|
+
} // checkIfStateMachineExists
|
|
187
|
+
|
|
188
|
+
async stopAndUpdateStateMachineConfig (key, stateMachineName, input) {
|
|
189
|
+
await this.stopTask(key)
|
|
190
|
+
|
|
191
|
+
const stateMachineOk = this.checkIfStateMachineExists(stateMachineName)
|
|
192
|
+
if (!stateMachineOk) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.scheduledTasks[key].stateMachineName = stateMachineName
|
|
197
|
+
this.scheduledTasks[key].input = typeof input === 'object'
|
|
198
|
+
? input
|
|
199
|
+
: {}
|
|
176
200
|
|
|
177
201
|
return this.taskModel.update(
|
|
178
202
|
{
|
|
179
203
|
key,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
lastRanExecutionName: executionName,
|
|
183
|
-
totalRunCount: totalRunCount + 1
|
|
204
|
+
stateMachineName: this.scheduledTasks[key].stateMachineName,
|
|
205
|
+
input: this.scheduledTasks[key].input
|
|
184
206
|
},
|
|
185
207
|
{
|
|
186
208
|
setMissingPropertiesToNull: false
|
|
187
209
|
}
|
|
188
210
|
)
|
|
189
|
-
}
|
|
211
|
+
} // stopAndUpdateStateMachineConfig
|
|
190
212
|
|
|
191
213
|
async stopAndUpdateTaskSchedule (key, rule) {
|
|
192
214
|
await this.stopTask(key)
|
|
@@ -212,7 +234,39 @@ class CronService {
|
|
|
212
234
|
setMissingPropertiesToNull: false
|
|
213
235
|
}
|
|
214
236
|
)
|
|
215
|
-
}
|
|
237
|
+
} // stopAndUpdateTaskSchedule
|
|
238
|
+
|
|
239
|
+
async findScheduledExecutions (key) {
|
|
240
|
+
const executions = await this.executionModel.find({
|
|
241
|
+
fields: [
|
|
242
|
+
'executionName',
|
|
243
|
+
'executionOptions',
|
|
244
|
+
'status',
|
|
245
|
+
'created',
|
|
246
|
+
'modified'
|
|
247
|
+
],
|
|
248
|
+
where: {
|
|
249
|
+
stateMachineName: {
|
|
250
|
+
equals: this.scheduledTasks[key].stateMachineName
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
orderBy: ['-modified']
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
return executions.filter(({ executionOptions }) => {
|
|
257
|
+
executionOptions = typeof executionOptions === 'string'
|
|
258
|
+
? JSON.parse(executionOptions)
|
|
259
|
+
: executionOptions
|
|
260
|
+
|
|
261
|
+
return executionOptions.instigatingClient.domain === INSTIGATING_CLIENT_DOMAIN &&
|
|
262
|
+
executionOptions.instigatingClient.scheduleKey === key
|
|
263
|
+
})
|
|
264
|
+
} // findScheduledExecutions
|
|
265
|
+
|
|
266
|
+
createScheduledTask (key, config = {}) {
|
|
267
|
+
this.scheduledTasks[key] = config
|
|
268
|
+
return this.persistTask(key, config)
|
|
269
|
+
} // createScheduledTask
|
|
216
270
|
|
|
217
271
|
async shutdown () {
|
|
218
272
|
await nodeSchedule.gracefulShutdown()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// const datetimeToRule = require('../../services/schedule/utils/datetime-to-rule')
|
|
2
|
+
|
|
3
|
+
class CreateScheduledTask {
|
|
4
|
+
init (resourceConfig, env) {
|
|
5
|
+
this.services = env.bootedServices
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async run (event, context) {
|
|
9
|
+
const {
|
|
10
|
+
key,
|
|
11
|
+
stateMachineName,
|
|
12
|
+
scheduleType,
|
|
13
|
+
datetime,
|
|
14
|
+
interval
|
|
15
|
+
} = event
|
|
16
|
+
|
|
17
|
+
const stateMachineOk = this.services.schedule.checkIfStateMachineExists(stateMachineName)
|
|
18
|
+
if (!stateMachineOk) {
|
|
19
|
+
return context.sendTaskSuccess()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let input = typeof event.input === 'object'
|
|
23
|
+
? event.input
|
|
24
|
+
: {}
|
|
25
|
+
|
|
26
|
+
if (typeof event.input === 'string') {
|
|
27
|
+
try {
|
|
28
|
+
input = JSON.parse(event.input)
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.log('Issue with input', event.input)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// const rule = scheduleType === 'interval'
|
|
35
|
+
// ? interval
|
|
36
|
+
// : datetimeToRule(new Date(datetime))
|
|
37
|
+
|
|
38
|
+
const config = {
|
|
39
|
+
stateMachineName,
|
|
40
|
+
input,
|
|
41
|
+
sendResponse: 'COMPLETE',
|
|
42
|
+
scheduleType,
|
|
43
|
+
interval,
|
|
44
|
+
datetime,
|
|
45
|
+
startOnBoot: false // todo
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await this.services.schedule.createScheduledTask(key, config)
|
|
49
|
+
// await this.services.schedule.stopAndUpdateTaskSchedule(key, rule)
|
|
50
|
+
// await this.services.schedule.stopAndUpdateStateMachineConfig(key, stateMachineName, input)
|
|
51
|
+
|
|
52
|
+
return context.sendTaskSuccess()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = CreateScheduledTask
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class FindScheduledExecutions {
|
|
2
|
+
init (resourceConfig, env) {
|
|
3
|
+
this.services = env.bootedServices
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async run (key, context) {
|
|
7
|
+
const executions = await this.services.schedule.findScheduledExecutions(key)
|
|
8
|
+
return context.sendTaskSuccess(executions)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = FindScheduledExecutions
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class StartScheduledTask {
|
|
2
|
+
init (resourceConfig, env) {
|
|
3
|
+
this.services = env.bootedServices
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async run (key, context) {
|
|
7
|
+
await this.services.schedule.startTask(key)
|
|
8
|
+
return context.sendTaskSuccess()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = StartScheduledTask
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class StopScheduledTask {
|
|
2
|
+
init (resourceConfig, env) {
|
|
3
|
+
this.services = env.bootedServices
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async run (key, context) {
|
|
7
|
+
await this.services.schedule.stopTask(key)
|
|
8
|
+
return context.sendTaskSuccess()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = StopScheduledTask
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class UpdateScheduledStateMachineConfig {
|
|
2
|
+
init (resourceConfig, env) {
|
|
3
|
+
this.services = env.bootedServices
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async run (event, context) {
|
|
7
|
+
const {
|
|
8
|
+
key,
|
|
9
|
+
stateMachineName
|
|
10
|
+
} = event
|
|
11
|
+
|
|
12
|
+
const stateMachineOk = this.services.schedule.checkIfStateMachineExists(stateMachineName)
|
|
13
|
+
if (!stateMachineOk) {
|
|
14
|
+
return context.sendTaskSuccess()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let input = typeof event.input === 'object'
|
|
18
|
+
? event.input
|
|
19
|
+
: {}
|
|
20
|
+
|
|
21
|
+
if (typeof event.input === 'string') {
|
|
22
|
+
try {
|
|
23
|
+
input = JSON.parse(event.input)
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.log('Issue with input', event.input)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await this.services.schedule.stopAndUpdateStateMachineConfig(key, stateMachineName, input)
|
|
30
|
+
|
|
31
|
+
return context.sendTaskSuccess()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = UpdateScheduledStateMachineConfig
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"UpdateScheduledTask": {
|
|
3
|
+
"Type": "Task",
|
|
4
|
+
"Parameters": {
|
|
5
|
+
"key.$": "$.key",
|
|
6
|
+
"scheduleType.$": "$.scheduleType",
|
|
7
|
+
"datetime.$": "$.datetime",
|
|
8
|
+
"interval.$": "$.interval"
|
|
9
|
+
},
|
|
10
|
+
"Resource": "module:updateScheduledTask",
|
|
11
|
+
"End": true
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const datetimeToRule = require('../../services/schedule/utils/datetime-to-rule')
|
|
2
|
+
|
|
3
|
+
class UpdateScheduledTask {
|
|
4
|
+
init (resourceConfig, env) {
|
|
5
|
+
this.services = env.bootedServices
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async run (event, context) {
|
|
9
|
+
const {
|
|
10
|
+
key,
|
|
11
|
+
scheduleType,
|
|
12
|
+
datetime,
|
|
13
|
+
interval
|
|
14
|
+
} = event
|
|
15
|
+
|
|
16
|
+
const rule = scheduleType === 'interval'
|
|
17
|
+
? interval
|
|
18
|
+
: datetimeToRule(new Date(datetime))
|
|
19
|
+
|
|
20
|
+
await this.services.schedule.stopAndUpdateTaskSchedule(key, rule)
|
|
21
|
+
|
|
22
|
+
return context.sendTaskSuccess()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = UpdateScheduledTask
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wmfs/tymly-schedule-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@semantic-release/git": "10.0.1",
|
|
31
31
|
"@wmfs/tymly": "1.235.1",
|
|
32
32
|
"@wmfs/tymly-pg-plugin": "1.268.0",
|
|
33
|
+
"@wmfs/tymly-test-helpers": "1.16.0",
|
|
33
34
|
"chai": "4.3.6",
|
|
34
35
|
"codecov": "3.8.3",
|
|
35
36
|
"conventional-changelog-metahub": "4.0.1",
|
package/plugin.json
CHANGED
package/test/schedule-tests.js
CHANGED
|
@@ -18,9 +18,7 @@ describe('Tymly schedule tests', function () {
|
|
|
18
18
|
|
|
19
19
|
let tymlyService
|
|
20
20
|
let scheduleService
|
|
21
|
-
// let statebox
|
|
22
21
|
let catStatsModel
|
|
23
|
-
// let executionsModel
|
|
24
22
|
let taskModel
|
|
25
23
|
let client
|
|
26
24
|
|
|
@@ -34,17 +32,16 @@ describe('Tymly schedule tests', function () {
|
|
|
34
32
|
],
|
|
35
33
|
pluginPaths: [
|
|
36
34
|
path.resolve(__dirname, '..'),
|
|
37
|
-
require.resolve('@wmfs/tymly-pg-plugin')
|
|
35
|
+
require.resolve('@wmfs/tymly-pg-plugin'),
|
|
36
|
+
require.resolve('@wmfs/tymly-test-helpers/plugins/mock-users-plugin')
|
|
38
37
|
]
|
|
39
38
|
}
|
|
40
39
|
)
|
|
41
40
|
|
|
42
41
|
tymlyService = tymlyServices.tymly
|
|
43
42
|
scheduleService = tymlyServices.schedule
|
|
44
|
-
// statebox = tymlyServices.statebox
|
|
45
43
|
taskModel = tymlyServices.storage.models.schedule_task
|
|
46
44
|
catStatsModel = tymlyServices.storage.models.tymlyTest_catStats
|
|
47
|
-
// executionsModel = tymlyServices.storage.models.tymly_execution
|
|
48
45
|
client = tymlyServices.storage.client
|
|
49
46
|
|
|
50
47
|
const catStats = await catStatsModel.find({})
|
|
@@ -74,9 +71,8 @@ describe('Tymly schedule tests', function () {
|
|
|
74
71
|
expect(tasks[0].datetime).to.eql(null)
|
|
75
72
|
expect(tasks[0].status).to.eql('STOPPED')
|
|
76
73
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
lastRunCount = totalRunCount
|
|
74
|
+
const executions = await scheduleService.findScheduledExecutions(scheduleKey)
|
|
75
|
+
lastRunCount = executions.length
|
|
80
76
|
|
|
81
77
|
// Waited 10 seconds and runs every 2 seconds so can be 5 or 6
|
|
82
78
|
expect(lastRunCount).to.be.greaterThanOrEqual(5)
|
|
@@ -96,7 +92,8 @@ describe('Tymly schedule tests', function () {
|
|
|
96
92
|
expect(tasks[0].datetime).to.eql(null)
|
|
97
93
|
expect(tasks[0].status).to.eql('STOPPED')
|
|
98
94
|
|
|
99
|
-
|
|
95
|
+
const executions = await scheduleService.findScheduledExecutions(scheduleKey)
|
|
96
|
+
expect(executions.length).to.eql(lastRunCount)
|
|
100
97
|
|
|
101
98
|
const catStats = await catStatsModel.find({})
|
|
102
99
|
expect(catStats.length).to.eql(lastRunCount)
|
|
@@ -131,9 +128,11 @@ describe('Tymly schedule tests', function () {
|
|
|
131
128
|
expect(tasks[0].interval).to.eql(null)
|
|
132
129
|
expect(tasks[0].datetime).to.not.eql(null)
|
|
133
130
|
expect(tasks[0].scheduleType).to.eql('datetime')
|
|
134
|
-
expect(tasks[0].totalRunCount).to.eql(lastRunCount)
|
|
135
131
|
expect(tasks[0].status).to.eql('STARTED')
|
|
136
132
|
|
|
133
|
+
const executions = await scheduleService.findScheduledExecutions(scheduleKey)
|
|
134
|
+
expect(executions.length).to.eql(lastRunCount)
|
|
135
|
+
|
|
137
136
|
const catStats = await catStatsModel.find({})
|
|
138
137
|
expect(catStats.length).to.eql(lastRunCount)
|
|
139
138
|
})
|
|
@@ -145,7 +144,8 @@ describe('Tymly schedule tests', function () {
|
|
|
145
144
|
expect(tasks.length).to.eql(1)
|
|
146
145
|
expect(tasks[0].status).to.eql('STARTED')
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
const executions = await scheduleService.findScheduledExecutions(scheduleKey)
|
|
148
|
+
expect(executions.length).to.eql(lastRunCount)
|
|
149
149
|
|
|
150
150
|
const catStats = await catStatsModel.find({})
|
|
151
151
|
expect(catStats.length).to.eql(lastRunCount)
|
|
@@ -163,7 +163,8 @@ describe('Tymly schedule tests', function () {
|
|
|
163
163
|
],
|
|
164
164
|
pluginPaths: [
|
|
165
165
|
path.resolve(__dirname, '..'),
|
|
166
|
-
require.resolve('@wmfs/tymly-pg-plugin')
|
|
166
|
+
require.resolve('@wmfs/tymly-pg-plugin'),
|
|
167
|
+
require.resolve('@wmfs/tymly-test-helpers/plugins/mock-users-plugin')
|
|
167
168
|
]
|
|
168
169
|
}
|
|
169
170
|
)
|
|
@@ -182,8 +183,10 @@ describe('Tymly schedule tests', function () {
|
|
|
182
183
|
expect(tasks[0].stateMachineName).to.eql('tymlyTest_sendCatUpdate')
|
|
183
184
|
expect(tasks[0].scheduleType).to.eql('datetime')
|
|
184
185
|
expect(tasks[0].interval).to.eql(null)
|
|
185
|
-
expect(tasks[0].status).to.eql('
|
|
186
|
-
|
|
186
|
+
expect(tasks[0].status).to.eql('STOPPED')
|
|
187
|
+
|
|
188
|
+
const executions = await scheduleService.findScheduledExecutions(scheduleKey)
|
|
189
|
+
expect(executions.length).to.eql(lastRunCount)
|
|
187
190
|
})
|
|
188
191
|
|
|
189
192
|
it('clean up data', async () => {
|