Skip to content

Commit 938244f

Browse files
committed
Merge pull request barryvdh#13 from GrahamCampbell/tweaks
Tweaks
2 parents 92988e2 + 212a1ab commit 938244f

File tree

11 files changed

+193
-188
lines changed

11 files changed

+193
-188
lines changed

.gitattributes

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
# Auto detect text files and perform LF normalization
21
* text=auto
32

4-
# Custom for Visual Studio
5-
*.cs diff=csharp
6-
*.sln merge=union
7-
*.csproj merge=union
8-
*.vbproj merge=union
9-
*.fsproj merge=union
10-
*.dbproj merge=union
11-
12-
# Standard to msysgit
13-
*.doc diff=astextplain
14-
*.DOC diff=astextplain
15-
*.docx diff=astextplain
16-
*.DOCX diff=astextplain
17-
*.dot diff=astextplain
18-
*.DOT diff=astextplain
19-
*.pdf diff=astextplain
20-
*.PDF diff=astextplain
21-
*.rtf diff=astextplain
22-
*.RTF diff=astextplain
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/readme.md export-ignore

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
/vendor
2-
composer.phar
31
composer.lock
4-
.DS_Store
2+
vendor

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717
"psr-4": {
1818
"Barryvdh\\Queue\\": "src/"
1919
}
20-
},
21-
"minimum-stability": "dev"
22-
}
20+
}
21+
}

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Laravel 4 Async Queue Driver
2+
23
## Push a function/closure to the background.
34

45
Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly.
@@ -8,14 +9,15 @@ This package is more usable as an alternative for running incidental tasks in th
89
> **Note:** If you are coming from 0.1.0 (or dev-master), you will need to run the migrations, since the new versions uses a database to store the queue.
910
1011
### Install
12+
1113
Add the package to the require section of your composer.json and run `composer update`
1214

1315
"barryvdh/laravel-async-queue": "0.2.x"
1416

1517
Add the Service Provider to the providers array in config/app.php
1618

1719
'Barryvdh\Queue\AsyncServiceProvider',
18-
20+
1921
You need to run the migrations for this package
2022

2123
$ php artisan migrate --package="barryvdh/laravel-async-queue"
@@ -27,7 +29,7 @@ Or publish them, so they are copied to your regular migrations
2729
You should now be able to use the async driver in config/queue.php
2830

