-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
252 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: go | ||
go: | ||
- 1.11.x | ||
env: | ||
- GO111MODULE=on | ||
script: | ||
- GOOS=windows go install -mod vendor github.com/liujianping/job | ||
- GOOS=linux go install -mod vendor github.com/liujianping/job | ||
- GOOS=darwin go install -mod vendor github.com/liujianping/job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package build | ||
|
||
import "fmt" | ||
|
||
var ( | ||
version = "dev" | ||
commit = "none" | ||
date = "unknown" | ||
) | ||
|
||
//Print version | ||
func Print() { | ||
fmt.Printf("%v, commit %v, built at %v\n", version, commit, date) | ||
} | ||
|
||
//Info build info | ||
func Info(v, m, d string) { | ||
version = v | ||
commit = m | ||
date = d | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
|
||
"github.com/liujianping/job/config" | ||
"github.com/liujianping/job/exec" | ||
"github.com/x-mod/routine" | ||
) | ||
|
||
//JOBs type | ||
type JOBs struct { | ||
jds []*config.JD | ||
report *exec.Reporter | ||
} | ||
|
||
//NewJOBs new JOBs | ||
func NewJOBs(jds []*config.JD, report *exec.Reporter) *JOBs { | ||
return &JOBs{ | ||
jds: jds, | ||
report: report, | ||
} | ||
} | ||
|
||
//Len of JOBs | ||
func (jobs JOBs) Len() int { | ||
return len(jobs.jds) | ||
} | ||
|
||
//Less Cmp of JOBs | ||
func (jobs JOBs) Less(i, j int) bool { | ||
return jobs.jds[i].Order.Weight < jobs.jds[j].Order.Weight | ||
} | ||
|
||
//Swap of JOBs | ||
func (jobs JOBs) Swap(i, j int) { | ||
jobs.jds[i], jobs.jds[j] = jobs.jds[j], jobs.jds[i] | ||
} | ||
|
||
//Sort of JOBs | ||
func (jobs JOBs) Sort() { | ||
sort.Sort(jobs) | ||
} | ||
|
||
//Execute impl executor | ||
func (jobs JOBs) Execute(ctx context.Context) error { | ||
jmap := make(map[string]chan error, jobs.Len()) | ||
var tail chan error | ||
for _, jd := range jobs.jds { | ||
if len(jd.Order.Precondition) == 0 { | ||
job := exec.NewJob(jd, jobs.report) | ||
ch := routine.Go(ctx, job) | ||
jmap[job.String()] = ch | ||
tail = ch | ||
if jd.Order.Wait { | ||
<-ch | ||
} | ||
} | ||
} | ||
for _, jd := range jobs.jds { | ||
for _, pre := range jd.Order.Precondition { | ||
if ch, ok := jmap[pre]; ok { | ||
<-ch | ||
} | ||
job := exec.NewJob(jd, jobs.report) | ||
ch := routine.Go(ctx, job) | ||
jmap[job.String()] = ch | ||
tail = ch | ||
if jd.Order.Wait { | ||
<-ch | ||
} | ||
} | ||
} | ||
return <-tail | ||
} |
Oops, something went wrong.