Skip to content

Commit

Permalink
fix: Read open dir mark correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jun 28, 2022
1 parent 91b16de commit aee60fe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/state/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ func (js *JobStore) EnqueueJob(newJob job.Job) (job.ID, error) {

newJobID := job.ID(fmt.Sprintf("%d", atomic.AddUint64(&js.lastJobId, 1)))

err = txn.Insert(js.tableName, &ScheduledJob{
sJob := &ScheduledJob{
ID: newJobID,
Job: newJob,
IsDirOpen: isDirOpen(txn, newJob.Dir),
State: StateQueued,
})
}

err = txn.Insert(js.tableName, sJob)
if err != nil {
return "", err
}

js.logger.Printf("JOBS: Enqueueing new job %q: %q for %q", newJobID, newJob.Type, newJob.Dir)
js.logger.Printf("JOBS: Enqueueing new job %q: %q for %q (IsDirOpen: %t)",
sJob.ID, sJob.Type, sJob.Dir, sJob.IsDirOpen)

txn.Commit()

Expand Down Expand Up @@ -204,7 +207,7 @@ func (js *JobStore) AwaitNextJob(ctx context.Context, priority job.JobPriority)
defer js.nextJobLowPrioMu.Unlock()
default:
// This should never happen
return "", job.Job{}, fmt.Errorf("unexpected priority: %#v", priority)
panic(fmt.Sprintf("unexpected priority: %#v", priority))
}

return js.awaitNextJob(ctx, priority)
Expand Down Expand Up @@ -245,12 +248,13 @@ func (js *JobStore) awaitNextJob(ctx context.Context, priority job.JobPriority)
return "", job.Job{}, err
}

js.logger.Printf("JOBS: Dispatching next job %q: %q for %q", sJob.ID, sJob.Type, sJob.Dir)
js.logger.Printf("JOBS: Dispatching next job %q (scheduler prio: %d, job prio: %d, isDirOpen: %t): %q for %q",
sJob.ID, priority, sJob.Priority, sJob.IsDirOpen, sJob.Type, sJob.Dir)
return sJob.ID, sJob.Job, nil
}

func isDirOpen(txn *memdb.Txn, dirHandle document.DirHandle) bool {
docObj, err := txn.First(documentsTableName, "id", dirHandle)
docObj, err := txn.First(documentsTableName, "dir", dirHandle)
if err != nil {
return false
}
Expand Down

0 comments on commit aee60fe

Please sign in to comment.