Repository: laravel/framework
File: src/Illuminate/Queue/QueueManager.php (PHP)

Code before:
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return $this
     */
    public function setApplication($app)
    {
        $this->app = $app;

        foreach ($this->connections as $connection) {
            $connection->setContainer($app);
        }

        return $this;
    }

    /**
     * Pause a queue by name.
     *
     * @param  string  $queue
     * @param  int  $ttl
     * @return void
     */
    public function pause($queue, $ttl = 86400)
    {
        $cache = $this->app['cache']->store();

        $cache->put("queue_paused:{$queue}", true, $ttl);

        // Add to the list of paused queues
        $pausedQueues = $this->getPausedQueues();

        if (! in_array($queue, $pausedQueues)) {
            $pausedQueues[] = $queue;
            $this->storePausedQueuesList($pausedQueues);
        }
    }

    /**
     * Resume a paused queue by name.
     *
     * @param  string  $queue
     * @return void
     */
    public function resume($queue)
    {
        $cache = $this->app['cache']->store();

        $cache->forget("queue_paused:{$queue}");

        // Remove from the list of paused queues
        $pausedQueues = $this->getPausedQueues();


Review comment (performance):
Operation is not atomic here. In some concurrent situation (pausing two queues same time) threir may be such case:

* first process getPausedQueues returns []
* second proccess getPausedQueues returns []
* first process storePausedQueuesList sets ['queue1']
* second process storePausedQueuesList sets ['queue2']

finaly queue_paused_list has ['queue2'] and not ['queue1', 'queue2'] as expected.

One way is to use some sort of locks or isolation here.
But maybe it would be better for siplicicty not to provide PauseList functionality at all. Pausing and resuming certain queue (and single isolated cache key) would be enough. Currently framwork does not have any  functions to get all existing queues list, so listing just paused queues is redundant.

Code after:
     * @return string
     */
    public function getDefaultDriver()
    {
        return $this->app['config']['queue.default'];
    }

    /**
     * Set the name of the default queue connection.
     *
     * @param  string  $name
     * @return void
     */
    public function setDefaultDriver($name)
    {
        $this->app['config']['queue.default'] = $name;
    }

    /**
     * Get the full name for the given connection.
     *
     * @param  string|null  $connection
     * @return string
     */
    public function getName($connection = null)
    {
        return $connection ?: $this->getDefaultDriver();
    }

    /**
     * Get the application instance used by the manager.
     *
     * @return \Illuminate\Contracts\Foundation\Application
     */
    public function getApplication()
    {
        return $this->app;
    }

    /**
     * Set the application instance used by the manager.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return $this
     */
    public function setApplication($app)
    {
        $this->app = $app;

        foreach ($this->connections as $connection) {
            $connection->setContainer($app);