Skip to content

Commit 28b4284

Browse files
authored
Merge pull request #43 from adhocore/running
feat: optimize struct field align, add tasker Running check
2 parents d84c389 + ec135dd commit 28b4284

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

batch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
// Expr represents an item in array for batch check
99
type Expr struct {
10+
Err error
1011
Expr string
1112
Due bool
12-
Err error
1313
}
1414

1515
// BatchDue checks if multiple expressions are due for given time (or now).

pkg/tasker/tasker.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,26 @@ type Task struct {
3939

4040
// Tasker is the task manager.
4141
type Tasker struct {
42-
Log *log.Logger
42+
until time.Time
43+
ctx context.Context
4344
loc *time.Location
4445
gron *gronx.Gronx
45-
wg sync.WaitGroup
46-
until time.Time
46+
Log *log.Logger
4747
exprs map[string][]string
4848
tasks map[string]TaskFunc
4949
mutex map[string]uint32
50-
abort bool
51-
timeout bool
52-
verbose bool
53-
ctx context.Context
5450
ctxCancel context.CancelFunc
51+
wg sync.WaitGroup
52+
verbose bool
53+
running bool
54+
timeout bool
55+
abort bool
5556
}
5657

5758
type result struct {
59+
err error
5860
ref string
5961
code int
60-
err error
6162
}
6263

6364
var exit = os.Exit
@@ -228,6 +229,7 @@ func (t *Tasker) now() time.Time {
228229
// Run runs the task manager.
229230
func (t *Tasker) Run() {
230231
t.doSetup()
232+
t.running = true
231233

232234
first := true
233235
for !t.abort && !t.timeout {
@@ -257,6 +259,12 @@ func (t *Tasker) Run() {
257259
}
258260

259261
t.wait()
262+
t.running = false
263+
}
264+
265+
// Running tells if tasker is up and running
266+
func (t *Tasker) Running() bool {
267+
return t.running && !t.abort && !t.timeout
260268
}
261269

262270
// Stop the task manager.
@@ -396,7 +404,7 @@ func (t *Tasker) doRun(ctx context.Context, ref string, task TaskFunc, rc chan r
396404
t.mutex[ref] = 0
397405
}
398406

399-
rc <- result{ref, code, err}
407+
rc <- result{err, ref, code}
400408
}
401409

402410
func (t *Tasker) doOut(rc chan result) {

0 commit comments

Comments
 (0)