From dadb66638722849e0e15b96c8e677d74bcf973f2 Mon Sep 17 00:00:00 2001 From: Jens Timmerman Date: Tue, 24 Oct 2017 12:25:05 +0200 Subject: [PATCH 1/3] record start time before starting --- bin/sync_django_ldap.py | 12 ++++++++---- setup.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/sync_django_ldap.py b/bin/sync_django_ldap.py index 456198c7..04765e84 100644 --- a/bin/sync_django_ldap.py +++ b/bin/sync_django_ldap.py @@ -67,11 +67,15 @@ def main(): try: last_timestamp = read_timestamp(SYNC_TIMESTAMP_FILENAME) except Exception: - _log.warning("Something broke reading the timestamp from %s" % SYNC_TIMESTAMP_FILENAME) + _log.warning("Something broke reading the timestamp from %s", SYNC_TIMESTAMP_FILENAME) last_timestamp = "201707230000Z" - _log.warning("We will resync from a while back : %s" % (last_timestamp,)) + _log.warning("We will resync from a while back : %s", last_timestamp) - _log.info("Using timestamp %s" % (last_timestamp)) + _log.info("Using timestamp %s", last_timestamp) + # record starttime before starting, and take a 10 sec safety buffer so we don't get gaps where users are approved + # in between the requesting of modified users and writing out the start time + start_time = datetime.now() - 10 + _log.info("startime %s", start_time) try: parent_pid = os.fork() @@ -135,7 +139,7 @@ def main(): if not result: if not opts.options.start_timestamp: - (_, ldap_timestamp) = convert_timestamp(datetime.now()) + (_, ldap_timestamp) = convert_timestamp(start_time) if not opts.options.dry_run: write_timestamp(SYNC_TIMESTAMP_FILENAME, ldap_timestamp) else: diff --git a/setup.py b/setup.py index 310a07a1..91f94e04 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ from vsc.install.shared_setup import ag, jt PACKAGE = { - 'version': '1.0.9', + 'version': '1.0.10', 'author': [ag, jt], 'maintainer': [ag, jt], 'tests_require': ['mock'], From 804f8fbcb400ff9fdb975c96c33ab8eedf345b84 Mon Sep 17 00:00:00 2001 From: Jens Timmerman Date: Tue, 24 Oct 2017 13:09:13 +0200 Subject: [PATCH 2/3] update last know good sync date to yesterday --- bin/sync_django_ldap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/sync_django_ldap.py b/bin/sync_django_ldap.py index 04765e84..6e92b8ff 100644 --- a/bin/sync_django_ldap.py +++ b/bin/sync_django_ldap.py @@ -68,8 +68,8 @@ def main(): last_timestamp = read_timestamp(SYNC_TIMESTAMP_FILENAME) except Exception: _log.warning("Something broke reading the timestamp from %s", SYNC_TIMESTAMP_FILENAME) - last_timestamp = "201707230000Z" - _log.warning("We will resync from a while back : %s", last_timestamp) + last_timestamp = "201710230000Z" + _log.warning("We will resync from a hardcoded know working sync a while back : %s", last_timestamp) _log.info("Using timestamp %s", last_timestamp) # record starttime before starting, and take a 10 sec safety buffer so we don't get gaps where users are approved From f1bdd2a91c7f4db4f1ac1f92dd93296c10f6a74b Mon Sep 17 00:00:00 2001 From: Jens Timmerman Date: Tue, 24 Oct 2017 13:15:54 +0200 Subject: [PATCH 3/3] use timedelta instead of integers to compute dates --- bin/sync_django_ldap.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/sync_django_ldap.py b/bin/sync_django_ldap.py index 6e92b8ff..fddabe90 100644 --- a/bin/sync_django_ldap.py +++ b/bin/sync_django_ldap.py @@ -22,8 +22,7 @@ import pwd import sys -from datetime import datetime - +import datetime from vsc.config.base import VSC_CONF_DEFAULT_FILENAME from vsc.accountpage.client import AccountpageClient @@ -74,7 +73,7 @@ def main(): _log.info("Using timestamp %s", last_timestamp) # record starttime before starting, and take a 10 sec safety buffer so we don't get gaps where users are approved # in between the requesting of modified users and writing out the start time - start_time = datetime.now() - 10 + start_time = datetime.datetime.now() + datetime.timedelta(seconds=-10) _log.info("startime %s", start_time) try: @@ -106,7 +105,7 @@ def main(): client = AccountpageClient(token=opts.options.access_token, url=opts.options.account_page_url + '/api/') syncer = LdapSyncer(client) - last = int((datetime.strptime(last_timestamp, "%Y%m%d%H%M%SZ") - datetime(1970, 1, 1)).total_seconds()) + last = int((datetime.datetime.strptime(last_timestamp, "%Y%m%d%H%M%SZ") - datetime.datetime(1970, 1, 1)).total_seconds()) altered_accounts = syncer.sync_altered_accounts(last, opts.options.dry_run) _log.debug("Altered accounts: %s", altered_accounts)