From 5051901a1e2391b6f8e5a13bba69906c22342885 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 20 Oct 2014 04:50:16 +0200 Subject: daq: nginx-lua fetcher improved init --- src/daq/nginx-lua/s5-nginx-lua-fetch.py | 40 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src/daq') 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) -- cgit v1.2.3