Exemplo n.º 1
0
        retry += 1
        logger.warn("cannot connect to redis DB - retrying (%d)" % retry)
        time.sleep(1)

assert retry < 10, "Cannot connect to redis DB - aborting"

redis.set('admin:storages', json.dumps(base_config['storages']))

pid = os.getpid()

logger.info('Running worker for %s - PID = %d' % (service, pid))

keyw = 'admin:worker:%s:%d' % (service, pid)
redis.hset(keyw, "launch_time", time.time())
redis.hset(keyw, "beat_time", time.time())
redis.expire(keyw, 600)

keys = 'admin:service:%s' % service
redis.hset(keys, "current_configuration", current_configuration)
redis.hset(keys, "configurations", json.dumps(configurations))
redis.hset(keys, "def", pickle.dumps(services[service]))

# remove reserved state from resources
for key in redis.keys('reserved:%s:*' % service):
    redis.delete(key)
# remove queued tasks on service
for key in redis.keys('queued:%s' % service):
    redis.delete(key)

# On startup, add all active tasks in the work queue or service queue
for task_id in task.list_active(redis, service):
Exemplo n.º 2
0
            file_path = os.path.join("configurations", filename)
            with open(file_path) as f:
                configurations[filename[len(service) + 1:-5]] = (os.path.getmtime(file_path),
                                                                 f.read())
            config_service_md5[md5file(file_path)] = filename[len(service) + 1:-5]
    current_configuration_md5 = md5file(args.config)
    if current_configuration_md5 in config_service_md5:
        current_configuration = config_service_md5[current_configuration_md5]

pid = os.getpid()
logger.info('Running worker for %s - PID = %d' % (service, pid))

instance_id = 'admin:worker:%s:%d' % (service, pid)
redis.hset(instance_id, "launch_time", time.time())
redis.hset(instance_id, "beat_time", time.time())
redis.expire(instance_id, 600)

keys = 'admin:service:%s' % service
redis.hset(keys, "current_configuration", current_configuration)
redis.hset(keys, "configurations", json.dumps(configurations))
redis2.hset(keys, "def", pickle.dumps(services[service]))


def graceful_exit(signum, frame):
    logger.info('received interrupt - stopping')
    redis.delete(instance_id)
    sys.exit(0)


signal.signal(signal.SIGTERM, graceful_exit)
signal.signal(signal.SIGINT, graceful_exit)