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

[v1.1.0] Supports Laravel 11 & PHP 8.2, 8.3 #2

Merged
merged 10 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .github/workflows/build-laravel.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Test (Laravel 9, 10)
name: Build & Test (Laravel 10, 11)
env:
TESTING_ENV: ${{ secrets.TESTING_ENV }}

Expand All @@ -16,10 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [
'9',
'10'
]
version: ['10', '11']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -28,7 +25,7 @@ jobs:
- name: Setup PHP with coverage driver
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: pcov

- name: Setup
Expand All @@ -40,22 +37,21 @@ jobs:
composer install --no-interaction
echo "$TESTING_ENV" > .env.testing

- name: Laravel 9 composition
if: matrix.version == '9'
- name: Laravel 10 composition
if: matrix.version == '10'
run: |
composer require \
"laravel/framework" "^9" \
"orchestra/testbench" "^7" \
"phpunit/phpunit" "^9" \
"phpunit/php-code-coverage" "^9" \
composer require "laravel/framework" "^10" \
"orchestra/testbench" "^8" \
--with-all-dependencies

- name: Laravel 10 composition
if: matrix.version == '10'
- name: Laravel 11 composition
if: matrix.version == '11'
run: |
composer require "laravel/framework" "^10" --with-all-dependencies
composer require "laravel/framework" "^11" \
"orchestra/testbench" "^9" \
--with-all-dependencies

- name: PHPUnit tests
if: success() && github.event.pull_request.draft == false
if: success()
run: |
composer test
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Test (PHP 8.1, 8.2)
name: Build & Test (PHP 8.2, 8.3)
env:
TESTING_ENV: ${{ secrets.TESTING_ENV }}

