Skip to content

Commit 4dfea54

Browse files
committed
runTask helper
1 parent bf85f84 commit 4dfea54

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

examples/tasks/status-display.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class StatusDisplayTask extends ITask {
66

77
constructor(options){
88
super({
9-
name: StatusDisplayTask.Name,
10-
background: true,
9+
name: StatusDisplayTask.name,
10+
background: StatusDisplayTask.Config.background,
1111
...options
1212
})
1313

@@ -16,6 +16,13 @@ class StatusDisplayTask extends ITask {
1616
this.duration = 5000
1717
this.timeout = null
1818
}
19+
20+
static get Config(){
21+
return {
22+
background: true,
23+
autostart: true
24+
}
25+
}
1926

2027
async exec(){
2128

src/service/itask.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const tasker = require('@dataparty/tasker')
44

55
module.exports = class ITask extends tasker.Task {
66

7+
constructor(options){
8+
super(options)
9+
}
10+
711
static get Name(){
812
throw new Error('not implemented')
913
}
@@ -12,10 +16,23 @@ module.exports = class ITask extends tasker.Task {
1216
throw new Error('not implemented')
1317
}
1418

19+
static get Config(){
20+
throw new Error('not implemented')
21+
22+
/**
23+
*
24+
* return {
25+
* background: true
26+
* autostart: true
27+
* }
28+
*/
29+
}
30+
1531
static get info(){
1632
return {
1733
Name: this.Name,
18-
Description: this.Description
34+
Description: this.Description,
35+
Config: this.Config
1936
}
2037
}
2138
}

src/service/service-runner-node.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const EndpointContext = require('./endpoint-context')
88
const DeltaTime = require('../utils/delta-time')
99

1010
const Router = require('origin-router').Router
11-
1211
const Runner = require('@dataparty/tasker').Runner
1312

1413
class ServiceRunnerNode {
@@ -97,11 +96,21 @@ class ServiceRunnerNode {
9796

9897
this.tasks[name] = task
9998

100-
this.taskRunner.addTask(task)
99+
if(TaskClass.Config.autostart){
100+
this.taskRunner.addTask(task)
101+
}
102+
103+
101104
dt.end()
102105
debug('loaded task',name,'in',dt.deltaMs,'ms')
103106
}
104107

108+
runTask(name){
109+
const task = this.tasks[name]
110+
111+
this.taskRunner.addTask(task)
112+
}
113+
105114
async loadEndpoint(name){
106115
if(this.endpoint[name]){
107116
return

0 commit comments

Comments
 (0)