コード例 #1
0
    def add_missing_state_specs(missing_state_specs,
                                incomplete_context_response):
        missing_values = incomplete_context_response.missing_values
        for state_spec in missing_state_specs:
            missing_value = missing_values.add()
            missing_value.state_name = state_spec.name

            protocol_expiration_spec = FromFunction.ExpirationSpec()
            sdk_expiration_spec = state_spec.expiration
            if not sdk_expiration_spec:
                protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.NONE
            else:
                protocol_expiration_spec.expire_after_millis = sdk_expiration_spec.expire_after_millis
                if sdk_expiration_spec.expire_mode is Expiration.Mode.AFTER_INVOKE:
                    protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_INVOKE
                elif sdk_expiration_spec.expire_mode is Expiration.Mode.AFTER_WRITE:
                    protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_WRITE
                else:
                    raise ValueError("Unexpected state expiration mode.")
            missing_value.expiration_spec.CopyFrom(protocol_expiration_spec)
コード例 #2
0
def collect_failure(missing_state_specs: typing.List[ValueSpec]) -> FromFunction:
    pb_from_function = FromFunction()
    incomplete_context = pb_from_function.incomplete_invocation_context
    missing_values = incomplete_context.missing_values
    for state_spec in missing_state_specs:
        missing_value = missing_values.add()
        missing_value.state_name = state_spec.name
        missing_value.type_typename = state_spec.type.typename

        protocol_expiration_spec = FromFunction.ExpirationSpec()
        if not state_spec.after_write and not state_spec.after_call:
            protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.NONE
        else:
            protocol_expiration_spec.expire_after_millis = state_spec.duration
            if state_spec.after_call:
                protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_INVOKE
            elif state_spec.after_write:
                protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_WRITE
            else:
                raise ValueError("Unexpected state expiration mode.")
        missing_value.expiration_spec.CopyFrom(protocol_expiration_spec)
    return pb_from_function
コード例 #3
0
    def add_missing_state_specs(missing_state_specs,
                                incomplete_context_response):
        missing_values = incomplete_context_response.missing_values
        for state_spec in missing_state_specs:
            missing_value = missing_values.add()
            missing_value.state_name = state_spec.name

            # TODO see the comment in typed_value_utils.from_proto_any_state on
            # TODO the reason to use this specific typename
            missing_value.type_typename = "type.googleapis.com/google.protobuf.Any"

            protocol_expiration_spec = FromFunction.ExpirationSpec()
            sdk_expiration_spec = state_spec.expiration
            if not sdk_expiration_spec:
                protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.NONE
            else:
                protocol_expiration_spec.expire_after_millis = sdk_expiration_spec.expire_after_millis
                if sdk_expiration_spec.expire_mode is Expiration.Mode.AFTER_INVOKE:
                    protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_INVOKE
                elif sdk_expiration_spec.expire_mode is Expiration.Mode.AFTER_WRITE:
                    protocol_expiration_spec.mode = FromFunction.ExpirationSpec.ExpireMode.AFTER_WRITE
                else:
                    raise ValueError("Unexpected state expiration mode.")
            missing_value.expiration_spec.CopyFrom(protocol_expiration_spec)