Expand All @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [ '8.1', '8.2' ]
version: [ '8.2', '8.3' ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -38,12 +38,12 @@ jobs:
echo "$TESTING_ENV" > .env.testing

- name: PHPUnit tests with coverage
if: success() && github.event.pull_request.draft == false
if: success()
run: |
composer test-coverage

- name: upload coverage to codecov.io
if: success() && matrix.version == '8.1'
if: success() && matrix.version == '8.2'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/try-installation.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
name: Try Install Package (Laravel 9 & 10)
name: Try Install Package (Laravel 9, 10, 11)
env:
LOCAL_ENV: ${{ secrets.LOCAL_ENV }}

on:
pull_request:
branches:
- 'main'
types: [ opened, synchronize, reopened, ready_for_review ]
push:
branches:
- 'main'
release:
types: [published]

jobs:
build:
strategy:
fail-fast: false
matrix:
version: [ '^9.0', '^10.0' ]
version: [ '^10.0', '^11.0' ]
runs-on: ubuntu-latest
steps:
- name: Setup PHP with coverage driver
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: pcov

- name: Setup and install package on Laravel
Expand Down
56 changes: 34 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,70 @@
[![Total Downloads](http://poser.pugx.org/shipsaas/laravel-priority-queue/downloads)](https://packagist.org/packages/shipsaas/laravel-priority-queue)
[![codecov](https://codecov.io/gh/shipsaas/laravel-priority-queue/branch/main/graph/badge.svg?token=V3HOOR12HA)](https://codecov.io/gh/shipsaas/laravel-priority-queue)
[![Build & Test](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build.yml/badge.svg)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build.yml)
[![Build & Test (Laravel 9, 10)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml/badge.svg)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml)
[![Build & Test (Laravel 10, 11)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml/badge.svg)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml)

A simple Priority Queue Driver for your Laravel Applications.
A simple Priority Queue Driver for your Laravel Applications to serve your priority messages and
makes users happy 🔋.

Laravel Priority Queue Driver uses the `database` driver.
With the famous Repository Pattern of Laravel, Priority Queue Driver is easily get injected into
Laravel's Lifecycle without any hassle/hurdle.

We can use built-in artisan command `php artisan queue:work` 😎.

## Supports
- Laravel 10 (compatible by default)
- Laravel 9 (supports until Laravel drops the bug fixes at [August 8th, 2023](https://laravel.com/docs/10.x/releases))
- PHP 8.1+
- Laravel 11 (supports by default)
- Laravel 10 (supports until Laravel drops the bug fixes at [August 6th, 2024](https://laravel.com/docs/11.x/releases))
- PHP 8.2 & 8.3
- Any database that Laravel supported.

## Architecture
## Architecture Diagram

![Seth Phat - Laravel Priority Queue](https://i.imgur.com/H8OEMhQ.png)

## Why `database`?

- Easy and simple to implement.
- Utilize the `ORDER BY` and `INDEX` for fast queue msgs pop process.
- Super visibility (you can view the jobs and their data in DB).
- Super flexibility (you can change the weight directly in DB to unblock important msgs).
### Why Priority Queue Driver use Database?

## Installation
- Everybody knows Database (MySQL, PgSQL, etc) 👀.
- Easy and simple to implement ❤️.
- Utilize the `ORDER BY` and `INDEX` for fast queue msgs pop process. Faster than any other stuff 🔥.
- Highest visibility (you can view the jobs and their data in DB) ⭐️.
- Highest flexibility (you can change the weight directly in DB to unblock important msgs) 💰.
- No extra tool involved. Just Laravel 🥰.

Install the library:
## Install Laravel Priority Queue

```bash
composer require shipsaas/laravel-priority-queue
```

Export and run the migration:
### One-Time Setup

Export and run the migration (one-time):

```bash
# if you don't need to adjust the migration, don't have to export it
php artisan vendor:publish --tag=priority-queue-migrations
php artisan migrate
```

### One-Time Setup

Open `config/queue.php` and add this into the `connections` array:

```php
'connections' => [
// ... a lot of connections above
// then our lovely guy here
'database-priority' => [
'driver' => 'database-priority',
'connection' => 'mysql',
'table' => 'priority_jobs',
'queue' => 'default',
'retry_after' => 90,
],
],
```

### Note
## Scale/Reliability Consideration

We highly recommend you to use a different database connection (eg `mysql_secondary`) to avoid the worker processes ramming your
It is recommended using a different database connection (eg `mysql_secondary`) to avoid the worker processes ramming your
primary database.

## Usage
Expand Down Expand Up @@ -86,7 +96,7 @@ class SendEmail implements ShouldQueue

public function getJobWeight() : int
{
return $this->user->isPro()
return $this->user->isUsingProPlan()
? 1000
: 500;
}
Expand All @@ -111,10 +121,12 @@ Queue::connection('database-priority')

## Run The Queue Worker

Nothing different from the Laravel's Doc.
Nothing different from the Laravel Documentation 😎. Just need to include the `database-priority` driver.

```bash
php artisan queue:work database-priority

# Extra win, priority on topic
php artisan queue:work database-priority --queue=custom
```

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shipsaas/laravel-priority-queue",
"type": "library",
"version": "1.0.0",
"version": "1.1.0",
"description": "Priority Queue implementation for your Laravel Applications",
"keywords": [
"laravel library",
Expand All @@ -19,14 +19,14 @@
],
"license": "MIT",
"require": {
"php": "^8.1|^8.2",
"laravel/framework": "^9|^10|dev-master"
"php": "^8.2|^8.3",
"laravel/framework": "^10|^11"
},
"require-dev": {
"fakerphp/faker": "^v1.20.0",
"mockery/mockery": "^1.5.1",
"phpunit/phpunit": "^9|^10",
"orchestra/testbench": "^7|^8",
"phpunit/phpunit": "^10",
"orchestra/testbench": "^8|^9",
"phpunit/php-code-coverage": "^9|^10",
"friendsofphp/php-cs-fixer": "^3.10"
},
Expand Down
Loading
Loading