Skip to content

Commit

Permalink
First public release
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel committed Aug 5, 2018
1 parent d4c7ea1 commit fc390e6
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 490 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.0.1] - 2018-08-05
### Added
- Initial Release
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Michael Milawski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Queue Server

#### What is this?
The Queue Server is a server that can work on long taking tasks in the background.
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.

#### Requirments
- PHP 7
- MySQL
- Linux server with access via SSH
- Linux server
- Composer

#### Installation
- At first do `composer install` to install all dependencies.
- Now install the database, `TODO: Add schemas for database or make an installer`
- Edit `src/config.php`
- Now install the database. The sql dump with an empty database you can find in the `assets/database` folder.
- Edit `src/config.php` and specify your database there, also configure the settings if you wish.

#### Usage
##### Starting the server
`php server.php`

Open your terminal and execute the following: `php server.php`.
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 &`

## API
With the built in API you can send jobs to the server, get the status, delete jobs etc.
With the built in API you can send jobs to the server, get the status, etc.

##### Sending jobs to the server
`POST: /jobs/add`

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

```
```json
{
"priority" : 200,
"context" : "MyCoolApp",
Expand All @@ -48,21 +48,47 @@ Use any http request library (eg. Guzzle or curl) to send a POST request to `/jo
}
```

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`.
The job payload is a JSON.

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".

There is also the `command` object. The command can be of type `http` or `exec` - These workers are stored in `src/app/workers`.
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.

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.

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

```json
{
"command": {
"type": "exec",
"cmd": "/home/michael/scripts/somescript.sh"
}
}
```

##### Get the status of all jobs
`GET: /jobs/status`

Example output
```json
{
"status": 200,
"data": {
"waiting": 0,
"working": 18,
"max_threads": 20,
"free_threads": 2
}
}
```

##### Get the status of a single job
`GET: /jobs/status/12345`




## Info
Project by Michael Milawski
Started: 07.2018
Status: In Development
Project by Michael Milawski
9 changes: 9 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO

### API
- Security. Use some kind of authentication for posting the jobs.
- Route: `jobs/get/<id>` will get the complete job object from database.


### Nice to haves
- Schedule jobs: post a job but tell the server to execute it at a specific time.
105 changes: 0 additions & 105 deletions _old/jobcentre.php

This file was deleted.

72 changes: 0 additions & 72 deletions _old/queue.php

This file was deleted.

Loading

0 comments on commit fc390e6

Please sign in to comment.