Skip to content

Commit

Permalink
Merge pull request #43 from adhocore/running
Browse files Browse the repository at this point in the history
feat: optimize struct field align, add tasker Running check
  • Loading branch information
adhocore authored Aug 18, 2024
2 parents d84c389 + ec135dd commit 28b4284
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

// Expr represents an item in array for batch check
type Expr struct {
Err error
Expr string
Due bool
Err error
}

// BatchDue checks if multiple expressions are due for given time (or now).
Expand Down
26 changes: 17 additions & 9 deletions pkg/tasker/tasker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@ type Task struct {

// Tasker is the task manager.
type Tasker struct {
Log *log.Logger
until time.Time
ctx context.Context
loc *time.Location
gron *gronx.Gronx
wg sync.WaitGroup
until time.Time
Log *log.Logger
exprs map[string][]string
tasks map[string]TaskFunc
mutex map[string]uint32
abort bool
timeout bool
verbose bool
ctx context.Context
ctxCancel context.CancelFunc
wg sync.WaitGroup
verbose bool
running bool
timeout bool
abort bool
}

type result struct {
err error
ref string
code int
err error
}

var exit = os.Exit
Expand Down Expand Up @@ -228,6 +229,7 @@ func (t *Tasker) now() time.Time {
// Run runs the task manager.
func (t *Tasker) Run() {
t.doSetup()
t.running = true

first := true
for !t.abort && !t.timeout {
Expand Down Expand Up @@ -257,6 +259,12 @@ func (t *Tasker) Run() {
}

t.wait()
t.running = false
}

// Running tells if tasker is up and running
func (t *Tasker) Running() bool {
return t.running && !t.abort && !t.timeout
}

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

rc <- result{ref, code, err}
rc <- result{err, ref, code}
}

func (t *Tasker) doOut(rc chan result) {
Expand Down

0 comments on commit 28b4284

Please sign in to comment.