Fixed bug.

This commit is contained in:
李铭昕 2019-08-08 11:07:12 +08:00
parent e297726da6
commit 94746088d7
3 changed files with 13 additions and 5 deletions

View File

@ -52,14 +52,17 @@ class Message implements MessageInterface, Serializable
$this->job = $this->job->generate();
}
return serialize($this->job);
return serialize([$this->job, $this->attempts]);
}
public function unserialize($serialized)
{
$this->job = unserialize($serialized);
if ($this->job instanceof CodeDegenerateInterface) {
$this->job = $this->job->degenerate();
[$job, $attempts] = unserialize($serialized);
if ($job instanceof CodeDegenerateInterface) {
$job = $job->degenerate();
}
$this->job = $job;
$this->attempts = $attempts;
}
}

View File

@ -95,7 +95,7 @@ class RedisDriverTest extends TestCase
$driver->push(new DemoJob($id, $model));
$serialized = (string) Context::get('test.async-queue.lpush.value');
$this->assertSame(218, strlen($serialized));
$this->assertSame(236, strlen($serialized));
/** @var Message $class */
$class = $packer->unpack($serialized);
@ -105,6 +105,9 @@ class RedisDriverTest extends TestCase
$key = Context::get('test.async-queue.lpush.key');
$this->assertSame('test:waiting', $key);
$this->assertSame(true, $class->attempts());
$this->assertSame(false, $class->attempts());
}
protected function getContainer()

View File

@ -20,6 +20,8 @@ class DemoJob extends Job
public $model;
protected $maxAttempts = 1;
public function __construct($id, $model = null)
{
$this->id = $id;