From d73a17232febe4e832032b5e34997a280c7d42e1 Mon Sep 17 00:00:00 2001 From: creadone Date: Sat, 1 May 2021 06:42:15 +0300 Subject: [PATCH] upd readme --- README.md | 47 +++++++++++++++++++++++++++++------------------ init.lua | 6 +++++- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3b2e0e1..2338b8e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Qube -HTTP API layer over Tarantool Queue. +API layer over Tarantool Queue via HTTP ## Installation @@ -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` \ No newline at end of file +6. Run server `tarantool init.lua` \ No newline at end of file diff --git a/init.lua b/init.lua index ab56a63..721a94d 100644 --- a/init.lua +++ b/init.lua @@ -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) }) } @@ -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 @@ -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 @@ -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' },