#!/usr/bin/env python
# Copyright European Organization for Nuclear Research (CERN)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Vincent Garonne, <vincent.garonne@cern.ch>, 2013

"""
Undertaker is a daemon to manage expired did.
"""

import argparse
import signal

from rucio.daemons.undertaker import run, stop

if __name__ == "__main__":

    signal.signal(signal.SIGTERM, stop)

    parser = argparse.ArgumentParser()
    parser.add_argument("--run-once", action="store_true", default=False, help='One iteration only')
    parser.add_argument("--total-workers", action="store", default=1, type=int, help='Total number of workers')
    parser.add_argument("--chunk-size", action="store", default=5, type=int, help='Chunk size')
    args = parser.parse_args()
    try:
        run(total_workers=args.total_workers, chunk_size=args.chunk_size, once=args.run_once)
    except KeyboardInterrupt:
        stop()
