Skip to content

Commit 7c92b53

Browse files
committed
osm.update.is_outdated: add optional offset argument
1 parent dd3fc8b commit 7c92b53

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,11 @@ Modules documentation
9797
=====================
9898

9999
* [tile methods](doc/osm_tile.md)
100-
101100
* [data methods](doc/osm_data.md)
102-
103101
* [tirex methods](doc/osm_tirex.md)
104-
105102
* [mod_tile+renderd methods](doc/osm_renderd.md)
106-
107103
* [custom http backend methods](doc/osm_http.md)
104+
* [update methods](doc/osm_update.md)
108105

109106

110107
TODO

doc/osm_update.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Returns list of all cached items.
6464
is_outdated
6565
-----------
6666

67-
**syntax:** *is_outdated = osm_update.is_outdated(metafilename, map)*
67+
**syntax:** *is_outdated = osm_update.is_outdated(metafilename, map, offset)*
6868

6969
Checks if metatile file is outdated.
7070

@@ -75,6 +75,16 @@ as outdated and rerender it.
7575
Uses nginx shared dict to cache mtime of flagfilename per map name (does not need to read this file
7676
on every request).
7777

78+
*Offset* is the optional argument (int, default value is 0). This value will be subtracted from
79+
FLAGFILE modification time. Can be useful if some metatiles must be updated with some delay:
80+
81+
```lua
82+
-- update metatiles for 18 zoom 30 days after new database was imported
83+
if z == 18 then
84+
local is_outdated = osm_update.is_outdated('/var/lib/mod_tile/mapname/16/0/0/0/0/0.meta', 'mapname', 30 * 24 * 60 * 60)
85+
end
86+
```
87+
7888
get_last_update
7989
---------------
8090

@@ -85,14 +95,14 @@ Get last update time stored in nginx shared memory cache for given map.
8595
get_mtime
8696
---------
8797

88-
**syntax:** *mtime = data.get_mtime("/var/lib/mod_tile/planet-import-complete")*
98+
**syntax:** *mtime = osm_update.get_mtime(filepath)*
8999

90-
Get modification time of file. If file does not exists, returns nil.
100+
Get modification time of file. If file does not exist, returns nil.
91101

92102
is_file_newer
93103
-------------
94104

95-
**syntax:** *is_outdated = data.is_file_newer("/var/lib/mod_tile/planet-import-complete", "/var/lib/mod_tile/map/1/1/1.png")*
105+
**syntax:** *is_newer = osm_update.is_file_newer(filepath1, filepath12)*
96106

97107
Compare modification time of two files. Returns true if file1 newer than file2.
98108

osm/update.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local shmem = ngx.shared.osm_last_update
2626
local UPDATE_KEY = 'enabled'
2727

2828
local _M = {
29-
_VERSION = '0.2',
29+
_VERSION = '0.3',
3030
FLAGFILE = '/var/lib/mod_tile/planet-import-complete',
3131
EXPTIME = 3600, -- one hour
3232
}
@@ -39,10 +39,11 @@ function _M.get_state()
3939
end
4040

4141
-- checks if metatile file is outdated
42-
-- args: metafilename, map (string)
42+
-- args: metafilename, map (string),
43+
-- offset (int) [optional, default=0]: offset in seconds, subtracted from metafilename mtime
4344
-- returns: true if metafilename older than flagfilename.
4445
--
45-
function _M.is_outdated(metafilename, map)
46+
function _M.is_outdated(metafilename, map, offset)
4647
if shmem == nil then
4748
return false
4849
end
@@ -56,7 +57,7 @@ function _M.is_outdated(metafilename, map)
5657
return false
5758
end
5859

59-
-- store mtime of flaf file to shared memory cache with key = map, value = last_update
60+
-- store mtime of flag file to shared memory cache with key = map, value = last_update
6061
-- and expiration time = exptime
6162
last_update = mtime
6263
local success = shmem:set(map, last_update, _M.EXPTIME)
@@ -73,7 +74,8 @@ function _M.is_outdated(metafilename, map)
7374
return true
7475
end
7576

76-
return last_update > mtime
77+
local _offset = offset or 0
78+
return (last_update - _offset) > mtime
7779
end
7880

7981
-- get last update time for map from nginx shared cache

0 commit comments

Comments
 (0)