コード例 #1
0
 function it_cannot_be_executed_unless_the_job_is_finished(Redis $tx)
 {
     $id = '123';
     $tx->watch("job:{$id}:txid")->shouldBeCalled();
     $tx->zscore('queue:my-queue:failed', $id)->willReturn(null);
     $tx->zscore('queue:my-queue:succeeded', $id)->willReturn(null);
     $this->shouldThrow('InvalidArgumentException')->duringExecute();
 }
コード例 #2
0
 function it_can_be_executed(Redis $tx)
 {
     $id = '123';
     $now = '2015-04-18T13:16:16.263400+0000';
     $tx->watch("job:{$id}:txid")->shouldBeCalled();
     $tx->zscore("queue:my-queue:failed", $id)->willReturn(1);
     $tx->multi()->shouldBeCalled();
     $tx->zrem('queue:my-queue:failed', $id)->shouldBeCalled()->willReturn(0);
     $tx->lpush('queue:my-queue:pending', $id)->shouldBeCalled();
     $tx->rpush("job:{$id}:history", Encoder::encode([$now, 'queued']))->shouldBeCalled();
     $tx->incr("job:{$id}:tries")->shouldBeCalled();
     $tx->incr("job:{$id}:txid")->shouldBeCalled();
     $this->execute();
 }
コード例 #3
0
ファイル: FailTransactionSpec.php プロジェクト: metro-q/metro
 function it_can_be_executed(Redis $tx)
 {
     $id = '123';
     $nowIso = '2015-04-18T13:16:16.263400+0000';
     $nowTs = 1429362976.2634;
     $tx->watch("job:{$id}:txid")->shouldBeCalled();
     $tx->zscore('queue:my-queue:succeeded', $id)->willReturn(null);
     $tx->multi()->shouldBeCalled();
     $tx->lrem('queue:my-queue:processing', 1, $id)->shouldBeCalled()->willReturn(1);
     $tx->zadd('queue:my-queue:failed', $nowTs, $id)->shouldBeCalled();
     $tx->rpush("job:{$id}:history", Encoder::encode([$nowIso, 'failed']))->shouldBeCalled();
     $tx->incr("job:{$id}:txid")->shouldBeCalled();
     $this->execute();
 }
コード例 #4
0
ファイル: RedisQueueSpec.php プロジェクト: metro-q/metro
 function it_handles_queued_garbage_properly(Redis $redis)
 {
     $redis->rpoplpush("queue:my-queue:pending", "queue:my-queue:processing")->willReturn('id');
     $redis->get("job:id")->willReturn('not json');
     $this->pop(['my-queue'])->shouldReturn(null);
 }
コード例 #5
0
 function it_can_be_executed(Redis $redis, Worker $worker)
 {
     $workerId = '1234@localhost';
     $worker->identify()->willReturn($workerId);
     $nowIso = '2015-04-18T13:16:16.263400+0000';
     $redis->multi()->shouldBeCalled();
     $redis->sadd("workers", "{$workerId}")->shouldBeCalled();
     $redis->del("worker:{$workerId}:queues")->shouldBeCalled();
     $redis->zadd("worker:{$workerId}:queues", 0, 'my-queue')->shouldBeCalled();
     $redis->zadd("worker:{$workerId}:queues", 1, 'your-queue')->shouldBeCalled();
     $redis->hsetnx("worker:{$workerId}:status", "first-seen", $nowIso)->shouldBeCalled();
     $redis->hset("worker:{$workerId}:status", "last-seen", $nowIso)->shouldBeCalled();
     $redis->expire("worker:{$workerId}:queues", 7 * 24 * 3600)->shouldBeCalled();
     $redis->expire("worker:{$workerId}:status", 7 * 24 * 3600)->shouldBeCalled();
     $redis->exec()->shouldBeCalled();
     $this->execute();
 }
コード例 #6
0
ファイル: RedisMonitorSpec.php プロジェクト: metro-q/metro
 function it_knows_a_workers_status(Redis $redis)
 {
     $redis->zrange("worker:123:queues", 0, -1)->willReturn(['q1', 'q2']);
     $redis->hget("worker:123:status", "first-seen")->willReturn('2015-05-25T09:43:12.681+0000');
     $redis->hget("worker:123:status", "last-seen")->willReturn('2015-05-25T10:59:28.710+0000');
     $this->getWorkerStatus('123')->shouldReturn(['id' => '123', 'firstHeardFrom' => '2015-05-25T09:43:12.681+0000', 'lastHeardFrom' => '2015-05-25T10:59:28.710+0000', 'queues' => ['q1', 'q2']]);
 }
コード例 #7
0
 function it_can_be_executed(Redis $tx)
 {
     $id = '123';
     $nowTs = 1429362976.2634;
     $nowIso = '2015-04-18T13:16:16.263400+0000';
     $expectedJob = $this->createJob();
     $tx->watch("job:{$id}:txid")->shouldBeCalled();
     $tx->multi()->shouldBeCalled();
     $tx->sadd('queues', 'my-queue')->shouldBeCalled();
     $tx->zadd('jobs', $nowTs, $id)->shouldBeCalled();
     $tx->zrem('queue:my-queue:failed', $id)->shouldBeCalled()->willReturn(0);
     $tx->lpush('queue:my-queue:pending', $id)->shouldBeCalled();
     $tx->setnx("job:{$id}", Encoder::encode($expectedJob))->shouldBeCalled();
     $tx->incr("job:{$id}:tries")->shouldBeCalled();
     $tx->rpush("job:{$id}:history", Encoder::encode([$nowIso, 'queued']))->shouldBeCalled();
     $tx->incr("job:{$id}:txid")->shouldBeCalled();
     $this->execute();
 }