2931
'default' => 'async',
30-
32+
3133
'connections' => array(
3234
...
3335
'async' => array(

src/AsyncQueue.php

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
<?php namespace Barryvdh\Queue;
1+
<?php
22

3+
namespace Barryvdh\Queue;
4+
5+
use Barryvdh\Queue\Models\Job;
36
use Illuminate\Queue\Queue;
47
use Illuminate\Queue\QueueInterface;
58
use Symfony\Component\Process\Process;
6-
use Barryvdh\Queue\Models\Job;
7-
8-
class AsyncQueue extends Queue implements QueueInterface {
99

10+
class AsyncQueue extends Queue implements QueueInterface
11+
{
1012
/**
1113
* Push a new job onto the queue.
1214
*
13-
* @param string $job
14-
* @param mixed $data
15-
* @param string $queue
16-
* @return mixed
15+
* @param string $job
16+
* @param mixed $data
17+
* @param string|null $queue
18+
*
19+
* @return int
1720
*/
1821
public function push($job, $data = '', $queue = null)
1922
{
2023
$id = $this->storeJob($job, $data);
2124
$this->startProcess($id, 0);
25+
2226
return 0;
2327
}
2428

2529
/**
26-
* Store the job in the database
27-
*
28-
* @param string $job
29-
* @param mixed $data
30-
* @param integer $delay
31-
* @return integer The id of the job
30+
* Store the job in the database.
31+
*
32+
* Returns the id of the job.
33+
*
34+
* @param string $job
35+
* @param mixed $data
36+
* @param int $delay
37+
*
38+
* @return int
3239
*/
33-
public function storeJob($job, $data, $delay = 0){
34-
40+
public function storeJob($job, $data, $delay = 0)
41+
{
3542
$payload = $this->createPayload($job, $data);
3643

37-
$job = new Job;
44+
$job = new Job();
3845
$job->status = Job::STATUS_OPEN;
3946
$job->delay = $delay;
4047
$job->payload = $payload;
@@ -44,19 +51,21 @@ public function storeJob($job, $data, $delay = 0){
4451
}
4552

4653
/**
47-
* Make a Process for the Artisan command for the job id
54+
* Make a Process for the Artisan command for the job id.
55+
*
56+
* @param int $jobId
4857
*
49-
* @param integer $jobId
58+
* @return void
5059
*/
5160
public function startProcess($jobId)
5261
{
5362
$environment = $this->container->environment();
5463
$cwd = $this->container['path.base'];
5564
$string = 'php artisan queue:async %d --env=%s ';
56-
if (defined('PHP_WINDOWS_VERSION_BUILD')){
57-
$string = 'start /B ' . $string . ' > NUL';
65+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
66+
$string = 'start /B '.$string.' > NUL';
5867
} else {
59-
$string = 'nohup ' . $string . ' > /dev/null 2>&1 &';
68+
$string = 'nohup '.$string.' > /dev/null 2>&1 &';
6069
}
6170

6271
$command = sprintf($string, $jobId, $environment);
@@ -67,39 +76,45 @@ public function startProcess($jobId)
6776
/**
6877
* Push a new job onto the queue after a delay.
6978
*
70-
* @param \DateTime|int $delay
71-
* @param string $job
72-
* @param mixed $data
73-
* @param string $queue
74-
* @return mixed
79+
* @param \DateTime|int $delay
80+
* @param string $job
81+
* @param mixed $data
82+
* @param string|null $queue
83+
*
84+
* @return int
7585
*/
7686
public function later($delay, $job, $data = '', $queue = null)
7787
{
7888
$delay = $this->getSeconds($delay);
7989
$id = $this->storeJob($job, $data, $delay);
8090
$this->startProcess($id);
91+
8192
return 0;
8293
}
8394

8495
/**
8596
* Pop the next job off of the queue.
8697
*
87-
* @param string $queue
88-
* @return \Illuminate\Queue\Jobs\Job|null
98+
* @param string|null $queue
99+
*
100+
* @return void
89101
*/
90-
public function pop($queue = null) {}
91-
102+
public function pop($queue = null)
103+
{
104+
// do nothing
105+
}
92106

93107
/**
94108
* Push a raw payload onto the queue.
95109
*
96-
* @param string $payload
97-
* @param string $queue
98-
* @param array $options
99-
* @return mixed
110+
* @param string $payload
111+
* @param string|null $queue
112+
* @param array $options
113+
*
114+
* @return void
100115
*/
101116
public function pushRaw($payload, $queue = null, array $options = array())
102117
{
103-
//
118+
// do nothing
104119
}
105120
}

src/AsyncServiceProvider.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<?php namespace Barryvdh\Queue;
1+
<?php
2+
3+
namespace Barryvdh\Queue;
24

3-
use Illuminate\Support\ServiceProvider;
45
use Barryvdh\Queue\Connectors\AsyncConnector;
56
use Barryvdh\Queue\Console\AsyncCommand;
7+
use Illuminate\Support\ServiceProvider;
68

7-
class AsyncServiceProvider extends ServiceProvider {
8-
9+
class AsyncServiceProvider extends ServiceProvider
10+
{
911
/**
1012
* Indicates if loading of the provider is deferred.
1113
*
@@ -14,34 +16,36 @@ class AsyncServiceProvider extends ServiceProvider {
1416
protected $defer = false;
1517

1618
/**
17-
* Register the service provider.
19+
* Add the connector to the queue drivers.
1820
*
1921
* @return void
2022
*/
21-
public function register()
23+
public function boot()
2224
{
23-
$this->registerAsyncCommand();
25+
$manager = $this->app['queue'];
26+
$this->registerAsyncConnector($manager);
2427
}
2528

2629
/**
27-
* Add the connector to the queue drivers
30+
* Register the service provider.
31+
*
32+
* @return void
2833
*/
29-
public function boot(){
30-
$manager = $this->app['queue'];
31-
$this->registerAsyncConnector($manager);
34+
public function register()
35+
{
36+
$this->registerAsyncCommand($this->app);
3237
}
3338

3439
/**
3540
* Register the queue listener console command.
3641
*
42+
* @param \Illuminate\Foundation\Application $app
43+
*
3744
* @return void
3845
*/
39-
protected function registerAsyncCommand()
46+
protected function registerAsyncCommand($app)
4047
{
41-
$app = $this->app;
42-
43-
$app['command.queue.async'] = $app->share(function($app)
44-
{
48+
$app['command.queue.async'] = $app->share(function ($app) {
4549
return new AsyncCommand();
4650
});
4751

@@ -51,14 +55,14 @@ protected function registerAsyncCommand()
5155
/**
5256
* Register the Async queue connector.
5357
*
54-
* @param \Illuminate\Queue\QueueManager $manager
58+
* @param \Illuminate\Queue\QueueManager $manager
59+
*
5560
* @return void
5661
*/
5762
protected function registerAsyncConnector($manager)
5863
{
59-
$manager->addConnector('async', function()
60-
{
61-
return new AsyncConnector;
64+
$manager->addConnector('async', function () {
65+
return new AsyncConnector();
6266
});
6367
}
6468

@@ -71,5 +75,4 @@ public function provides()
7175
{
7276
return array('command.queue.async');
7377
}
74-
7578
}

src/Connectors/AsyncConnector.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
<?php namespace Barryvdh\Queue\Connectors;
1+
<?php
22

3-
use Illuminate\Queue\Connectors\ConnectorInterface;
4-
use Barryvdh\Queue\AsyncQueue;
3+
namespace Barryvdh\Queue\Connectors;
54

6-
class AsyncConnector implements ConnectorInterface {
5+
use Barryvdh\Queue\AsyncQueue;
6+
use Illuminate\Queue\Connectors\ConnectorInterface;
77

8+
class AsyncConnector implements ConnectorInterface
9+
{
810
/**
911
* Establish a queue connection.
1012
*
11-
* @param array $config
13+
* @param array $config
14+
*
1215
* @return \Illuminate\Queue\QueueInterface
1316
*/
1417
public function connect(array $config)
1518
{
16-
return new AsyncQueue;
19+
return new AsyncQueue();
1720
}
18-
19-
}
21+
}

0 commit comments

Comments
 (0)