Skip to content

Commit

Permalink
Merge pull request #10 from gochore/dev
Browse files Browse the repository at this point in the history
new JobOption WithNoMutext

close #8
  • Loading branch information
wolfogre authored Mar 2, 2020
2 parents 6ae9b75 + 7aaf8b8 commit 9fa0eb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion inner_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type innerJob struct {
after AfterFunc
retryTimes int
retryInterval RetryInterval
noMutex bool
}

func (j *innerJob) Key() string {
Expand Down Expand Up @@ -60,7 +61,7 @@ func (j *innerJob) Run() {
}

if !task.Skipped {
if j.cron.mutex == nil || j.cron.mutex.SetIfNotExists(task.Key, c.hostname) {
if j.noMutex || j.cron.mutex == nil || j.cron.mutex.SetIfNotExists(task.Key, c.hostname) {
beginAt := time.Now()
task.BeginAt = &beginAt

Expand Down
6 changes: 6 additions & 0 deletions job_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ func WithRetryInterval(retryInterval RetryInterval) JobOption {
job.retryInterval = retryInterval
}
}

func WithNoMutex() JobOption {
return func(job *innerJob) {
job.noMutex = true
}
}
24 changes: 24 additions & 0 deletions job_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,27 @@ func TestWithRetryTimes(t *testing.T) {
})
}
}

func TestWithNoMutex(t *testing.T) {
tests := []struct {
name string
check func(t *testing.T, option JobOption)
}{
{
name: "regular",
check: func(t *testing.T, option JobOption) {
j := &innerJob{}
option(j)
if !j.noMutex {
t.Fatal(j.noMutex)
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := WithNoMutex()
tt.check(t, got)
})
}
}

0 comments on commit 9fa0eb6

Please sign in to comment.