@live-change/timer-service 0.8.52 → 0.8.54
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/index.js +20 -4
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -21,6 +21,9 @@ const Timer = definition.model({
|
|
|
21
21
|
timestamp: {
|
|
22
22
|
type: Number
|
|
23
23
|
},
|
|
24
|
+
time: {
|
|
25
|
+
type: Date,
|
|
26
|
+
},
|
|
24
27
|
loops: {
|
|
25
28
|
type: Number
|
|
26
29
|
},
|
|
@@ -53,6 +56,10 @@ const Timer = definition.model({
|
|
|
53
56
|
},
|
|
54
57
|
cause: {
|
|
55
58
|
type: String
|
|
59
|
+
},
|
|
60
|
+
createdAt: {
|
|
61
|
+
type: Date,
|
|
62
|
+
default: () => new Date()
|
|
56
63
|
}
|
|
57
64
|
},
|
|
58
65
|
indexes: {
|
|
@@ -126,6 +133,7 @@ async function timersLoop() {
|
|
|
126
133
|
}
|
|
127
134
|
let nextTs = timersQueue[0].timestamp
|
|
128
135
|
let now = Date.now()
|
|
136
|
+
//console.log("NEXT TS", nextTs, '<', now, '-->', nextTs < now, "INQ", timersQueue)
|
|
129
137
|
while(nextTs < now) {
|
|
130
138
|
fireTimer(timersQueue.shift())
|
|
131
139
|
if(timersQueue.length === 0) {
|
|
@@ -232,6 +240,7 @@ async function startTimers() {
|
|
|
232
240
|
|
|
233
241
|
function runTimerAction(timer) {
|
|
234
242
|
console.error("RUN ACTION", timer)
|
|
243
|
+
console.trace("RUN ACTION")
|
|
235
244
|
if(timer.command) {
|
|
236
245
|
if(!timer.command.service) timer.command.service = timer.service
|
|
237
246
|
return app.command({
|
|
@@ -260,7 +269,8 @@ function runTimerAction(timer) {
|
|
|
260
269
|
}
|
|
261
270
|
|
|
262
271
|
function insertTimer(timer) {
|
|
263
|
-
console.log("INSERT TIMER", timer, "TO", timersQueue)
|
|
272
|
+
//console.log("INSERT TIMER", timer, "TO", timersQueue)
|
|
273
|
+
if(timersById.has(timer.id)) return //throw new Error("INSERT TIMER DUPLICATED!!!")
|
|
264
274
|
timersById.set(timer.id, timer)
|
|
265
275
|
for(let i = 0; i < timersQueue.length; i++) {
|
|
266
276
|
if(timer.timestamp < timersQueue[i].timestamp) {
|
|
@@ -296,9 +306,15 @@ definition.trigger({
|
|
|
296
306
|
}
|
|
297
307
|
},
|
|
298
308
|
async execute({ timer }, { client, service, trigger }, emit) {
|
|
299
|
-
console.log("CREATE TIMER", timer)
|
|
300
309
|
if(!timer) throw new Error("timer is required")
|
|
301
|
-
let timestamp = new Date(timer.timestamp).getTime()
|
|
310
|
+
let timestamp = timer.timestamp && new Date(timer.timestamp).getTime()
|
|
311
|
+
let time = timer.time && new Date(timer.time)
|
|
312
|
+
if((!time) && (!timestamp)) {
|
|
313
|
+
console.log("TIMER", timer, "TIME", time, "TIMESTAMP", timestamp)
|
|
314
|
+
throw new Error("timestamp or time is required")
|
|
315
|
+
}
|
|
316
|
+
if(!timestamp) timestamp = time.getTime()
|
|
317
|
+
if(!time) time = new Date(timestamp)
|
|
302
318
|
let loops = timer.loops || 0
|
|
303
319
|
let timerId = timer.id || app.generateUid()
|
|
304
320
|
let maxRetries = timer.maxRetries || 0
|
|
@@ -306,7 +322,7 @@ definition.trigger({
|
|
|
306
322
|
let interval = timer.interval || 0
|
|
307
323
|
if(loops > 0 && interval === 0) throw new Error("impossibleTimer")
|
|
308
324
|
const props = {
|
|
309
|
-
...timer, timestamp, loops, interval, timerId, maxRetries, retryDelay, retries: 0,
|
|
325
|
+
...timer, timestamp, time, loops, interval, timerId, maxRetries, retryDelay, retries: 0,
|
|
310
326
|
causeType: trigger.causeType,
|
|
311
327
|
cause: trigger.cause
|
|
312
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/timer-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.54",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.8.
|
|
25
|
+
"@live-change/framework": "^0.8.54"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1558b41fc331424507874c0afd3d149ffb849ca8"
|
|
28
28
|
}
|