Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/599 - Add a database Queue driver #897

Merged
merged 13 commits into from
Sep 14, 2019
Merged

Feature/599 - Add a database Queue driver #897

merged 13 commits into from
Sep 14, 2019

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Sep 11, 2019

Closes #599

Documentation

Install from this branch

$ pip install https://github.com/masoniteframework/core/archive/feature/599.zip

First you will need to create the migration for your queue jobs:

$ craft queue:table --jobs

If you want to have a table where failed jobs will be stored, you can create a migration for that table as well. If this table does not exist, any failed jobs will simply stay failed.

$ craft queue:table --failed

Change the database configuration to use the database driver:

DRIVER = 'database'

Or you can leave the queue driver as is and specify the driver directly with the Queue class:

from masonite.queue import Queue

def show(self, queue: Queue):
    queue.driver('database').push(..)

Waiting

With the database driver, you have the ability to use the wait keyword. To queue a job to run 10 minutes from now you can do something like:

from masonite.queue import Queue
from app.jobs import SomeJob

def show(self, queue: Queue):
    queue.driver('database').push(SomeJob, args=(arg1, arg2), wait="10 minutes")

Running the worker

The database driver, like the amqp driver, requires a worker to be running. You can run the worker by using the queue:work command:

$ craft queue:work --driver database

This will start a worker that will poll the database for new jobs every 5 seconds. Once new jobs are found it will run them all and then continue waiting for new jobs. If any jobs fail they will run 3 more times. If the job still fails it will be added to the failed_jobs if one exists. If one does not exist it will stay failed inside the queue_jobs table.

You can still run failed jobs by running

$ craft queue:work --driver database --failed 

@josephmancuso josephmancuso changed the title Feature/599 Feature/599 - Add a database Queue driver Sep 14, 2019
@josephmancuso josephmancuso changed the base branch from 2.2 to master September 14, 2019 12:50
@josephmancuso josephmancuso merged commit 9e8b8ad into master Sep 14, 2019
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.

None yet

1 participant