Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize struct field align, add tasker Running check #43

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading