#!/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:
# - Cedric Serfon, <cedric.serfon@cern.ch>, 2014
# - Mario Lassnig, <mario.lassnig@cern.ch>, 2015

'''
Necromancer Daemon : Bring the dead files back to life
'''

import argparse
import signal

from rucio.daemons.necromancer import run, stop


if __name__ == "__main__":

    # Bind our callback to the SIGTERM signal and run the daemon:
    signal.signal(signal.SIGTERM, stop)

    parser = argparse.ArgumentParser()
    parser.add_argument("--run-once", action="store_true", default=False, help='Runs one loop iteration')
    parser.add_argument("--threads", action="store", default=1, type=int, help='Concurrency control: number of threads')
    parser.add_argument("--bulk", action="store", default=1000, type=int, help='Bulk control: number of requests per cycle')

    args = parser.parse_args()

    try:
        run(threads=args.threads, bulk=args.bulk, once=args.run_once)
    except KeyboardInterrupt:
        stop()
