Skip to content

Commit

Permalink
rollback of utcnow() -> now(UTC)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaeno committed Jan 11, 2024
1 parent 9cc3f66 commit a8a4936
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pandaclient/JobSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pandaclient/PdbUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pandaclient/PsubUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pandaclient/openidc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pandaclient/queryPandaMonUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a8a4936

Please sign in to comment.