Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit fc390e6

Browse files
author
Michel
committed
First public release
1 parent d4c7ea1 commit fc390e6

17 files changed

Lines changed: 364 additions & 490 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [0.0.1] - 2018-08-05
8+
### Added
9+
- Initial Release

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Michael Milawski
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
# Queue Server
22

33
#### What is this?
4-
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.
55

66
#### Requirments
77
- PHP 7
88
- MySQL
9-
- Linux server with access via SSH
9+
- Linux server
1010
- Composer
1111

1212
#### Installation
1313
- 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.
1616

1717
#### Usage
1818
##### 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 &`
2121

2222
## 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.
2424

2525
##### Sending jobs to the server
2626
`POST: /jobs/add`
2727

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:
2929

30-
```
30+
```json
3131
{
3232
"priority" : 200,
3333
"context" : "MyCoolApp",
@@ -48,21 +48,47 @@ Use any http request library (eg. Guzzle or curl) to send a POST request to `/jo
4848
}
4949
```
5050

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`.
5256
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.
5357

5458
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.
5559

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.:
61+
62+
```json
63+
{
64+
"command": {
65+
"type": "exec",
66+
"cmd": "/home/michael/scripts/somescript.sh"
67+
}
68+
}
69+
```
70+
5671
##### Get the status of all jobs
5772
`GET: /jobs/status`
5873

74+
Example output
75+
```json
76+
{
77+
"status": 200,
78+
"data": {
79+
"waiting": 0,
80+
"working": 18,
81+
"max_threads": 20,
82+
"free_threads": 2
83+
}
84+
}
85+
```
86+
5987
##### Get the status of a single job
6088
`GET: /jobs/status/12345`
6189

6290

6391

6492

6593
## Info
66-
Project by Michael Milawski
67-
Started: 07.2018
68-
Status: In Development
94+
Project by Michael Milawski

TODO.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# TODO
2+
3+
### API
4+
- Security. Use some kind of authentication for posting the jobs.
5+
- Route: `jobs/get/<id>` will get the complete job object from database.
6+
7+
8+
### Nice to haves
9+
- Schedule jobs: post a job but tell the server to execute it at a specific time.

_old/jobcentre.php

Lines changed: 0 additions & 105 deletions
This file was deleted.

_old/queue.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)