#!/usr/bin/env python
# -*- coding: utf-8 -*-
import qondor
import argparse, datetime
parser = argparse.ArgumentParser()
parser.add_argument(
    'runtimestamp',
    type    = str,
    help    = 'Timestamp in the future, up to which to sleep'
    )
parser.add_argument(
    '--allowed_lateness',
    type    = int,
    help    = 'Maximum number of seconds after `runtimestamp` for which the return status is still 0',
    default = 300
    )
args = parser.parse_args()

def main():
    try:
        runtime = datetime.datetime.strptime(args.runtimestamp, '%Y-%m-%d %H:%M:%S')
    except ValueError:
        runtime = datetime.datetime.strptime(args.runtimestamp, '%Y-%m-%d %H:%M:%S.%f')
    qondor.utils.sleep_until(runtime, args.allowed_lateness)

if __name__ == '__main__':
    main()