diff --git a/README.md b/README.md index 6fdf150..0767465 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A persistent and flexible background jobs library for go. [![GoDoc](https://godoc.org/github.com/albrow/jobs?status.svg)](https://godoc.org/github.com/albrow/jobs) -Version: 0.1.0 +Version: 0.1.1 Jobs is powered by redis and supports the following features: @@ -163,15 +163,15 @@ grabbed from the database that did not yet finish will be requeued and picked up There are two known ways that a job may be executed more than once: -1) If there is a power failure or hard reset while a worker is in the middle of executing a job, the job may be - stuck in a half-executed state. Since there is no way to know how much of the job was successfully completed, - the job will be requeued and picked up by a different pool, where it may be partially or fully executed - more than once. -2) If a pool becomes disconnected, it will be considered stale and its jobs will be requeued and reclaimed - by a different pool. However, if the stale pool is able to partly or fully execute jobs without a reliable - internet connection, any jobs belonging to the stale pool might be executed more than once. You can increase - the [StaleTimeout](https://godoc.org/github.com/albrow/jobs#PoolConfig) parameter for a pool to make this - scenario less likely. +1. If there is a power failure or hard reset while a worker is in the middle of executing a job, the job may be + stuck in a half-executed state. Since there is no way to know how much of the job was successfully completed, + the job will be requeued and picked up by a different pool, where it may be partially or fully executed + more than once. +2. If a pool becomes disconnected, it will be considered stale and its jobs will be requeued and reclaimed + by a different pool. However, if the stale pool is able to partly or fully execute jobs without a reliable + internet connection, any jobs belonging to the stale pool might be executed more than once. You can increase + the [StaleTimeout](https://godoc.org/github.com/albrow/jobs#PoolConfig) parameter for a pool to make this + scenario less likely. License diff --git a/doc.go b/doc.go index 321372f..3bdb271 100644 --- a/doc.go +++ b/doc.go @@ -4,7 +4,7 @@ // package jobs is a persistent and flexible background jobs library. // -// Version: 0.1.0 +// Version: 0.1.1 // // Jobs is powered by redis and supports the following features: // diff --git a/job.go b/job.go index 6d41a6c..2885ea3 100644 --- a/job.go +++ b/job.go @@ -163,10 +163,11 @@ func (j *Job) Reschedule(time time.Time) error { unixNanoTime := time.UTC().UnixNano() t.command("HSET", redis.Args{j.key(), "time", unixNanoTime}, nil) t.setStatus(j, StatusQueued) + j.time = unixNanoTime + t.addJobToTimeIndex(j) if err := t.exec(); err != nil { return err } - j.time = unixNanoTime j.status = StatusQueued return nil } diff --git a/job_test.go b/job_test.go index 7290a5a..070a954 100644 --- a/job_test.go +++ b/job_test.go @@ -153,6 +153,7 @@ func TestJobReschedule(t *testing.T) { t.Errorf("Unexpected error in job.Reschedule: %s", err.Error()) } expectJobFieldEquals(t, job, "time", unixNanoTime, int64Converter) + expectJobInTimeIndex(t, job) // Run through a set of possible state paths and make sure the result is // always what we expect