diff --git a/pandaclient/JobSpec.py b/pandaclient/JobSpec.py index 2c030fa..93a8799 100755 --- a/pandaclient/JobSpec.py +++ b/pandaclient/JobSpec.py @@ -236,7 +236,7 @@ def __setattr__(self, name, value): newVal = getattr(self, name) if name == "jobStatus": if oldVal != newVal: - self.stateChangeTime = datetime.datetime.now(datetime.UTC) + self.stateChangeTime = datetime.datetime.utcnow() # collect changed attributes if oldVal != newVal and name not in self._suppAttrs: self._changedAttrs[name] = value diff --git a/pandaclient/PdbUtils.py b/pandaclient/PdbUtils.py index 4c4106e..b2e60c0 100644 --- a/pandaclient/PdbUtils.py +++ b/pandaclient/PdbUtils.py @@ -499,7 +499,7 @@ def initialzieDB(verbose=False, restoreDB=False): def insertJobDB(job, verbose=False): tmpLog = PLogger.getPandaLogger() # set update time - job.lastUpdate = datetime.datetime.now(datetime.UTC) + job.lastUpdate = datetime.datetime.utcnow() # make sql sql1 = "INSERT INTO %s (%s) " % (pdbProxy.tablename, LocalJobSpec.columnNames()) sql1 += "VALUES " + job.values() @@ -519,7 +519,7 @@ def updateJobDB(job, verbose=False, updateTime=None): job.lastUpdate = updateTime sql1 += " AND lastUpdate<'%s' " % updateTime.strftime("%Y-%m-%d %H:%M:%S") else: - job.lastUpdate = datetime.datetime.now(datetime.UTC) + job.lastUpdate = datetime.datetime.utcnow() status, out = pdbProxy.execute_direct(sql1) if not status: raise RuntimeError("failed to update job") @@ -539,7 +539,7 @@ def setRetryID(job, verbose=False): # delete old jobs def deleteOldJobs(days, verbose=False): # time limit - limit = datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=days) + limit = datetime.datetime.utcnow() - datetime.timedelta(days=days) # make sql sql1 = "DELETE FROM %s " % pdbProxy.tablename sql1 += " WHERE creationTime<'%s' " % limit.strftime("%Y-%m-%d %H:%M:%S") diff --git a/pandaclient/PsubUtils.py b/pandaclient/PsubUtils.py index 7ecc279..9738708 100644 --- a/pandaclient/PsubUtils.py +++ b/pandaclient/PsubUtils.py @@ -48,7 +48,7 @@ def resetCacheValues(): global cacheActime global cacheLastUpdate global cacheVomsInfo - timeNow = datetime.datetime.now(datetime.UTC) + timeNow = datetime.datetime.utcnow() if cacheLastUpdate is None or (timeNow - cacheLastUpdate) > datetime.timedelta(minutes=60): cacheLastUpdate = timeNow cacheProxyStatus = None diff --git a/pandaclient/openidc_utils.py b/pandaclient/openidc_utils.py index 8304e0b..e9efde5 100644 --- a/pandaclient/openidc_utils.py +++ b/pandaclient/openidc_utils.py @@ -80,7 +80,7 @@ def get_id_token(self, token_endpoint, client_id, client_secret, device_code, in return False, "aborted" if self.verbose: self.log_stream.debug("getting ID token") - startTime = datetime.datetime.now(datetime.UTC) + startTime = datetime.datetime.utcnow() data = { "client_id": client_id, "client_secret": client_secret, @@ -90,7 +90,7 @@ def get_id_token(self, token_endpoint, client_id, client_secret, device_code, in rdata = urlencode(data).encode() req = Request(token_endpoint, rdata) req.add_header("content-type", "application/x-www-form-urlencoded") - while datetime.datetime.now(datetime.UTC) - startTime < datetime.timedelta(seconds=expires_in): + while datetime.datetime.utcnow() - startTime < datetime.timedelta(seconds=expires_in): try: conn = urlopen(req) text = conn.read().decode() @@ -173,8 +173,8 @@ def check_token(self): # decode ID token data = json.load(f) dec = decode_id_token(data["id_token"]) - exp_time = datetime.datetime.utcfromtimestamp(dec["exp"]) - delta = exp_time - datetime.datetime.now(datetime.UTC) + exp_time = datetime.datetime.timezone.utcfromtimestamp(dec["exp"]) + delta = exp_time - datetime.datetime.utcnow() if self.verbose: self.log_stream.debug("token expiration time : {0} UTC".format(exp_time.strftime("%Y-%m-%d %H:%M:%S"))) # check expiration time diff --git a/pandaclient/queryPandaMonUtils.py b/pandaclient/queryPandaMonUtils.py index 0ac2e53..af11981 100644 --- a/pandaclient/queryPandaMonUtils.py +++ b/pandaclient/queryPandaMonUtils.py @@ -65,7 +65,7 @@ def query_tasks( else: rep = urlopen(req, context=context) if verbose: - sys.stderr.write("time UTC = {0}\n".format(datetime.datetime.now(datetime.UTC))) + sys.stderr.write("time UTC = {0}\n".format(datetime.datetime.utcnow())) rec = rep.getcode() if verbose: sys.stderr.write("resp code = {0}\n".format(rec)) @@ -116,7 +116,7 @@ def query_jobs(jeditaskid, limit=10000, drop=True, verbose=False): else: rep = urlopen(req, context=context) if verbose: - sys.stderr.write("time UTC = {0}\n".format(datetime.datetime.now(datetime.UTC))) + sys.stderr.write("time UTC = {0}\n".format(datetime.datetime.utcnow())) rec = rep.getcode() if verbose: sys.stderr.write("resp code = {0}\n".format(rec))