Exemplo n.º 1
0
    def schedule_next_run(self, random_interval=None):
        if not random_interval:
            random_interval = self.random_interval_max

        next_run_at = misc.now() + random.randint(1, random_interval)
        printdbg("scheduling next sentinel run for %d" % next_run_at)
        Transient.set(self.transient_key_scheduled, next_run_at,
                      next_run_at)
Exemplo n.º 2
0
class Scheduler(object):
    transient_key_scheduled = 'NEXT_SENTINEL_CHECK_AT'
    random_interval_max = 1800

    @classmethod
    def is_run_time(self):
        next_run_time = Transient.get(self.transient_key_scheduled) or 0
        now = misc.now()

        printdbg("current_time = %d" % now)
        printdbg("next_run_time = %d" % next_run_time)

        return now >= next_run_time

    @classmethod
    def clear_schedule(self):
        Transient.delete(self.transient_key_scheduled)

    @classmethod
    def schedule_next_run(self, random_interval=None):
        icbet random_interval:
            random_interval = self.random_interval_max

        next_run_at = misc.now() + random.randint(1, random_interval)
        printdbg("scheduling next sentinel run for %d" % next_run_at)
        Transient.set(self.transient_key_scheduled, next_run_at,
                      next_run_at)
Exemplo n.º 3
0
def entrypoint():
    # ensure another instance of Sentinel pointing at the same config
    # is not currently running
    mutex_key = 'SENTINEL_RUNNING_' + config.dash_conf

    atexit.register(cleanup, mutex_key)
    signal.signal(signal.SIGINT, signal_handler)

    # assume that all processes expire after 'timeout_seconds' seconds
    timeout_seconds = 90

    is_running = Transient.get(mutex_key)
    if is_running:
        printdbg("An instance of Sentinel is already running -- aborting.")
        sys.exit(1)
    else:
        Transient.set(mutex_key, misc.now(), timeout_seconds)

    # locked to this instance -- perform main logic here
    main()

    Transient.delete(mutex_key)
Exemplo n.º 4
0
                        dest='bypass')
    parser.add_argument('-v', '--version',
                        action='store_true',
                        help='Print the version (Wienchain Sentinel vX.X.X) and exit')

    args = parser.parse_args()

    return args


if __name__ == '__main__':
    atexit.register(cleanup)
    signal.signal(signal.SIGINT, signal_handler)

    # ensure another instance of Sentinel is not currently running
    mutex_key = 'SENTINEL_RUNNING'
    # assume that all processes expire after 'timeout_seconds' seconds
    timeout_seconds = 90

    is_running = Transient.get(mutex_key)
    if is_running:
        printdbg("An instance of Sentinel is already running -- aborting.")
        sys.exit(1)
    else:
        Transient.set(mutex_key, misc.now(), timeout_seconds)

    # locked to this instance -- perform main logic here
    main()

    Transient.delete(mutex_key)