Skip to content

Commit 59eea8a

Browse files
committed
scheduler/state: avoid passing JobStore via ctx
This (hack) is no longer necessary since all indexing logic is now self-contained within one package.
1 parent b6fdc5d commit 59eea8a

File tree

4 files changed

+3
-27
lines changed

4 files changed

+3
-27
lines changed

internal/job/job_store.go

-15
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@ package job
22

33
import (
44
"context"
5-
"fmt"
65
)
76

87
type JobStore interface {
98
EnqueueJob(newJob Job) (ID, error)
109
WaitForJobs(ctx context.Context, ids ...ID) error
1110
}
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-
}

internal/scheduler/scheduler.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ func (s *Scheduler) eval(ctx context.Context) {
6969

7070
deferredJobIds := make(job.IDs, 0)
7171
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)
7473
if err != nil {
7574
s.logger.Printf("deferred job failed: %s", err)
7675
}

internal/scheduler/scheduler_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,7 @@ func TestScheduler_defer(t *testing.T) {
262262
Type: "test-type",
263263
Defer: func(ctx context.Context, jobErr error) (job.IDs, error) {
264264
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
270266

271267
id1, err := je.EnqueueJob(job.Job{
272268
Dir: document.DirHandleFromPath(dirPath),

internal/state/jobs_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,7 @@ func TestJobStore_FinishJob_defer(t *testing.T) {
640640

641641
defer1Func := func(ctx context.Context, jobErr error) (job.IDs, error) {
642642
ids := make(job.IDs, 0)
643-
jobStore, err := job.JobStoreFromContext(ctx)
644-
if err != nil {
645-
return ids, err
646-
}
643+
jobStore := ss.JobStore
647644

648645
id, err := jobStore.EnqueueJob(job.Job{
649646
Func: func(ctx context.Context) error {
@@ -672,7 +669,6 @@ func TestJobStore_FinishJob_defer(t *testing.T) {
672669
}
673670

674671
ctx := context.Background()
675-
ctx = job.WithJobStore(ctx, ss.JobStore)
676672
// execute deferred func, which is what scheduler would do
677673
deferredIds, err := defer1Func(ctx, nil)
678674
if err != nil {

0 commit comments

Comments
 (0)