Skip to content

Conversation

@yhbyun
Copy link

@yhbyun yhbyun commented Jul 6, 2015

In getJobFromId method of AsyncClass class, there is beginTransaction, but no commit. So the every sql statements that executed in command handler, and job delete statement rollback.

The following is mysql log.

150706 15:18:16    70 Connect   homestead@localhost on homestead
                   70 Prepare   set names 'utf8' collate 'utf8_unicode_ci'
                   70 Execute   set names 'utf8' collate 'utf8_unicode_ci'
                   70 Close stmt
                   70 Query     START TRANSACTION
                   70 Prepare   select * from `jobs` where `queue` = ? and `reserved` = ? and `id` = ? limit 1 for update
                   70 Execute   select * from `jobs` where `queue` = 'default' and `reserved` = '0' and `id` = '31' limit 1 for update
                   70 Close stmt
                   70 Prepare   update `jobs` set `reserved` = ?, `reserved_at` = ? where `id` = ?
                   70 Execute   update `jobs` set `reserved` = '1', `reserved_at` = '1436195896' where `id` = '31'
                   70 Close stmt
                   70 Prepare   select * from `bookmarks` where `bookmarks`.`id` = ? limit 1
                   70 Execute   select * from `bookmarks` where `bookmarks`.`id` = '4' limit 1
                   70 Close stmt
150706 15:18:24    70 Prepare   delete from `jobs` where `id` = ?
                   70 Execute   delete from `jobs` where `id` = '31'
                   70 Close stmt
                   70 Query     rollback
                   70 Quit

So, I added two commit lines.

I referred to the laravel 5.0 Illumindate\Queue\DataBaseQueue's pop method.

    public function pop($queue = null)
    {
        $queue = $this->getQueue($queue);

        if ( ! is_null($this->expire))
        {
            $this->releaseJobsThatHaveBeenReservedTooLong($queue);
        }

        if ($job = $this->getNextAvailableJob($queue))
        {
            $this->markJobAsReserved($job->id);

            $this->database->commit();

            return new DatabaseJob(
                $this->container, $this, $job, $queue
            );
        }

        $this->database->commit();
    }

@barryvdh
Copy link
Owner

barryvdh commented Aug 7, 2015

The transaction is now gone. Do you still have a problem?

@barryvdh barryvdh closed this Aug 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants