Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/vendor/
/protocol.txt
/.php_cs.cache
/.idea/
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
}
},
"require": {
"amphp/amp": "^2",
"amphp/socket": "^1.0",
"amphp/amp": "^3",
"amphp/socket": "^2",
"amphp/uri": "^0.1",
"symfony/yaml": "^3.3|^4|^5"
},
"require-dev": {
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6",
"amphp/phpunit-util": "^v3.0.0",
"phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^2.3"
},
"config": {
"platform": {
"php": "7.1.0"
"php": "8.1.0"
}
}
}
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");
// can connect to the server with an additional tube query parameter.
// $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300?tube=foobar");

$systemStats = yield $beanstalk->getSystemStats();
$systemStats = $beanstalk->getSystemStats()->await();

$readyJobs = $systemStats->currentJobsReady;
```
Expand Down
22 changes: 11 additions & 11 deletions docs/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ permalink: /jobs
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

// This step not required if you included a tube query parameter when creating the client
$beanstalk->use('foobar');
$beanstalk->use('foobar')->await();

$payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image"
"path" => "/path/to/image.png"
]);

$jobId = yield $beanstalk->put($payload);
$jobId = $beanstalk->put($payload)->await();
```

## Pulling Jobs off a Queue

```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$beanstalk->watch('foobar');
$beanstalk->watch('foobar')->await();

while([$jobId, $jobData] = yield $beanstalk->reserve()) {
while([$jobId, $jobData] = $beanstalk->reserve()->await()) {
// Work the job using $jobData
// Once you're finished, delete the job
yield $beanstalk->delete($jobId);
$beanstalk->delete($jobId)->await();

// If there was an error, you can bury the job for inspection later
yield $beanstalk->bury($jobId);
$beanstalk->bury($jobId)->await();

// Of you can release the job, to be picked up by a new worker
yield $beanstalk->release($jobId);
$beanstalk->release($jobId)->await();
}
```

Expand All @@ -48,12 +48,12 @@ while([$jobId, $jobData] = yield $beanstalk->reserve()) {
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$beanstalk->watch('foobar');
$beanstalk->watch('foobar')->await();

while([$jobId, $jobData] = yield $beanstalk->reserve()) {
while([$jobId, $jobData] = $beanstalk->reserve()->await()) {
// Work the job
// If you still need time to work the job, you can utilize the touch command
yield $beantstalk->touch($jobId);
$beantstalk->touch($jobId)->await();
}
```

Expand All @@ -62,6 +62,6 @@ while([$jobId, $jobData] = yield $beanstalk->reserve()) {
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$jobStats = yield $beanstalk->getJobStats($jobId = 42);
$jobStats = $beanstalk->getJobStats($jobId = 42)->await();
$jobStats->state; // ready
```
2 changes: 1 addition & 1 deletion docs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To see what stats are available for the system, checkout the [System](classes/sy
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$stats = yield $beanstalk->getSystemStats();
$stats = $beanstalk->getSystemStats()->await();
```

## Close the Connection
Expand Down
32 changes: 16 additions & 16 deletions docs/tubes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ By default Beanstalk will use the default tube for reserving and storing new job
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

// This will store the job on the "default" tube.
$jobId = yield $beanstalk->put($payload = json_encode([
$jobId = $beanstalk->put($payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image"
"path" => "/path/to/image.png"
]););
]))->await();

$beanstalk->use('foobar');
$beanstalk->use('foobar')->await();

// This will store the job on the "foobar" tube.
$jobId = yield $beanstalk->put($payload = json_encode([
$jobId = $beanstalk->put($payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image"
"path" => "/path/to/image.png"
]));
]))->await();
```

## Pausing a Tube
Expand All @@ -37,7 +37,7 @@ If you need to pause a tube, preventing any new jobs from being reserved, you ca
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->pause($tube = 'foobar');
$beanstalk->pause($tube = 'foobar')->await();
```

## Watching and Ignoring Tubes
Expand All @@ -47,9 +47,9 @@ By default when you reserve a job you'll either pull from the `default` tube, or
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->watch($tube = 'foobar');
yield $beanstalk->watch($tube = 'barbaz');
yield $beanstalk->ignore($tube = 'default');
$beanstalk->watch($tube = 'foobar')->await();
$beanstalk->watch($tube = 'barbaz')->await();
$beanstalk->ignore($tube = 'default')->await();
// Watchlist will contain "foobar" and "barbaz"
```

Expand All @@ -60,11 +60,11 @@ To find out which tubes your connection is currently watching.
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->watch($tube = 'foobar');
yield $beanstalk->watch($tube = 'barbaz');
yield $beanstalk->ignore($tube = 'default');
$beanstalk->watch($tube = 'foobar')->await();
$beanstalk->watch($tube = 'barbaz')->await();
$beanstalk->ignore($tube = 'default')->await();

$watchlist = $beanstalk->listWatchedTubes();
$watchlist = $beanstalk->listWatchedTubes()->await();
```

## Get a List of All Existing Tubes
Expand All @@ -74,7 +74,7 @@ If you need to see a list of all the tubes that exist on the server.
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$tubes = yield $beanstalk->listTubes();
$tubes = $beanstalk->listTubes()->await();
```

## Get the Tube Being Used
Expand All @@ -84,7 +84,7 @@ To determine which tube your client is currently using.
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$tube = yield $beanstalk->getUsedTube();
$tube = $beanstalk->getUsedTube()->await();
```

## Get Tube Stats
Expand All @@ -94,5 +94,5 @@ To see what stats are available for a tube, checkout the [Tube](classes/tube) cl
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$stats = yield $beanstalk->getTubeStats($tube = 'default');
$stats = $beanstalk->getTubeStats($tube = 'default')->await();
```
10 changes: 5 additions & 5 deletions examples/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;
use Revolt\EventLoop;

Loop::run(function () {
EventLoop::queue(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->watch('foobar');
$beanstalk->watch('foobar')->await();

while (list($jobId, $payload) = yield $beanstalk->reserve()) {
while (list($jobId, $payload) = $beanstalk->reserve()->await()) {
echo "Job id: $jobId\n";
echo "Payload: $payload\n";

$beanstalk->delete($jobId);
$beanstalk->delete($jobId)->await();
}
});
7 changes: 3 additions & 4 deletions examples/producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;

Loop::run(function () {
Revolt\EventLoop::queue(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->use('foobar');
$beanstalk->use('foobar')->await();

$payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image",
"path" => "/path/to/image.png"
]);

$jobId = yield $beanstalk->put($payload);
$jobId = $beanstalk->put($payload)->await();

echo "Inserted job id: $jobId\n";

Expand Down
6 changes: 3 additions & 3 deletions examples/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Amp\Beanstalk\BeanstalkClient;
use Amp\Beanstalk\Stats\System;
use Amp\Loop;

Loop::run(function () {

Revolt\EventLoop::queue(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");

/**
* @var System $systemStats
*/
$systemStats = yield $beanstalk->getSystemStats();
$systemStats = $beanstalk->getSystemStats()->await();
echo "Active connections: {$systemStats->currentConnections}\n";
echo "Jobs ready: {$systemStats->currentJobsReady}\n";

Expand Down
23 changes: 11 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
Loading