# HG changeset patch # User bsw # Date 1427194208 -3600 # Node ID e9f6ae14bc72748555e6af2b8933eced54da79a1 # Parent 591b78770f66aeab7c7d358baf0e6336a79881e2 Updated event notifications and moved code from config to prefork initializer diff -r 591b78770f66 -r e9f6ae14bc72 app/main/_prefork/10_init.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/_prefork/10_init.lua Tue Mar 24 11:50:08 2015 +0100 @@ -0,0 +1,36 @@ +if not config.fork then + config.fork = {} +end + +if not config.fork.pre then + config.fork.pre = 4 +end + +if not config.fork.max then + config.fork.max = 8 +end + +if not config.fork.delay then + config.fork.delay = 1 +end + +if not config.port then + config.port = 8080 +end + +if config.localhost == nil then + config.localhost = true +end + +listen{ + { proto = "tcp4", port = config.port, localhost = true }, + { proto = "interval", delay = 5, handler = function() + Event:send_pending_notifications() + end }, + pre_fork = config.fork.pre, + max_fork = config.fork.max, + fork_delay = config.fork.delay +} + +execute.inner() + diff -r 591b78770f66 -r e9f6ae14bc72 config/devel.lua --- a/config/devel.lua Mon Mar 23 23:18:43 2015 +0100 +++ b/config/devel.lua Tue Mar 24 11:50:08 2015 +0100 @@ -271,6 +271,9 @@ config.enable_debug_trace = true +config.fork = { pre = 64, max = 256, delay = 0.01 } + + -- WebMCP accelerator -- uncomment the following two lines to use C implementations of chosen -- functions and to disable garbage collection during the request, to diff -r 591b78770f66 -r e9f6ae14bc72 config/init.lua --- a/config/init.lua Mon Mar 23 23:18:43 2015 +0100 +++ b/config/init.lua Tue Mar 24 11:50:08 2015 +0100 @@ -108,32 +108,4 @@ request.add_header("Cache-Control", "max-age=3600"); end - return -end - -if not config.fork then - config.fork = {} -end - -if not config.fork.pre then - config.fork.pre = 4 -end - -if not config.fork.max then - config.fork.max = 8 -end - -if not config.fork.delay then - config.fork.delay = 1 -end - -if not config.port then - config.port = 8080 -end - -listen{ - { proto = "tcp4", port = config.port, localhost = true }, - pre_fork = config.fork.pre, - max_fork = config.fork.max, - fork_delay = config.fork.delay -} +end \ No newline at end of file diff -r 591b78770f66 -r e9f6ae14bc72 model/event.lua --- a/model/event.lua Mon Mar 23 23:18:43 2015 +0100 +++ b/model/event.lua Tue Mar 24 11:50:08 2015 +0100 @@ -59,8 +59,7 @@ :add_where("event_seen_by_member.member_id ISNULL OR event_seen_by_member.member_id != member.id") :exec() - print (_("Event #{id} -> #{num} members", { id = self.id, num = #members_to_notify })) - + io.stderr:write("Sending notifications for event #{id} to #{num} members", { id = self.id, num = #members_to_notify }) local url @@ -167,19 +166,31 @@ event:send_notification() + if config.notification_handler_func then + config.notification_handler_func(event) + end + return true end end +function Event:send_pending_notifications() + while true do + if not Event:send_next_notification() then + break + end + end +end + function Event:send_notifications_loop() while true do local did_work = Event:send_next_notification() if not did_work then - print "Sleeping 1 second" - os.execute("sleep 1") + print "Sleeping 5 second" + os.execute("sleep 5") end end