Skip to content

Commit

Permalink
incldue additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
spigad committed Jan 3, 2020
1 parent 72f0582 commit 6331a09
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ def check_tts_data(self):
logging.debug("Token about to expire. Get tts data...")
tts_data = self.get_tts_data(True)
else:
logging.debug("Token OK.")
return True
if os.path.exists(self.config.user.key) and os.path.getsize(self.config.user.key) > 0:
logging.debug("Token OK.")
return True
else:
logging.debug("%s has zero lenght... getting tts data again" % self.config.user.key)
tts_data = self.get_tts_data(True)
else:
logging.debug("Token not exist, get exchange token...")
self.exchanged_token = self.get_exchange_token()
Expand Down Expand Up @@ -482,6 +486,19 @@ def get_tts_data(self, exchange=False):
def generate_proxy(self):
"""Generates proxy with grid-proxy-init only if there are not errors."""


if os.path.exists(self.config.user.proxy):
logging.debug("Check proxy cert : %s", self.config.user.proxy)
ctime = os.stat(self.config.user.proxy).st_ctime
since = time.time() - ctime
logging.debug("Check expiration time: %s > %s",
since, self.config.local_cache.expiration_time)
if since < self.config.local_cache.expiration_time:
logging.debug("cached proxy file still ok")
return self.config.user.proxy
else:
logging.debug("proxy file about to expire. Get tts data...")

if self.check_tts_data():
logging.debug("Generating proxy for %s", self.exchanged_token)

Expand Down

0 comments on commit 6331a09

Please sign in to comment.