Skip to content

Commit 31d05e8

Browse files
authored
Merge pull request #14 from MbahDjoe/master
Laravel 9 and Amazon Linux 2 Support
2 parents ab561e0 + 66418da commit 31d05e8

18 files changed

+404
-970
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ composer.phar
55

66
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
77
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
8-
# composer.lock
8+
composer.lock
9+
910
### JetBrains template
1011
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
1112
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

README.md

+39-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Laravel 5 Queue Worker for Elastic Beanstalk
1+
# Laravel 5 - 9.x Queue Worker for Elastic Beanstalk
22

3-
*Use your L5 application as a worker to consume queues on AWS Elasticbeanstalk*
3+
*Use your Laravel application as a worker to consume queues on AWS Elasticbeanstalk*
44

55
Laravel provides a [wonderful array](https://laravel.com/docs/5.1/queues) of drivers for consuming queues within your application as well as [some documentation](https://laravel.com/docs/5.1/queues#supervisor-configuration) on how to manage your application with [Supervisord](http://supervisord.org/) when it is acting as a worker.
66

77
Unfortunately that's where the documentation ends. There is no guidance on how to manage multiple workers from a devops context which is a huge bummer. But don't worry fam I've got your covered.
88

9-
**This package enables your L5 application to manage itself, as a worker, in an [AWS Elasticbeanstalk](https://aws.amazon.com/elasticbeanstalk/) environment.**
9+
**This package enables your Laravel application to manage itself, as a worker, in an [AWS Elasticbeanstalk](https://aws.amazon.com/elasticbeanstalk/) environment.**
1010

1111
**It provides these features:**
1212

@@ -16,20 +16,31 @@ Unfortunately that's where the documentation ends. There is no guidance on how t
1616
* **Parsing of EB environmental variables to generate supervisor config**
1717
* **Or using a pre-built supervisor config supplied in project**
1818

19-
# Let's get down to business
19+
## Amazon Linux 1 deprecation
20+
21+
Amazon Linux 1 (AL1) is going to be unsupported soon, it is advised to migrate to use Amazon Linux 2 (AL2)
22+
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html
23+
Starts from this release will only support AL2, please use previous releases for use in AL1
2024

25+
# Let's get down to business
2126

2227
## Installation
2328

2429
Require this package
2530

26-
```php
31+
```bash
2732
composer require "foxxmd/laravel-elasticbeanstalk-queue-worker"
2833
```
2934

35+
or for Amazon Linux 1,
36+
37+
```bash
38+
composer require "foxxmd/laravel-elasticbeanstalk-queue-worker@^0.3"
39+
```
40+
3041
**After installing the package you can either:**
3142

32-
Add the ServiceProvider to the providers array in `config/app.php`
43+
Add the ServiceProvider to the providers array in `config/app.php` (for Laravel 5.4 or lower)
3344

3445
```php
3546
FoxxMD\LaravelElasticBeanstalkQueueWorker\ElasticBeanstalkQueueWorkerProvider::class
@@ -43,9 +54,15 @@ php artisan vendor:publish --tag=ebworker
4354

4455
**OR**
4556

46-
Copy everything from `src/.ebextensions` into your own `.ebextensions` folder manually
57+
Copy everything from `src/.ebextensions` into your own `.ebextensions` folder and everything from `src/.platform` into your own `.platform` folder manually
58+
59+
**Note:** This library only consists of the EB deploy steps -- the provider is only for a convenience -- so if you want to you can modify/consolidate the `.ebextensions` / `.platform` folder if you're not into me overwriting your stuff.
4760

48-
**Note:** This library only consists of the EB deploy steps -- the provider is only for a convenience -- so if you want to you can modify/consolidate the `.ebextensions` folder if you're not into me overwriting your stuff.
61+
Don't forget to add +x permission to the EB Platform Hooks scripts
62+
63+
```bash
64+
find .platform -type f -iname "*.sh" -exec chmod +x {} +
65+
```
4966

5067

5168
## Configuration
@@ -54,29 +71,33 @@ Copy everything from `src/.ebextensions` into your own `.ebextensions` folder ma
5471

5572
In order for worker deployment to be active you **must** add this environmental to your elasticbeanstalk environment configuration:
5673

57-
```
74+
```bash
5875
IS_WORKER = true
5976
```
6077

6178
**If this variable is false or not present the deployment will not run**
6279

63-
### Set Queue Driver
80+
### Set Queue Driver / Connection
6481

6582
Set the [driver](https://laravel.com/docs/5.1/queues#introduction) in your your EB environmental variables:
6683

67-
```
84+
```bash
6885
QUEUE_DRIVER = [driver]
6986
```
7087

71-
**Note: If no `QUEUE_DRIVER` key is present in your EB environmental variables then `beanstalkd` will be used.**
88+
Since Laravel 5.7 the variable name got changed so will also support the new name:
89+
90+
```bash
91+
QUEUE_CONNECTION = [driver]
92+
```
7293

7394
### Add Queues
7495

7596
All queues are configured using EB environmental variables with the following syntax:
7697

7798
**Note**: brackets are placeholders only, do not use them in your actual configuration
7899

79-
```
100+
```bash
80101
queue[QueueName] = [queueName] # Required. The name of the queue that should be run.
81102
[QueueName]NumProcs = [value] # Optional. The number of instances supervisor should run for this queue. Defaults to 1
82103
[QueueName]Tries = [value] # Optional. The number of times the worker should attempt to run in the event an unexpected exit code occurs. Defaults to 5
@@ -113,14 +134,16 @@ return array(
113134

114135
Now during the deploy process your configuration file will be used instead of generating one.
115136

116-
Note: you can check `eb-activity.log` for your EB environment to verify if the deploy process detected and deployed your file. Search for `Starting supervisor configuration parsing.` in the log.
137+
Note: you can check `eb-hooks.log` for your EB environment to verify if the deploy process detected and deployed your file. Search for `Starting supervisor configuration parsing.` in the log.
117138

118139
# But how does it work?
119140

120141
Glad you asked. It's a simple process but required a ton of trial and error to get right (kudos to AWS for their lack of documentation)
121142

122143
EB applications can contain a [folder](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html) that provides advanced configuration for an EB environment, called `.ebextensions`.
123144

145+
EB applications since AL2 can contain [platform hooks](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html) that provides hook scripts for an EB environment, called `.platform`.
146+
124147
This package uses AWS commands files in this folder to detect, install, and update supervisor and its configuration and then run it for you.
125148

126149
### 1. Ingress Supervisor rules
@@ -133,7 +156,7 @@ Supervisor requires port 9001 to be open if you want to access its web monitor.
133156

134157
Otherwise `parseConfig.php` looks for a json file generated earlier that contains all of the environmental variables configured for elastic beanstalk. It then parses out any queue configurations found (see `Add Queues`) section above and generates a supervisor program for each as well as supplying each program with all the environmental variables set for EB. The program to be generated looks like this:
135158

136-
```
159+
```bash
137160
[program:$queue]
138161
command=php artisan queue:work $connection --queue=$queue --tries=$tries --sleep=$sleep --daemon
139162
directory=/var/app/current/
@@ -168,11 +191,7 @@ Now a bash script `workerDeploy.sh` checks for `IS_WORKER=TRUE` in the EB enviro
168191

169192
# Caveats
170193

171-
This is almost verbatim how I have things setup for another project so some usage is limited because of how it was originally written:
172-
173-
* Queue driver defaults to beanstalkd if not explicitly set
174-
175-
All of these are simple fixes though! Check out issues to see these and more and if you need them please make a PR!
194+
Please check out issues and if you need them please make a PR!
176195

177196
## Contributing
178197

composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"email": "[email protected]"
1111
}
1212
],
13-
"require": {
14-
"illuminate/console": "~5.1",
15-
"illuminate/support": "~5.1"
16-
},
17-
"autoload": {
18-
"psr-4": {
19-
"FoxxMD\\LaravelElasticBeanstalkQueueWorker\\": "src/"
20-
}
21-
},
13+
"require": {
14+
"illuminate/console": "5 - 9",
15+
"illuminate/support": "5 - 9"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"FoxxMD\\LaravelElasticBeanstalkQueueWorker\\": "src/"
20+
}
21+
},
2222
"extra": {
2323
"laravel": {
2424
"providers": [

0 commit comments

Comments
 (0)