Commit 878c3b3a authored by Rafael Monnerat's avatar Rafael Monnerat

[webrunner]: use newest timestamp in equeue.db to get last backup date

in some webrunner, there are 2 keys in equeue.db:

```
>>> print(db.keys())
['/srv/slapgrid/slappart18/bin//runner-importer', '/srv/slapgrid/slappart18/bin/runner-importer']
```

As you can see, the importer script path changed. But we don't care
about this, we always want to have the latest (= the newest) backup date.

See merge request !734
parents 58a3efb3 d9dff0e8
...@@ -41,17 +41,17 @@ def getLatestBackupDate(): ...@@ -41,17 +41,17 @@ def getLatestBackupDate():
equeue_database_copy = os.path.join(temporary_directory, 'equeue.db') equeue_database_copy = os.path.join(temporary_directory, 'equeue.db')
shutil.copyfile(equeue_database, equeue_database_copy) shutil.copyfile(equeue_database, equeue_database_copy)
db = gdbm.open(equeue_database_copy) db = gdbm.open(equeue_database_copy)
# Usually, there is only one callback (so only one key # Usually, there is only one callback (so only one key in the db), but if
# in the db), but if there are several: # there are several we take the "newest" one. Indeed, sometimes the importer
# Take the "oldest" one (oldest value). # script change name those introducing a new key inside the db.
db_keys = db.keys() db_keys = db.keys()
if not db_keys: if not db_keys:
result = False result = False
else: else:
last_backup = db[db_keys[-1]] last_backup = db[db_keys[0]]
for callback in db_keys: for callback in db_keys:
timestamp = float(db[callback]) timestamp = float(db[callback])
if timestamp < last_backup: if timestamp > last_backup:
last_backup = timestamp last_backup = timestamp
result = datetime.datetime.fromtimestamp(last_backup) result = datetime.datetime.fromtimestamp(last_backup)
db.close() db.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment