M queue.sql => queue.sql +13 -3
@@ 12,7 12,17 @@ CREATE TABLE IF NOT EXISTS queue (
CREATE INDEX IF NOT EXISTS expires_idx ON queue(expires);
-CREATE TRIGGER IF NOT EXISTS requeue_expired BEFORE UPDATE ON queue BEGIN
- UPDATE queue SET expires = 0, tries = tries + 1 WHERE expires > 0 AND expires < (SELECT strftime('%s', 'now'));
+CREATE TRIGGER IF NOT EXISTS requeue_expired_update BEFORE UPDATE ON queue BEGIN
+ UPDATE queue SET expires = 0, tries = tries + 1 WHERE expires > 0 AND expires < (SELECT (julianday('now') - 2440587.5)*86400.0);
UPDATE queue SET expires = -1 WHERE max_tries > 0 AND tries = max_tries;
-END
+END;
+
+CREATE TRIGGER IF NOT EXISTS requeue_expired_insert AFTER INSERT ON queue BEGIN
+ UPDATE queue SET expires = 0, tries = tries + 1 WHERE expires > 0 AND expires < (SELECT (julianday('now') - 2440587.5)*86400.0);
+ UPDATE queue SET expires = -1 WHERE max_tries > 0 AND tries = max_tries;
+END;
+
+CREATE TRIGGER IF NOT EXISTS requeue_expired_delete AFTER DELETE ON queue BEGIN
+ UPDATE queue SET expires = 0, tries = tries + 1 WHERE expires > 0 AND expires < (SELECT (julianday('now') - 2440587.5)*86400.0);
+ UPDATE queue SET expires = -1 WHERE max_tries > 0 AND tries = max_tries;
+END;
M queue_test.go => queue_test.go +0 -2
@@ 122,8 122,6 @@ func TestAutoRequeue(t *testing.T) {
if _, _, err := Dequeue(db, "test", Timeout(0)); err != nil {
assert.NoError(t, err)
}
- // must sleep at least one second due to unix resolution
- time.Sleep(1 * time.Second)
nAfter, err := Length(db, "test")
require.NoError(t, err)