config/queue.pyfile. Out of the box, Masonite supports 3 drivers:
asyncdriver simply sends jobs into the background using multithreading. The
amqpdriver is used for any AMQP compatible message queues like RabbitMQ. If you do create a driver, consider making it available on PyPi so others can also install it. The
databasedriver has a few additional features that the other drivers do not have if you need more fine-grained control
Queueableclass that is provided by Masonite. We can simply create jobs using the
app/jobs/SendWelcomeEmail.py. Our job will look like:
Queueclass. Let's run this job from a controller method:
asyncdriver which just sends tasks into the background.
handle()method. This can be done by passing in an iterator into the
asyncqueue driver will allow you to send jobs into the background to run asynchronously. This does not need any third party services like the
multiprocess. The differences between the two is that
threadinguses several threads and
multiprocessuses several processes. Which mode you should use depends on the type of jobs you are processing. You should research what is best depending on your use cases.
blockingsetting in your
APP_DEBUGenvironment variable is:
amqpdriver can be used to communicate with RabbitMQ services.
vhostbut doesn't have a port, we can add a
vhostand set the port to none.
portboth have the option of being
None. If you are developing locally then
vhostshould likely be left out all together. The setting below will most likely be used for your production settings:
queue_jobsand on fail, will store all failed jobs in a
failed_jobstable if one exists. If the
failed_jobstable does not exist then it will not store any failed jobs and any jobs that fail will be lost.
queue:tablecommand with the flag on which table you would like:
queue_jobsmigration where you can store your jobs:
failed_jobsmigration where you can store your failed jobs:
databasedriver. Other drivers currently do not have this ability. In order to delay a job you can use a string time using the
queue:workcommand. It might be a good idea to run this command in a new terminal window since it will stay running until we close it.
channelmay mean different things to different drivers. For the
channelis which queue to listen to. For the
channelis the connection to find the
Queueable) then the job will not requeue. It will only ever attempt to run once.
failedmethod which will be called when the job fails. You can do things like fix a parameter and requeue something, call other queues, send an email to your development team etc.
Queueableclass will handle being failed. All other queued objects will simply die with no failed callback.
division by zero.
databases/migrations. Then you can will migrate it: