summaryrefslogtreecommitdiff
path: root/src/daq
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-20 04:50:16 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-20 05:16:02 +0200
commit5051901a1e2391b6f8e5a13bba69906c22342885 (patch)
tree96c89b334dad2ced3539079264d42e1143980c7c /src/daq
parentclients are now unique by (ip|ua) (diff)
daq: nginx-lua fetcher improved init
Diffstat (limited to 'src/daq')
-rwxr-xr-xsrc/daq/nginx-lua/s5-nginx-lua-fetch.py40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/daq/nginx-lua/s5-nginx-lua-fetch.py b/src/daq/nginx-lua/s5-nginx-lua-fetch.py
index 924b1a9..86ef940 100755
--- a/src/daq/nginx-lua/s5-nginx-lua-fetch.py
+++ b/src/daq/nginx-lua/s5-nginx-lua-fetch.py
@@ -170,13 +170,12 @@ class NGXLuaFetcher():
self._duration = properties['duration']
self._tags = properties['tags']
self._url = properties['url']
- self._nameformat = properties['nameformat']
self._initStreamerIds(properties['streamer-ids'])
self._proto = None
self._conn = None
self._connected = False
- self._url_re = None
+ self._url_re = re.compile(properties['nameformat'])
self._looper = None
self._start_time = None
@@ -222,15 +221,15 @@ class NGXLuaFetcher():
def run(self):
- if self._initFetch():
- # try to be aligned with current time
- # this will eventually get out of sync but for now this is good enough
- offset = self._duration - (time.time() % self._duration)
- print 'SFive: %sZ -> will wait %0.2f seconds before starting looper (alignment)' % (datetime.datetime.utcnow().isoformat('T'), offset)
- self._looper = task.LoopingCall(self._sendUpdates)
- reactor.callLater(offset, self._startLooper)
- reactor.callWhenRunning(self._initSocket)
- reactor.run()
+ self._initFetch()
+ # try to be aligned with current time
+ # this will eventually get out of sync but for now this is good enough
+ offset = self._duration - (time.time() % self._duration)
+ print 'SFive: %sZ -> will wait %0.2f seconds before starting looper (alignment)' % (datetime.datetime.utcnow().isoformat('T'), offset)
+ self._looper = task.LoopingCall(self._sendUpdates)
+ reactor.callLater(offset, self._startLooper)
+ reactor.callWhenRunning(self._initSocket)
+ reactor.run()
def _startLooper(self):
self._start_time = datetime.datetime.utcnow().replace(microsecond=0)
@@ -248,20 +247,11 @@ class NGXLuaFetcher():
self._start_time = datetime.datetime.utcnow().replace(microsecond=0)
def _initFetch(self):
- try:
- self._url_re = re.compile(self._nameformat)
-
- print "SFive: trying to fetch from '%s'" % self._url
- agent = Agent(reactor)
- d = agent.request('GET', self._url, Headers({'User-Agent': ['SFive nginx-lua fetcher']}), None)
- d.addCallback(self._httpResponse)
- d.addBoth(self.close)
-
- except re.error as e:
- print 'SFive: regex error: %s' % (e)
- return False
-
- return True
+ print "SFive: trying to fetch from '%s'" % self._url
+ agent = Agent(reactor)
+ d = agent.request('GET', self._url, Headers({'User-Agent': ['SFive nginx-lua fetcher']}), None)
+ d.addCallback(self._httpResponse)
+ d.addBoth(self.close)
def _httpResponse(self, response):
print 'SFive: got response from %s: %d %s' % (self._url, response.code, response.phrase)