mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 08:15:14 +00:00
Making the factory responsible to set the arguments and the queue
This commit is contained in:
parent
de22db6826
commit
8f542e5035
@ -182,13 +182,14 @@ class Resque_Job implements Resque_JobInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->jobFactory !== null) {
|
if ($this->jobFactory !== null) {
|
||||||
$this->instance = $this->jobFactory->create($this->payload['class']);
|
$this->instance = $this->jobFactory->create($this->payload['class'], $this->getArguments(), $this->queue);
|
||||||
} else {
|
return $this->instance;
|
||||||
$this->instance = new $this->payload['class'];
|
|
||||||
}
|
}
|
||||||
|
$this->instance = new $this->payload['class'];
|
||||||
$this->instance->job = $this;
|
$this->instance->job = $this;
|
||||||
$this->instance->args = $this->getArguments();
|
$this->instance->args = $this->getArguments();
|
||||||
$this->instance->queue = $this->queue;
|
$this->instance->queue = $this->queue;
|
||||||
|
|
||||||
return $this->instance;
|
return $this->instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ interface Resque_Job_FactoryInterface
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $className
|
* @param $className
|
||||||
|
* @param array $args
|
||||||
|
* @param $queue
|
||||||
* @return Resque_JobInterface
|
* @return Resque_JobInterface
|
||||||
*/
|
*/
|
||||||
public function create($className);
|
public function create($className, array $args, $queue);
|
||||||
}
|
}
|
||||||
|
@ -369,10 +369,8 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
'args' => null
|
'args' => null
|
||||||
);
|
);
|
||||||
$job = new Resque_Job('jobs', $payload);
|
$job = new Resque_Job('jobs', $payload);
|
||||||
$factory = $this->getMock('Resque_Job_FactoryInterface');
|
$factory = new Some_Stub_Factory();
|
||||||
$job->setJobFactory($factory);
|
$job->setJobFactory($factory);
|
||||||
$testJob = $this->getMock('Resque_JobInterface');
|
|
||||||
$factory->expects(self::once())->method('create')->will($this->returnValue($testJob));
|
|
||||||
$instance = $job->getInstance();
|
$instance = $job->getInstance();
|
||||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
||||||
}
|
}
|
||||||
@ -403,3 +401,18 @@ class Some_Job_Class implements Resque_JobInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Some_Stub_Factory implements Resque_Job_FactoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $className
|
||||||
|
* @param array $args
|
||||||
|
* @param $queue
|
||||||
|
* @return Resque_JobInterface
|
||||||
|
*/
|
||||||
|
public function create($className, array $args, $queue)
|
||||||
|
{
|
||||||
|
return new Some_Job_Class();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user