Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b973f38

Browse files
committed
Merge branch '4.0'
2 parents b4020ae + 6305fb2 commit b973f38

7 files changed

Lines changed: 61 additions & 18 deletions

File tree

src/Illuminate/Foundation/changes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
{"message": "Moved newPivot method into model for custom Pivot model instances.", "backport": null},
7474
{"message": "Added 'shared' method to View to pull a single shared item out.", "backport": null},
7575
{"message": "Added assertHasOldInput test assertion.", "backport": null},
76-
{"message": "Added slick new 'sometimes' method to Validator for conditionally adding rules.", "backport": null}
76+
{"message": "Added slick new 'sometimes' method to Validator for conditionally adding rules.", "backport": null},
77+
{"message": "Added new '--sleep' option to queue:listen command to control time between jobs.", "backport": null}
7778
]
7879
}

src/Illuminate/Queue/Console/ListenCommand.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Listener $listener)
4848
*/
4949
public function fire()
5050
{
51-
$this->listener->setEnvironment($this->laravel->environment());
51+
$this->setListenerOptions();
5252

5353
$delay = $this->input->getOption('delay');
5454

@@ -87,6 +87,18 @@ protected function getQueue($connection)
8787
return $this->input->getOption('queue') ?: $queue;
8888
}
8989

90+
/**
91+
* Set the options on the queue listener.
92+
*
93+
* @return void
94+
*/
95+
protected function setListenerOptions()
96+
{
97+
$this->listener->setEnvironment($this->laravel->environment());
98+
99+
$this->listener->setSleep($this->option('sleep'));
100+
}
101+
90102
/**
91103
* Get the console command arguments.
92104
*
@@ -114,6 +126,8 @@ protected function getOptions()
114126
array('memory', null, InputOption::VALUE_OPTIONAL, 'The memory limit in megabytes', 128),
115127

116128
array('timeout', null, InputOption::VALUE_OPTIONAL, 'Seconds a job may run before timing out', 60),
129+
130+
array('sleep', null, InputOption::VALUE_OPTIONAL, 'Seconds to wait before checking queue for jobs', 3),
117131
);
118132
}
119133

src/Illuminate/Queue/Console/WorkCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public function __construct(Worker $worker)
4848
*/
4949
public function fire()
5050
{
51-
$queue = $this->input->getOption('queue');
51+
$queue = $this->option('queue');
5252

53-
$delay = $this->input->getOption('delay');
53+
$delay = $this->option('delay');
5454

5555
// The memory limit is the amount of memory we will allow the script to occupy
5656
// before killing it and letting a process manager restart it for us, which
5757
// is to protect us against any memory leaks that will be in the scripts.
58-
$memory = $this->input->getOption('memory');
58+
$memory = $this->option('memory');
5959

60-
$connection = $this->input->getArgument('connection');
60+
$connection = $this->argument('connection');
6161

62-
$this->worker->pop($connection, $queue, $delay, $memory, $this->input->getOption('sleep'));
62+
$this->worker->pop($connection, $queue, $delay, $memory, $this->option('sleep'));
6363
}
6464

6565
/**
@@ -88,7 +88,7 @@ protected function getOptions()
8888

8989
array('memory', null, InputOption::VALUE_OPTIONAL, 'The memory limit in megabytes', 128),
9090

91-
array('sleep', null, InputOption::VALUE_NONE, 'Whether the worker should sleep when no job is available'),
91+
array('sleep', null, InputOption::VALUE_OPTIONAL, 'Number of seconds to sleep when no job is available', 3),
9292
);
9393
}
9494

src/Illuminate/Queue/Listener.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class Listener {
1818
*/
1919
protected $environment;
2020

21+
/**
22+
* The amount of seconds to wait before polling the queue.
23+
*
24+
* @var int
25+
*/
26+
protected $sleep = 3;
27+
2128
/**
2229
* Create a new queue listener.
2330
*
@@ -83,7 +90,7 @@ public function runProcess(Process $process, $memory)
8390
*/
8491
public function makeProcess($connection, $queue, $delay, $memory, $timeout)
8592
{
86-
$string = 'php artisan queue:work %s --queue="%s" --delay=%s --memory=%s --sleep';
93+
$string = 'php artisan queue:work %s --queue="%s" --delay=%s --memory=%s --sleep=%s';
8794

8895
// If the environment is set, we will append it to the command string so the
8996
// workers will run under the specified environment. Otherwise, they will
@@ -93,7 +100,7 @@ public function makeProcess($connection, $queue, $delay, $memory, $timeout)
93100
$string .= ' --env='.$this->environment;
94101
}
95102

96-
$command = sprintf($string, $connection, $queue, $delay, $memory);
103+
$command = sprintf($string, $connection, $queue, $delay, $memory, $this->sleep);
97104

98105
return new Process($command, $this->commandPath, null, null, $timeout);
99106
}
@@ -140,4 +147,25 @@ public function setEnvironment($environment)
140147
$this->environment = $environment;
141148
}
142149

143-
}
150+
/**
151+
* Get the amount of seconds to wait before polling the queue.
152+
*
153+
* @return int
154+
*/
155+
public function getSleep()
156+
{
157+
return $this->sleep;
158+
}
159+
160+
/**
161+
* Set the amount of seconds to wait before polling the queue.
162+
*
163+
* @param int $sleep
164+
* @return void
165+
*/
166+
public function setSleep($sleep)
167+
{
168+
$this->sleep = $sleep;
169+
}
170+
171+
}

src/Illuminate/Queue/QueueServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use Illuminate\Support\ServiceProvider;
44
use Illuminate\Queue\Console\WorkCommand;
55
use Illuminate\Queue\Console\ListenCommand;
6-
use Illuminate\Queue\Console\SubscribeCommand;
76
use Illuminate\Queue\Connectors\SqsConnector;
7+
use Illuminate\Queue\Console\SubscribeCommand;
88
use Illuminate\Queue\Connectors\SyncConnector;
99
use Illuminate\Queue\Connectors\IronConnector;
1010
use Illuminate\Queue\Connectors\RedisConnector;

src/Illuminate/Queue/Worker.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function __construct(QueueManager $manager)
2929
* @param string $queue
3030
* @param int $delay
3131
* @param int $memory
32-
* @param bool $sleep
32+
* @param int $sleep
3333
* @return void
3434
*/
35-
public function pop($connection, $queue = null, $delay = 0, $memory = 128, $sleep = false)
35+
public function pop($connection, $queue = null, $delay = 0, $memory = 128, $sleep = 3)
3636
{
3737
$connection = $this->manager->connection($connection);
3838

@@ -45,9 +45,9 @@ public function pop($connection, $queue = null, $delay = 0, $memory = 128, $slee
4545
{
4646
$this->process($job, $delay);
4747
}
48-
elseif ($sleep)
48+
else
4949
{
50-
$this->sleep(1);
50+
$this->sleep($sleep);
5151
}
5252
}
5353

tests/Queue/QueueListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testMakeProcessCorrectlyFormatsCommandLine()
4141
$this->assertInstanceOf('Symfony\Component\Process\Process', $process);
4242
$this->assertEquals(__DIR__, $process->getWorkingDirectory());
4343
$this->assertEquals(3, $process->getTimeout());
44-
$this->assertEquals('php artisan queue:work connection --queue="queue" --delay=1 --memory=2 --sleep', $process->getCommandLine());
44+
$this->assertEquals('php artisan queue:work connection --queue="queue" --delay=1 --memory=2 --sleep=3', $process->getCommandLine());
4545
}
4646

47-
}
47+
}

0 commit comments

Comments
 (0)