File: lua_backbround_script_timer.lua

package info (click to toggle)
civetweb 1.16%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,184 kB
  • sloc: ansic: 32,473; cpp: 1,374; sh: 480; javascript: 204; makefile: 120; php: 11; perl: 6; python: 3
file content (36 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- Declare a shared "timer" counter and functions "timer"
-- and "start" when the script is loading.
shared.timer = 0


function timer()
    -- Increment shared value.
    shared.timer = shared.timer + 1
    -- Return true to keep interval timer running or false to stop.
    return true
end


function start()
    -- The "start" function is called when the server is ready.
    -- At this point, a timer can be created.
    mg.set_interval(timer, 5)
end


function stop()
    -- The "stop" function is called when the server is stopping.
end

function log(ri)
    -- The "log" function can be used to
	-- (a) filter messages and return boolean: true (log) or false (do not log)
	-- (b) format log message and return it as string (empty string will not log)
	-- (c) forward the log data to an external log
	
	-- Example: Log only if the request was not made from localhost
	return (ri.remote_addr ~= "127.0.0.1");
end

-- Return false to abort server startup.
return true;