File tree 4 files changed +3
-27
lines changed
4 files changed +3
-27
lines changed Original file line number Diff line number Diff line change @@ -2,24 +2,9 @@ package job
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
)
7
6
8
7
type JobStore interface {
9
8
EnqueueJob (newJob Job ) (ID , error )
10
9
WaitForJobs (ctx context.Context , ids ... ID ) error
11
10
}
12
-
13
- type jobStoreCtxKey struct {}
14
-
15
- func WithJobStore (ctx context.Context , js JobStore ) context.Context {
16
- return context .WithValue (ctx , jobStoreCtxKey {}, js )
17
- }
18
-
19
- func JobStoreFromContext (ctx context.Context ) (JobStore , error ) {
20
- js , ok := ctx .Value (jobStoreCtxKey {}).(JobStore )
21
- if ! ok {
22
- return nil , fmt .Errorf ("not found JobStore in context" )
23
- }
24
- return js , nil
25
- }
Original file line number Diff line number Diff line change @@ -69,8 +69,7 @@ func (s *Scheduler) eval(ctx context.Context) {
69
69
70
70
deferredJobIds := make (job.IDs , 0 )
71
71
if nextJob .Defer != nil {
72
- deferCtx := job .WithJobStore (ctx , s .jobStorage )
73
- deferredJobIds , err = nextJob .Defer (deferCtx , jobErr )
72
+ deferredJobIds , err = nextJob .Defer (ctx , jobErr )
74
73
if err != nil {
75
74
s .logger .Printf ("deferred job failed: %s" , err )
76
75
}
Original file line number Diff line number Diff line change @@ -262,11 +262,7 @@ func TestScheduler_defer(t *testing.T) {
262
262
Type : "test-type" ,
263
263
Defer : func (ctx context.Context , jobErr error ) (job.IDs , error ) {
264
264
ids := make (job.IDs , 0 )
265
- je , err := job .JobStoreFromContext (ctx )
266
- if err != nil {
267
- log .Fatal (err )
268
- return ids , err
269
- }
265
+ je := ss .JobStore
270
266
271
267
id1 , err := je .EnqueueJob (job.Job {
272
268
Dir : document .DirHandleFromPath (dirPath ),
Original file line number Diff line number Diff line change @@ -640,10 +640,7 @@ func TestJobStore_FinishJob_defer(t *testing.T) {
640
640
641
641
defer1Func := func (ctx context.Context , jobErr error ) (job.IDs , error ) {
642
642
ids := make (job.IDs , 0 )
643
- jobStore , err := job .JobStoreFromContext (ctx )
644
- if err != nil {
645
- return ids , err
646
- }
643
+ jobStore := ss .JobStore
647
644
648
645
id , err := jobStore .EnqueueJob (job.Job {
649
646
Func : func (ctx context.Context ) error {
@@ -672,7 +669,6 @@ func TestJobStore_FinishJob_defer(t *testing.T) {
672
669
}
673
670
674
671
ctx := context .Background ()
675
- ctx = job .WithJobStore (ctx , ss .JobStore )
676
672
// execute deferred func, which is what scheduler would do
677
673
deferredIds , err := defer1Func (ctx , nil )
678
674
if err != nil {
You can’t perform that action at this time.
0 commit comments