

@typecheck(ExperimentId, (basestring, dict), basestring, typecheck.ANY)
def create(self, experiment_id, client_initial_data, request_info, now=None):
    client = self._redis_maker()
    serialized_client_initial_data = json.dumps(client_initial_data)
    server_initial_data = '{}'
    if (now is None):
        now = datetime.datetime.utcnow
    else:
        self.now = now
    current_moment = now()
    now_timestamp = (time.mktime(current_moment.timetuple()) + (current_moment.microsecond / 1000000.0))
    MAX_TRIES = 10
    for _ in xrange(MAX_TRIES):
        reservation_id = str(uuid.uuid4())
        value = client.sadd(WEBLAB_RESERVATIONS, reservation_id)
        if (value == 0):
            continue
        weblab_reservation = (WEBLAB_RESERVATION % reservation_id)
        weblab_reservation_status = (WEBLAB_RESERVATION_STATUS % reservation_id)
        weblab_resource_reservations = (WEBLAB_RESOURCE_RESERVATIONS % experiment_id.to_weblab_str())
        reservation_data = {
            REQUEST_INFO: request_info,
            SERVER_INITIAL_DATA: server_initial_data,
            CLIENT_INITIAL_DATA: serialized_client_initial_data,
            EXPERIMENT_TYPE: experiment_id.to_weblab_str(),
        }
        serialized_reservation_data = json.dumps(reservation_data)
        pipeline = client.pipeline()
        pipeline.hset(weblab_reservation_status, LATEST_ACCESS, now_timestamp)
        pipeline.set(weblab_reservation, serialized_reservation_data)
        pipeline.sadd(weblab_resource_reservations, reservation_id)
        pipeline.execute()
        return reservation_id
    raise Exception(("Couldn't create a session after %s tries" % MAX_TRIES))

dataset/ETHPy150Open weblabdeusto/weblabdeusto/server/src/weblab/core/coordinator/redis/reservations_manager.py ReservationsManager.create/original