Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeepraju/918b104aa9846c650d75 to your computer and use it in GitHub Desktop.
Save sandeepraju/918b104aa9846c650d75 to your computer and use it in GitHub Desktop.
Minimal docs for SharQ Server

Getting the code

# clone the source code from github
git clone https://github.com/plivo/sharq-server.git

Installation

# create a virtual environment.
virtualenv venv && source ./venv/bin/active

# in the project root directory.
make build && make install

Running the server

SharQ server exposes the sharq-server command.

usage: sharq-server [-h] -c SHARQ_CONFIG [-gc GUNICORN_CONFIG] [--version]

SharQ Server!

optional arguments:
  -h, --help            show this help message and exit
  -c SHARQ_CONFIG, --config SHARQ_CONFIG
                        Absolute path of the SharQ configuration file.
  -gc GUNICORN_CONFIG, --gunicorn-config GUNICORN_CONFIG
                        Gunicorn configuration file.
  --version             show program's version number and exit

SharQ server can be started with the following command. A simple SharQ config file can be found here.

$sharq-server --config sharq.conf

Ensure the SharQ server is up by making a HTTP request.

$curl http://127.0.0.1:8080/
{
  "message": "Hello, SharQ!"
}

Getting Started with the SharQ API

Enqueue

POST /enqueue/<queue_type>/<queue_id>/

Request (Raw JSON POST data):

{
  "job_id": "b81c07a7-5bba-4790-ab40-a061994088c1",
  "interval": 1000,
  "payload": {"hello": "world"}
}

Response (success):

Status Code: 201

{
  "status": "queued"
}

Response (bad request):

Status Code: 400

{
    "message": "`queue_type` is a mandatory parameter",
    "status": "failure"
}

cURL Example:

$curl -H "Accept: application/json" \
-H "Content-type: application/json" \
-X POST -d ' {"job_id": "b81c07a7-5bba-4790-ab40-a061994088c1", "interval": 1000, "payload": {"hello": "world"}}' \
http://localhost:8080/enqueue/sms/1/

Dequeue

GET /dequeue/<queue_type>/

Response (success):

Status Code: 200

{
  "job_id": "b81c07a7-5bba-4790-ab40-a061994088c1",
  "payload": {
    "hello": "world"
  },
  "queue_id": "1",
  "status": "success"
}

Response (queue has no job ready):

Status Code: 404

{
    "status": "failure"
}

Response (bad request): Status Code: 400

{
    "message": "`queue_type` has an invalid value.",
    "status": "failure"
}

cURL Example:

curl http://localhost:8080/dequeue/sms/

Finish

POST /finish/<queue_type>/<queue_id>/<job_id>/

Response (success):

Status Code: 200

{
  "status": "success"
}

Response (bad request):

Status Code: 400

{
    "message": "`queue_id` is a mandatory parameter",
    "status": "failure"
}

cURL Example:

curl -X POST http://localhost:8080/finish/sms/1/b81c07a7-5bba-4790-ab40-a061994088c1/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment