You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+153-83
Original file line number
Diff line number
Diff line change
@@ -11,70 +11,96 @@
11
11
12
12
This package allows you to use Google Cloud Scheduler to schedule Laravel commands.
13
13
14
-
It only supports Artisan commands at this time due to security concerns.
15
-
16
14
# How it works
17
15
18
16
Cloud Scheduler will make HTTP calls to your application. This package adds an endpoint to your application that accepts these HTTP calls with their payload (an Artisan command) and execute them.
There are two ways to schedule commands using this package:
21
19
22
-
All these features are supported. This package scans your console kernel (`app/Console/Kernel.php`) to see if the scheduled command in Cloud Scheduler is also scheduled in the console kernel, If it is, it will respect all configured events/hooks associated with the command. (such as withoutOverlapping)
20
+
<details>
21
+
<summary>1. Schedule the `schedule:run` command</summary>
23
22
24
-
# Requirements
23
+
This is the easiest way to use this package. You can schedule the `schedule:run` command to run every minute.
If your application does not have commands that should run every minute, you may choose to schedule them individually.
30
+
31
+
If the command uses `withoutOverlapping`, `before`, `after`, `onSuccess`, `thenPing`, etc, this package will respect those settings, as long as the command is also scheduled in the console kernel.
32
+
33
+
For example, let's say we have to generate a report every day at 3:00 AM. We can schedule the `reports:generate` command to run at 3:00 AM using Cloud Scheduler. After the report is generated, OhDear should be pinged.
25
34
26
-
This package requires Laravel 6 or higher.
35
+
Firstly, schedule the command in Cloud Tasks:
27
36
28
-
Please check the table below for supported Laravel and PHP versions:
37
+
<imgsrc="/schedule-command-example.png">
38
+
39
+
Then, schedule the command in the console kernel:
40
+
41
+
```php
42
+
public function schedule(Schedule $schedule)
43
+
{
44
+
$schedule->command('report:generate')
45
+
->thenPing('https://ohdear.app/ping');
46
+
}
47
+
```
29
48
30
-
|Laravel Version| PHP Version |
31
-
|---|---|
32
-
| 6.x | 7.4 or 8.0
33
-
| 7.x | 7.4 or 8.0
34
-
| 8.x | 7.4 or 8.0
35
-
| 9.x | 8.0 or 8.1 or 8.2 or 8.3
36
-
| 10.x | 8.1 or 8.2 or 8.3
49
+
The package will pick up on the scheduled settings and ping OhDear after the command has run.
(3) Optional: whitelist route for maintenance mode
76
+
3 - Ensure PHP executable is in open_basedir. This is required for the package to run Artisan commands.
53
77
54
-
This step is optional, but highly recommended. To allow jobs to keep running if the application is down (`php artisan down`) you must modify the `PreventRequestsDuringMaintenance` middleware:
4 - Optional, but highly recommended: server configuration
60
85
61
-
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
86
+
Since Artisan commands are now invoked via an HTTP request, you might encounter issues with timeouts. Here's how to adjust them:
62
87
63
-
class PreventRequestsDuringMaintenance extends Middleware
64
-
{
65
-
/**
66
-
* The URIs that should be reachable while maintenance mode is enabled.
67
-
*
68
-
* @var array
69
-
*/
70
-
protected $except = [
71
-
+ '/cloud-scheduler-job',
72
-
];
88
+
```nginx
89
+
server {
90
+
# other server configuration ...
91
+
92
+
location /cloud-scheduler-job {
93
+
proxy_connect_timeout 600s;
94
+
proxy_read_timeout 600s;
95
+
fastcgi_read_timeout 600s;
96
+
}
97
+
98
+
# other locations and server configuration ...
73
99
}
74
100
75
101
```
76
102
77
-
(4) Optional: set application `RUNNING_IN_CONSOLE` (highly recommended)
103
+
5 - Optional, but highly recommended: set application `RUNNING_IN_CONSOLE`
78
104
79
105
Some Laravel service providers only register their commands if the application is being accessed through the command line (Artisan). Because we are calling Laravel scheduler from a HTTP call, that means some commands may never register, such as the Laravel Scout command:
80
106
@@ -101,73 +127,117 @@ public function boot()
101
127
}
102
128
```
103
129
104
-
To circumvent this, please add the following to `public/index.php`
130
+
To circumvent this, please add the following to `bootstrap/app.php`
0 commit comments