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
{{ message }}
This repository was archived by the owner on Nov 14, 2024. It is now read-only.
The Queue Server is a server that can work on long taking tasks in the background.
4
+
The Queue Server is a server that can work on long taking tasks in the background. You add a "job" by simply posting a json payload to a URL. Using this queue server you can decouple long taking tasks from the frontend. You can for example use it to send hundreds of E-Mails or create many thumbnails. The use doesn't have to wait for the execution and his browser won't be blocked. After the execution the queue server can inform your application that the job was done by calling a callback URL.
5
5
6
6
#### Requirments
7
7
- PHP 7
8
8
- MySQL
9
-
- Linux server with access via SSH
9
+
- Linux server
10
10
- Composer
11
11
12
12
#### Installation
13
13
- At first do `composer install` to install all dependencies.
14
-
- Now install the database, `TODO: Add schemas for database or make an installer`
15
-
- Edit `src/config.php`
14
+
- Now install the database. The sql dump with an empty database you can find in the `assets/database` folder.
15
+
- Edit `src/config.php`and specify your database there, also configure the settings if you wish.
16
16
17
17
#### Usage
18
18
##### Starting the server
19
-
`php server.php`
20
-
19
+
Open your terminal and execute the following: `php server.php`.
20
+
Make sure that the server is always running, even if you close the terminal. I recommend to use `screen` or `byobu` or simply start the process in the backgroud if you don't care about logs: `php server.php &`
21
21
22
22
## API
23
-
With the built in API you can send jobs to the server, get the status, delete jobs etc.
23
+
With the built in API you can send jobs to the server, get the status, etc.
24
24
25
25
##### Sending jobs to the server
26
26
`POST: /jobs/add`
27
27
28
-
Use any http request library (eg. Guzzle or curl) to send a POST request to `/jobs/add`. This will store the job in the `queue` database which the queue server will execute. The payload for the request could look like this:
28
+
Use any http request library (eg. Guzzle or curl) to send a POST request to `/jobs/add`. This will store the job in the `queue` database which the queue server will execute. For development purposes I recommend using Postman (a free API Client) The payload for the request could look like this:
29
29
30
-
```
30
+
```json
31
31
{
32
32
"priority" : 200,
33
33
"context" : "MyCoolApp",
@@ -48,21 +48,47 @@ Use any http request library (eg. Guzzle or curl) to send a POST request to `/jo
48
48
}
49
49
```
50
50
51
-
The job payload is a JSON which has the `command` object. The command can be of type `http` or `exec` - These workers are stored in `src/app/workers`.
51
+
The job payload is a JSON.
52
+
53
+
each job can have the `priority` value (default = 500), the higher this value the earlier your job will be executed. You can also use a `context` - this is just a string with any name, eg. your app name, or what you are trying to do, eg "send_mailing".
54
+
55
+
There is also the `command` object. The command can be of type `http` or `exec` - These workers are stored in `src/app/workers`.
52
56
In this example the http worker will be executed to do http requests. This could be a file on a server which takes some time to execute. For example this could be a GET request to `sendmails.php?mailing=1234` which will send a lot of emails in the background.
53
57
54
58
Once the job is done, you can use the `callback_done` callback to call another URL or execute a system command. This will inform another server that the job is done. Callbacks are not mandatory but can be useful in some cases.
55
59
60
+
Here is another example by using the `ExecWorker` which will execute a command on your server, The command can be literaly anything (at least anything that the www user can do). Here I also don't use the `callback_done` callback.:
0 commit comments