Docker deploys Laravel application to realize queue & task scheduling

Docker deploys Laravel application to realize queue & task scheduling

In the previous article, we wrote about how to deploy Laravel applications with Docker. In this article, we will write about how to deploy Laravel applications with queues and task scheduling.

1. Let's first prepare our docker/app.cron file

Note that the blank line at the end of the file is required.

#!/usr/bin/env bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1

2. Create a new entry file: docker-entrypoint-queue.sh

Note that this file requires execute permissions.

#!/usr/bin/env bash

php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Load the scheduled task and restart cron
crontab docker/app.cron
/etc/init.d/cron restart

# Execute queue php artisan queue:work --timeout=60

3. This time we use docker compose to run the program: ./docker-compose.yml

version: "3.4"

services:
 API:
  build: .
  image: moorper/example-laravel
  networks:
   -frontend
   - backend
  environment:
   - APP_ENV=development
  ports:
   - "80:80"
  entrypoint: ./docker-entrypoint.sh
 queue:
  build: .
  image: moorper/example-laravel
  networks:
   - backend
  environment:
   - APP_ENV=development
  entrypoint: ./docker-script-entrypoint.sh
  
networks:
 frontend:
 backend:

4. Operation

docker-compose up -d

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Laravel5.6 framework mail queue database driver simple demo example
  • Summary of Laravel's Queue Queue Tips
  • Laravel 6 will add the ability to set middleware for specific queue tasks
  • Implementation of Laravel Queue
  • Analysis of the principle and usage of Laravel framework queue
  • Why not use blpop to get the queue in Laravel?
  • Detailed explanation of the problem of multiple processes in Laravel Redis taking queues at the same time
  • Source code analysis of the reasons why Laravel repeatedly executes the same queue task
  • Some issues that need to be paid attention to when using message queues in Laravel
  • Example of sending emails using queues in Laravel
  • A brief discussion on the implementation principle of Laravel queue and problem solving records
  • A brief analysis of the configuration and use of queues in Laravel5
  • How to use message queues and asynchronous queues in PHP's Laravel framework
  • Experience using queue service in Laravel 4.2
  • Detailed explanation of queue and job operations in Laravel framework

<<:  MySQL 5.7.20 installation and configuration method graphic tutorial (win10)

>>:  Vue recursively implements three-level menu

Recommend

How to change the root password in a container using Docker

1. Use the following command to set the ssh passw...

How to write configuration files and use MyBatis simply

How to write configuration files and use MyBatis ...

el-table in vue realizes automatic ceiling effect (supports fixed)

Table of contents Preface Implementation ideas Ef...

Detailed explanation of MySQL database index

Table of contents 1. Introduction to MySQL Index ...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

MySQL uses find_in_set() function to implement where in() order sorting

This article introduces a tutorial about how to u...

How to install PostgreSQL11 on CentOS7

Install PostgreSQL 11 on CentOS 7 PostgreSQL: The...

Vue-cli creates a project and analyzes the project structure

Table of contents 1. Enter a directory and create...

Detailed Introduction to Nginx Installation and Configuration Rules

Table of contents 1. Installation and operation o...

Detailed explanation of browser negotiation cache process based on nginx

This article mainly introduces the detailed proce...

Detailed explanation of MySQL covering index

concept If the index contains all the data that m...

Let’s talk in detail about how browsers view closures

Table of contents Preface Introduction to Closure...