Skip to content

Commit

Permalink
upd readme
Browse files Browse the repository at this point in the history
  • Loading branch information
creadone committed May 1, 2021
1 parent 6816806 commit d73a172
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qube

HTTP API layer over Tarantool Queue.
API layer over Tarantool Queue via HTTP

## Installation

Expand All @@ -13,30 +13,41 @@ HTTP API layer over Tarantool Queue.
```lua
-- config.lua

Config.http = {
root = '/api/v1',
host = '127.0.0.1',
port = '5672',
token = '77c04ced3f915240d0c5d8d5819f84c7',
log_requests = true,
log_errors = true
}

-- TNT configuration
Config.tarantool = {
access = {
user = 'qube',
password = '77c04ced3f915240d0c5d8d5819f84c7',
},
node = {
pid_file = '/var/run/tarantool',
memtx_memory = 1024 * 1024 * 1024 * 2,
memtx_dir = '/var/backup/qube',
wal_dir = '/var/backup/qube',
log = '/var/log/qube/qube.log',
background = false,
custom_proc_title = 'qube'
pid_file = '/var/run/qube.pid',
memtx_memory = 1024 * 1024 * 1024 * 1,
memtx_dir = './',
wal_dir = './',
background = false,
custom_proc_title = 'qube',
-- log_format = 'json'
}
}

-- HTTP Server
Config.http = {
root = '/api/v1',
host = '127.0.0.1',
port = 5672,
token = '77c04ced3f915240d0c5d8d5819f84c7',
log_requests = true,
log_errors = true
}

-- Shipper (push tasks back to app)
Config.shipper = {
enable = true,
user_agent = 'QubeShipper',
token = '77c04ced3f915240d0c5d8d5819f84c7',
webhook_url = 'http://localhost:3000/qube/_jobs',
task_check = 1
}
```

4. Run server `tarantool init.lua`
6. Run server `tarantool init.lua`
6 changes: 5 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ box.cfg(config.tarantool.node)
local json = require('json')
local qube = require('lib.qube')
local shipper = require('lib.shipper')
shipper.start()
shipper.start()

local http_router = require('http.router')
local http_server = require('http.server')
local tsgi = require('http.tsgi')

-- Push response to client
local function send_response(code, payload)
if not type(payload) == 'table' then
return { status = code, body = json.encode({ message = tostring(payload) }) }
Expand All @@ -20,6 +21,7 @@ local function send_response(code, payload)
end
end

-- Authenticate request before process
local function auth_request(env)
local request_token = env:header('x-auth-token')
if not request_token == config.http.token then
Expand All @@ -29,6 +31,7 @@ local function auth_request(env)
end
end

-- Forward request to handle accordingly to table 'routes'
local function forward_request(controller, request)
local success, result = pcall(qube[controller], request)
if not success then
Expand All @@ -38,6 +41,7 @@ local function forward_request(controller, request)
end
end

-- List of supported routes
local routes = {
{ method = 'GET', path = '/tubes', controller = 'tube_list' },
{ method = 'POST', path = '/tubes', controller = 'create_tube' },
Expand Down

0 comments on commit d73a172

Please sign in to comment.