summaryrefslogtreecommitdiff
path: root/src/daq/nginx-lua/s5-nginx-fetch.lua
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-17 03:15:09 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-17 03:15:09 +0200
commit6340720a0d6ce9a5fb9d63b8896c78df02f5670e (patch)
treed1d31ed187a00eb1d8b59e292f7d1461faee7497 /src/daq/nginx-lua/s5-nginx-fetch.lua
parentlog data expires now (diff)
sfive nginx-lua plugin works now
Diffstat (limited to 'src/daq/nginx-lua/s5-nginx-fetch.lua')
-rw-r--r--src/daq/nginx-lua/s5-nginx-fetch.lua48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/daq/nginx-lua/s5-nginx-fetch.lua b/src/daq/nginx-lua/s5-nginx-fetch.lua
index 90503de..8bfcf07 100644
--- a/src/daq/nginx-lua/s5-nginx-fetch.lua
+++ b/src/daq/nginx-lua/s5-nginx-fetch.lua
@@ -33,10 +33,52 @@
-- Install this by adding the following to your nginx.conf
--
-- location /sfive {
+-- allow localhost;
+-- deny all;
+--
+-- lua_check_client_abort on;
-- content_by_lua_file '/path/to/s5-nginx-fetch.lua';
-- }
--
-ngx.say('Content-type: text/plain; charset=UTF-8')
-ngx.say('')
-ngx.say('sfive says hello world!')
+local sfive = ngx.shared.sfive
+
+local function fetch_cleanup()
+ ngx.log(ngx.INFO, "SFive(fetch): cleanup fetch")
+ sfive:delete("fetch:connected")
+end
+
+local ok, err, force = sfive:add("fetch:connected", 1)
+-- TODO: race condition: when client disconnects here we won't free up the singleton...
+if not ok then
+ if err == "exists" then
+ ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE)
+ else
+ ngx.log(ngx.ERR, "SFive(fetch): failed to set connected flag: " .. err)
+ ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
+ end
+else
+ local ok, err = ngx.on_abort(fetch_cleanup)
+ if not ok then
+ ngx.log(ngx.ERR, "SFive(fetch): failed to register the on_abort callback: ", err)
+ ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
+ end
+
+ ngx.log(ngx.INFO, "SFive(fetch): client connected")
+
+ local sfive_log = ngx.shared.sfive_log
+ while true do
+ logs = sfive_log:get_keys()
+ for i, k in ipairs(logs) do
+ local ok, err = ngx.say(sfive_log:get(k))
+ if not ok then
+ ngx.log(ngx.ERR, "SFive(fetch): failed to register the on_abort callback: ", err)
+ break
+ end
+ sfive_log:delete(k)
+ end
+ ngx.flush()
+ ngx.sleep(0.1)
+ end
+ fetch_cleenup()
+end