Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 16, 2020
1 parent 452826b commit 06b378c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Queue/ClearableQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface ClearableQueue
{
/**
* Clear all jobs from the queue.
* Delete all of the jobs from the queue.
*
* @param string $queue
* @return int
Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Queue/Console/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ClearCommand extends Command
*
* @var string
*/
protected $description = 'Clear the queue';
protected $description = 'Delete all of the jobs from the specified queue';

/**
* Execute the console command.
Expand All @@ -45,14 +45,15 @@ public function handle()
// configuration file for the application. We will pull it based on the set
// connection being run for the queue operation currently being executed.
$queueName = $this->getQueue($connection);

$queue = ($this->laravel['queue'])->connection($connection);

if ($queue instanceof ClearableQueue) {
$count = $queue->clear($queueName);

$this->line('<info>Cleared '.$count.' jobs from the '.$queueName.' queue</info> ');
$this->line('<info>Cleared '.$count.' jobs from the ['.$queueName.'] queue</info> ');
} else {
$this->line('<error>Clearing queues is not supported on '.(new ReflectionClass($queue))->getShortName().'</error> ');
$this->line('<error>Clearing queues is not supported on ['.(new ReflectionClass($queue))->getShortName().']</error> ');
}

return 0;
Expand Down
26 changes: 13 additions & 13 deletions src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,6 @@ protected function markJobAsReserved($job)
return $job;
}

/**
* Clear all jobs from the queue.
*
* @param string $queue
* @return int
*/
public function clear($queue)
{
return $this->database->table($this->table)
->where('queue', $this->getQueue($queue))
->delete();
}

/**
* Delete a reserved job from the queue.
*
Expand Down Expand Up @@ -354,6 +341,19 @@ public function deleteAndRelease($queue, $job, $delay)
});
}

/**
* Delete all of the jobs from the queue.
*
* @param string $queue
* @return int
*/
public function clear($queue)
{
return $this->database->table($this->table)
->where('queue', $this->getQueue($queue))
->delete();
}

/**
* Get the queue or return the default.
*
Expand Down
36 changes: 18 additions & 18 deletions src/Illuminate/Queue/LuaScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@ public static function size()
LUA;
}

/**
* Get the Lua script for clearing the queue.
*
* KEYS[1] - The name of the primary queue
* KEYS[2] - The name of the "delayed" queue
* KEYS[3] - The name of the "reserved" queue
*
* @return string
*/
public static function clear()
{
return <<<'LUA'
local size = redis.call('llen', KEYS[1]) + redis.call('zcard', KEYS[2]) + redis.call('zcard', KEYS[3])
redis.call('del', KEYS[1], KEYS[2], KEYS[3])
return size
LUA;
}

/**
* Get the Lua script for pushing jobs onto the queue.
*
Expand Down Expand Up @@ -142,6 +124,24 @@ public static function migrateExpiredJobs()
end
return val
LUA;
}

/**
* Get the Lua script for removing all jobs from the queue.
*
* KEYS[1] - The name of the primary queue
* KEYS[2] - The name of the "delayed" queue
* KEYS[3] - The name of the "reserved" queue
*
* @return string
*/
public static function clear()
{
return <<<'LUA'
local size = redis.call('llen', KEYS[1]) + redis.call('zcard', KEYS[2]) + redis.call('zcard', KEYS[3])
redis.call('del', KEYS[1], KEYS[2], KEYS[3])
return size
LUA;
}
}
30 changes: 15 additions & 15 deletions src/Illuminate/Queue/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,6 @@ protected function retrieveNextJob($queue, $block = true)
return [$job, $reserved];
}

/**
* Clear all jobs from the queue.
*
* @param string $queue
* @return int
*/
public function clear($queue)
{
$queue = $this->getQueue($queue);

return $this->getConnection()->eval(
LuaScripts::clear(), 3, $queue, $queue.':delayed', $queue.':reserved'
);
}

/**
* Delete a reserved job from the queue.
*
Expand Down Expand Up @@ -302,6 +287,21 @@ public function deleteAndRelease($queue, $job, $delay)
);
}

/**
* Delete all of the jobs from the queue.
*
* @param string $queue
* @return int
*/
public function clear($queue)
{
$queue = $this->getQueue($queue);

return $this->getConnection()->eval(
LuaScripts::clear(), 3, $queue, $queue.':delayed', $queue.':reserved'
);
}

/**
* Get a random ID string.
*
Expand Down

0 comments on commit 06b378c

Please sign in to comment.