DJJob.php
public function getNewJob() {
        # we can grab a locked job if we own the lock
        $rs = $this->runQuery("
            SELECT id
            FROM   " . self::$jobsTable . "
            WHERE  queue = ?
            AND    (run_at IS NULL OR NOW() >= run_at)
            AND    (locked_at IS NULL OR locked_by = ?)
            AND    failed_at IS NULL
            AND    attempts < ?
            ORDER BY created_at DESC
            LIMIT  10
        ", array($this->queue, $this->name, $this->max_attempts));

        // randomly order the 10 to prevent lock contention among workers
        shuffle($rs);

        foreach ($rs as $r) {
            $job = new DJJob($this->name, $r["id"], array(
                "max_attempts" => $this->max_attempts,
                "fail_on_output" => $this->fail_on_output
            ));
            if ($job->acquireLock()) return $job;
        }

        return false;
    }
public function getNewJob() {
        # we can grab a locked job if we own the lock
        $rs = $this->runQuery("
            SELECT id
            FROM   " . self::$jobsTable . "
            WHERE  queue = ?
            AND    (run_at IS NULL OR NOW() >= run_at)
            AND    (locked_at IS NULL OR locked_by = ?)
            AND    failed_at IS NULL
            AND    attempts < ?
            ORDER BY created_at DESC
            LIMIT  10
        ", array($this->queue, $this->name, $this->max_attempts));

        // randomly order the 10 to prevent lock contention among workers
        shuffle($rs);

        foreach ($rs as $r) {
            $job = new DJJob($this->name, $r["id"], array(
                "max_attempts" => $this->max_attempts,
                "fail_on_output" => $this->fail_on_output
            ));
            if ($job->acquireLock()) return $job;
        }

        return false;
    }
public function getNewJob ( ) { # we can grab a locked job if we own the lock $ rs = $ this -> runQuery ( "
            SELECT id
            FROM   " . self :: $ jobsTable . "
            WHERE  queue = ?
            AND    (run_at IS NULL OR NOW() >= run_at)
            AND    (locked_at IS NULL OR locked_by = ?)
            AND    failed_at IS NULL
            AND    attempts < ?
            ORDER BY created_at DESC
            LIMIT  10
        " , array ( $ this -> queue , $ this -> name , $ this -> max_attempts ) ) ; // randomly order the 10 to prevent lock contention among workers shuffle ( $ rs ) ; foreach ( $ rs as $ r ) { $ job = new DJJob ( $ this -> name , $ r [ "id" ] , array ( "max_attempts" => $ this -> max_attempts , "fail_on_output" => $ this -> fail_on_output ) ) ; if ( $ job -> acquireLock ( ) ) return $ job ; } return false ; }
Returns a new job ordered by most recent first
why this?
run newest first, some jobs get left behind
run oldest first, all jobs get left behind

@return \DJJob|false A job if one was successfully locked. Otherwise false.
Returns a new job ordered by most recent first why this? run newest first some jobs get left behind run oldest first all jobs get left behind