Skip to content

Commit

Permalink
Adding job options to . Thanks @aleksraiden. Accounting for floating …
Browse files Browse the repository at this point in the history
…point in exception messages.
  • Loading branch information
mariano committed Feb 16, 2017
1 parent 7242127 commit 33dcf6f
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 25 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,16 @@
All Notable changes will be documented in this file. This project adheres to
[Semantic Versioning](http://semver.org/).

## [2.0.3] - 2017-02-16

### Added
- Added `nohang` option to `getJob()`. Thanks @kaecyra
- Added ability to specify job options when scheduling a job
via `schedule()`. Thanks @aleksraiden

### Changed
- Removed `predis/predis` from list of suggested packages to install

## [2.0.2] - 2016-05-10

### Fixed
Expand Down Expand Up @@ -153,6 +163,7 @@ parameters were specified, an `InvalidCommandArgumentException` was thrown.
- Added support for Predis connections, and allowing adding new connection
methods via `ConnectionInterface`.

[2.0.3]: https://github.com/mariano/disque-php/releases/tag/2.0.3
[2.0.2]: https://github.com/mariano/disque-php/releases/tag/2.0.2
[2.0.1]: https://github.com/mariano/disque-php/releases/tag/2.0.1
[2.0-alpha]: https://github.com/mariano/disque-php/releases/tag/2.0-alpha
Expand Down
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -107,11 +107,7 @@ libraries for the inspiration.
[The PHP League](https://thephpleague.com) for an awesome `README.md` skeleton,
and tips about packaging PHP components.

A special acknolewdgment and appreciation for our amazing contributors:

* [Revisor](https://github.com/Revisor) for his incredible work on this library.

* [mvrhov](https://github.com/mvrhov) for helping us support Disque RC1 node ID new format.
A special acknolewdgment and appreciation for our []amazing contributors](https://github.com/mariano/disque-php/graphs/contributors)!

## License

Expand Down
3 changes: 0 additions & 3 deletions composer.json
Expand Up @@ -24,9 +24,6 @@
"require": {
"php": ">=5.5"
},
"suggest": {
"predis/predis": "Use Predis to handle the connection with Disque instead of the built in client"
},
"require-dev": {
"phpunit/phpunit": "~4.6",
"scrutinizer/ocular": "~1.1",
Expand Down
8 changes: 4 additions & 4 deletions src/Queue/Queue.php
Expand Up @@ -72,10 +72,11 @@ public function setMarshaler(MarshalerInterface $marshaler)
*
* @param JobInterface $job Job
* @param DateTime $when Date & time on when job should be ready for processing
* @param array $options ADDJOB options sent to the client
* @return JobInterface Job pushed
* @throws InvalidArgumentException
*/
public function schedule(JobInterface $job, DateTime $when)
public function schedule(JobInterface $job, DateTime $when, array $options = [])
{
if (!isset($this->timeZone)) {
$this->timeZone = new DateTimeZone(self::DEFAULT_JOB_TIMEZONE);
Expand All @@ -88,9 +89,8 @@ public function schedule(JobInterface $job, DateTime $when)
throw new InvalidArgumentException('Specified schedule time has passed');
}

return $this->push($job, [
'delay' => ($date->getTimestamp() - $now->getTimestamp())
]);
$options['delay'] = ($date->getTimestamp() - $now->getTimestamp());
return $this->push($job, $options);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Command/AddJobTest.php
Expand Up @@ -116,7 +116,7 @@ public function testBuildInvalidOptionTimeoutNonNumeric()

public function testBuildInvalidOptionTimeoutNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"timeout":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"timeout":3.14\d*}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['timeout' => 3.14]]);
}
Expand All @@ -130,7 +130,7 @@ public function testBuildInvalidOptionReplicateNonNumeric()

public function testBuildInvalidOptionReplicateNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"replicate":3.14,"timeout":0}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"replicate":3.14\d*,"timeout":0}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['replicate' => 3.14]]);
}
Expand All @@ -144,7 +144,7 @@ public function testBuildInvalidOptionDelayNonNumeric()

public function testBuildInvalidOptionDelayNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"delay":3.14,"timeout":0}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"delay":3.14\d*,"timeout":0}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['delay' => 3.14]]);
}
Expand All @@ -158,7 +158,7 @@ public function testBuildInvalidOptionRetryNonNumeric()

public function testBuildInvalidOptionRetryNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"retry":3.14,"timeout":0}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"retry":3.14\d*,"timeout":0}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['retry' => 3.14]]);
}
Expand All @@ -172,7 +172,7 @@ public function testBuildInvalidOptionTtlNonNumeric()

public function testBuildInvalidOptionTtlNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"ttl":3.14,"timeout":0}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"ttl":3.14\d*,"timeout":0}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['ttl' => 3.14]]);
}
Expand All @@ -186,7 +186,7 @@ public function testBuildInvalidOptionMaxlenNonNumeric()

public function testBuildInvalidOptionMaxlenNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\AddJob: {"maxlen":3.14,"timeout":0}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\AddJob: {"maxlen":3.14\d*,"timeout":0}$/');
$c = new AddJob();
$c->setArguments(['q', 'j', ['maxlen' => 3.14]]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Command/GetJobTest.php
Expand Up @@ -77,7 +77,7 @@ public function testBuildInvalidOptionCountNonNumeric()

public function testBuildInvalidOptionCountNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\GetJob: {"count":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\GetJob: {"count":3.14\d*}$/');
$c = new GetJob();
$c->setArguments(['q1', 'q2', ['count' => 3.14]]);
}
Expand All @@ -91,7 +91,7 @@ public function testBuildInvalidOptionTimeoutNonNumeric()

public function testBuildInvalidOptionTimeoutNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\GetJob: {"timeout":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\GetJob: {"timeout":3.14\d*}$/');
$c = new GetJob();
$c->setArguments(['q1', 'q2', ['timeout' => 3.14]]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/JScanTest.php
Expand Up @@ -88,7 +88,7 @@ public function testBuildInvalidOptionCountNonNumeric()

public function testBuildInvalidOptionCountNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\JScan: {"count":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\JScan: {"count":3.14\d*}$/');
$c = new JScan();
$c->setArguments([0, ['count' => 3.14]]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/QPeekTest.php
Expand Up @@ -80,7 +80,7 @@ public function testBuildInvalidArgumentsNonNumeric()

public function testBuildInvalidArgumentsNonInt()
{
$this->setExpectedException(InvalidCommandArgumentException::class, 'Invalid command arguments. Arguments for command Disque\\Command\\QPeek: ["test",3.14]');
$this->setExpectedExceptionRegExp(InvalidCommandArgumentException::class, '/^Invalid command arguments. Arguments for command Disque\\\\Command\\\\QPeek: \["test",3.14\d*\]$/');
$c = new QPeek();
$c->setArguments(['test', 3.14]);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/QScanTest.php
Expand Up @@ -88,7 +88,7 @@ public function testBuildInvalidOptionMinlenNonNumeric()

public function testBuildInvalidOptionMinlenNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\QScan: {"minlen":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\QScan: {"minlen":3.14\d*}$/');
$c = new QScan();
$c->setArguments([0, ['minlen' => 3.14]]);
}
Expand All @@ -102,7 +102,7 @@ public function testBuildInvalidOptionMaxlenNonNumeric()

public function testBuildInvalidOptionMaxlenNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\QScan: {"maxlen":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\QScan: {"maxlen":3.14\d*}$/');
$c = new QScan();
$c->setArguments([0, ['maxlen' => 3.14]]);
}
Expand All @@ -116,7 +116,7 @@ public function testBuildInvalidOptionImportrateNonNumeric()

public function testBuildInvalidOptionImportrateNonInt()
{
$this->setExpectedException(InvalidOptionException::class, 'Invalid command options. Options for command Disque\\Command\\QScan: {"importrate":3.14}');
$this->setExpectedExceptionRegExp(InvalidOptionException::class, '/^Invalid command options. Options for command Disque\\\\Command\\\\QScan: {"importrate":3.14\d*}$/');
$c = new QScan();
$c->setArguments([0, ['importrate' => 3.14]]);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Queue/QueueTest.php
Expand Up @@ -517,6 +517,27 @@ public function testScheduleWayInTheFuture()
$this->assertSame($job, $result);
}

public function testScheduleWithOptions()
{
$delay = 10;

$job = new Job();
$queue = m::mock(Queue::class.'[push]', [m::mock(Client::class), 'queue'])
->shouldReceive('push')
->with($job,
anyOf(
['retry' => 1000, 'delay' => $delay],
['retry' => 1000, 'delay' => $delay - 1]
))
->andReturn($job)
->once()
->mock();

$when = new DateTime('+' . $delay . ' seconds', new DateTimeZone(Queue::DEFAULT_JOB_TIMEZONE));
$result = $queue->schedule($job, $when, ['retry' => 1000]);
$this->assertSame($job, $result);
}

public function testProcessingConnected()
{
$job = m::mock(JobInterface::class)
Expand Down

0 comments on commit 33dcf6f

Please sign in to comment.