Fix exception when attempting to write a datetime to db (#5467)

redis-py 3.0 used in master branch only accepts user data as bytes,
strings or numbers (ints, longs and floats). Attempting to specify a key
or a value as any other type will raise a DataError exception.
This PR address the issue bt converting datetime to str
This commit is contained in:
bingwang-ms 2020-09-25 20:19:18 +08:00 committed by GitHub
parent 13cec4c486
commit 584e2223dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,9 +184,9 @@ class ProcDockerStats(daemon_base.DaemonBase):
self.update_dockerstats_command()
datetimeobj = datetime.now()
# Adding key to store latest update time.
self.update_state_db('DOCKER_STATS|LastUpdateTime', 'lastupdate', datetimeobj)
self.update_state_db('DOCKER_STATS|LastUpdateTime', 'lastupdate', str(datetimeobj))
self.update_processstats_command()
self.update_state_db('PROCESS_STATS|LastUpdateTime', 'lastupdate', datetimeobj)
self.update_state_db('PROCESS_STATS|LastUpdateTime', 'lastupdate', str(datetimeobj))
# Data need to be updated every 2 mins. hence adding delay of 120 seconds
time.sleep(120)