use crate::{
ActivityHeartbeatResponse, ActivityIdentifier, WorkflowCancelOptions, WorkflowCountOptions,
WorkflowDescribeOptions, WorkflowFetchHistoryOptions, WorkflowQueryOptions,
WorkflowSignalOptions, WorkflowStartError, WorkflowStartOptions, WorkflowStartUpdateOptions,
WorkflowTerminateOptions,
errors::{
AsyncActivityError, ClientError, WorkflowInteractionError, WorkflowQueryError,
WorkflowUpdateError,
},
schedules::{
CreateScheduleOptions, ScheduleBackfill, ScheduleError, ScheduleOverlapPolicy,
ScheduleUpdate,
},
};
use futures_util::future::BoxFuture;
use std::{any::Any, sync::Arc};
use temporalio_common::{
data_converters::{
GenericPayloadConverter, PayloadConversionError, SerializationContext, TemporalSerializable,
},
protos::temporal::api::{
common::v1::Payload,
history::v1::HistoryEvent,
schedule::v1::ScheduleListEntry,
update::v1::Outcome,
workflow::v1::WorkflowExecutionInfo,
workflowservice::v1::{
CountWorkflowExecutionsResponse, DescribeScheduleResponse,
DescribeWorkflowExecutionResponse, QueryWorkflowResponse,
},
},
};
mod temporal_client_value {
use super::*;
pub trait Sealed {
fn serialize_client_payloads(
&self,
context: &SerializationContext<'_>,
) -> Result<Vec<Payload>, PayloadConversionError>;
}
impl<T> Sealed for T
where
T: Any + TemporalSerializable + Send,
{
fn serialize_client_payloads(
&self,
context: &SerializationContext<'_>,
) -> Result<Vec<Payload>, PayloadConversionError> {
context.converter.to_payloads(context, self)
}
}
}
pub trait TemporalClientValue: Any + Send + temporal_client_value::Sealed {
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
impl<T> TemporalClientValue for T
where
T: Any + TemporalSerializable + Send,
{
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl dyn TemporalClientValue {
pub(crate) fn serialize_payloads(
&self,
context: &SerializationContext<'_>,
) -> Result<Vec<Payload>, PayloadConversionError> {
temporal_client_value::Sealed::serialize_client_payloads(self, context)
}
}
pub trait HasArgs {
fn args_ref<T: Any>(&self) -> Option<&T>;
fn args_mut<T: Any>(&mut self) -> Option<&mut T>;
fn replace_args<T>(&mut self, args: T)
where
T: TemporalSerializable + Send + 'static;
}
macro_rules! impl_with_args {
($input:ty) => {
impl HasArgs for $input {
fn args_ref<T: Any>(&self) -> Option<&T> {
self.args.as_any().downcast_ref()
}
fn args_mut<T: Any>(&mut self) -> Option<&mut T> {
self.args.as_any_mut().downcast_mut()
}
fn replace_args<T>(&mut self, args: T)
where
T: TemporalSerializable + Send + 'static,
{
self.args = Box::new(args);
}
}
};
}
pub struct Next<'a, I, O> {
inner: Box<dyn FnOnce(I) -> O + Send + 'a>,
}
impl<'a, I, O> Next<'a, I, O> {
pub(crate) fn new(f: impl FnOnce(I) -> O + Send + 'a) -> Self {
Self { inner: Box::new(f) }
}
pub fn run(self, input: I) -> O {
(self.inner)(input)
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct StartWorkflowInput {
pub workflow_type: String,
pub options: WorkflowStartOptions,
pub rpc_options: crate::RpcOptions,
#[debug(skip)]
args: Box<dyn TemporalClientValue>,
}
impl StartWorkflowInput {
pub(crate) fn new<T>(workflow_type: String, args: T, mut options: WorkflowStartOptions) -> Self
where
T: TemporalSerializable + Send + 'static,
{
let rpc_options = std::mem::take(&mut options.rpc_options);
Self {
workflow_type,
options,
rpc_options,
args: Box::new(args),
}
}
pub(crate) fn into_parts(
self,
) -> (
String,
Box<dyn TemporalClientValue>,
WorkflowStartOptions,
crate::RpcOptions,
) {
(
self.workflow_type,
self.args,
self.options,
self.rpc_options,
)
}
}
impl_with_args!(StartWorkflowInput);
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StartWorkflowOutput {
pub workflow_id: String,
pub run_id: String,
}
impl StartWorkflowOutput {
pub(crate) fn new(workflow_id: impl Into<String>, run_id: impl Into<String>) -> Self {
Self {
workflow_id: workflow_id.into(),
run_id: run_id.into(),
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct ListWorkflowsPageInput {
pub query: String,
pub next_page_token: Vec<u8>,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct ListWorkflowsPageOutput {
pub executions: Vec<WorkflowExecutionInfo>,
pub next_page_token: Vec<u8>,
}
impl ListWorkflowsPageOutput {
pub(crate) fn new(executions: Vec<WorkflowExecutionInfo>, next_page_token: Vec<u8>) -> Self {
Self {
executions,
next_page_token,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct CountWorkflowsInput {
pub query: String,
pub options: WorkflowCountOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct CountWorkflowsOutput {
pub response: CountWorkflowExecutionsResponse,
}
impl CountWorkflowsOutput {
pub(crate) fn new(response: CountWorkflowExecutionsResponse) -> Self {
Self { response }
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DescribeWorkflowInput {
pub workflow_id: String,
pub run_id: String,
pub options: WorkflowDescribeOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DescribeWorkflowOutput {
pub response: DescribeWorkflowExecutionResponse,
}
impl DescribeWorkflowOutput {
pub(crate) fn new(response: DescribeWorkflowExecutionResponse) -> Self {
Self { response }
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct FetchWorkflowHistoryPageInput {
pub workflow_id: String,
pub run_id: String,
pub next_page_token: Vec<u8>,
pub options: WorkflowFetchHistoryOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct FetchWorkflowHistoryPageOutput {
pub events: Vec<HistoryEvent>,
pub next_page_token: Vec<u8>,
}
impl FetchWorkflowHistoryPageOutput {
pub(crate) fn new(events: Vec<HistoryEvent>, next_page_token: Vec<u8>) -> Self {
Self {
events,
next_page_token,
}
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct SignalWorkflowInput {
pub workflow_id: String,
pub run_id: String,
pub signal_name: String,
pub options: WorkflowSignalOptions,
#[debug(skip)]
args: Box<dyn TemporalClientValue>,
}
impl SignalWorkflowInput {
pub(crate) fn new<T>(
workflow_id: String,
run_id: String,
signal_name: String,
args: T,
options: WorkflowSignalOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
workflow_id,
run_id,
signal_name,
options,
args: Box::new(args),
}
}
pub(crate) fn into_parts(
self,
) -> (
String,
String,
String,
Box<dyn TemporalClientValue>,
WorkflowSignalOptions,
) {
(
self.workflow_id,
self.run_id,
self.signal_name,
self.args,
self.options,
)
}
}
impl_with_args!(SignalWorkflowInput);
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct QueryWorkflowInput {
pub workflow_id: String,
pub run_id: String,
pub query_name: String,
pub options: WorkflowQueryOptions,
#[debug(skip)]
args: Box<dyn TemporalClientValue>,
}
impl QueryWorkflowInput {
pub(crate) fn new<T>(
workflow_id: String,
run_id: String,
query_name: String,
args: T,
options: WorkflowQueryOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
workflow_id,
run_id,
query_name,
options,
args: Box::new(args),
}
}
pub(crate) fn into_parts(
self,
) -> (
String,
String,
String,
Box<dyn TemporalClientValue>,
WorkflowQueryOptions,
) {
(
self.workflow_id,
self.run_id,
self.query_name,
self.args,
self.options,
)
}
}
impl_with_args!(QueryWorkflowInput);
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct QueryWorkflowOutput {
pub response: QueryWorkflowResponse,
}
impl QueryWorkflowOutput {
pub(crate) fn new(response: QueryWorkflowResponse) -> Self {
Self { response }
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct StartWorkflowUpdateInput {
pub workflow_id: String,
pub run_id: String,
pub update_name: String,
pub options: WorkflowStartUpdateOptions,
#[debug(skip)]
args: Box<dyn TemporalClientValue>,
}
impl StartWorkflowUpdateInput {
pub(crate) fn new<T>(
workflow_id: String,
run_id: String,
update_name: String,
args: T,
options: WorkflowStartUpdateOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
workflow_id,
run_id,
update_name,
options,
args: Box::new(args),
}
}
pub(crate) fn into_parts(
self,
) -> (
String,
String,
String,
Box<dyn TemporalClientValue>,
WorkflowStartUpdateOptions,
) {
(
self.workflow_id,
self.run_id,
self.update_name,
self.args,
self.options,
)
}
}
impl_with_args!(StartWorkflowUpdateInput);
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct StartWorkflowUpdateOutput {
pub update_id: String,
pub workflow_id: String,
pub run_id: Option<String>,
pub known_outcome: Option<Outcome>,
}
impl StartWorkflowUpdateOutput {
pub(crate) fn new(
update_id: impl Into<String>,
workflow_id: impl Into<String>,
run_id: Option<String>,
known_outcome: Option<Outcome>,
) -> Self {
Self {
update_id: update_id.into(),
workflow_id: workflow_id.into(),
run_id,
known_outcome,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct PollWorkflowUpdateInput {
pub update_id: String,
pub workflow_id: String,
pub run_id: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct PollWorkflowUpdateOutput {
pub outcome: Outcome,
}
impl PollWorkflowUpdateOutput {
pub(crate) fn new(outcome: Outcome) -> Self {
Self { outcome }
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct CancelWorkflowInput {
pub workflow_id: String,
pub run_id: String,
pub first_execution_run_id: String,
pub options: WorkflowCancelOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct TerminateWorkflowInput {
pub workflow_id: String,
pub run_id: String,
pub first_execution_run_id: String,
pub options: WorkflowTerminateOptions,
}
#[non_exhaustive]
#[derive(Debug)]
pub struct CreateScheduleInput {
pub schedule_id: String,
pub options: CreateScheduleOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CreateScheduleOutput {
pub schedule_id: String,
}
impl CreateScheduleOutput {
pub(crate) fn new(schedule_id: impl Into<String>) -> Self {
Self {
schedule_id: schedule_id.into(),
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct ListSchedulesPageInput {
pub maximum_page_size: i32,
pub query: String,
pub next_page_token: Vec<u8>,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct ListSchedulesPageOutput {
pub schedules: Vec<ScheduleListEntry>,
pub next_page_token: Vec<u8>,
}
impl ListSchedulesPageOutput {
pub(crate) fn new(schedules: Vec<ScheduleListEntry>, next_page_token: Vec<u8>) -> Self {
Self {
schedules,
next_page_token,
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DescribeScheduleInput {
pub schedule_id: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DescribeScheduleOutput {
pub response: DescribeScheduleResponse,
}
impl DescribeScheduleOutput {
pub(crate) fn new(response: DescribeScheduleResponse) -> Self {
Self { response }
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct UpdateScheduleInput {
pub schedule_id: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct SendScheduleUpdateInput {
pub schedule_id: String,
pub update: ScheduleUpdate,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct DeleteScheduleInput {
pub schedule_id: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct PauseScheduleInput {
pub schedule_id: String,
pub note: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct UnpauseScheduleInput {
pub schedule_id: String,
pub note: String,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct TriggerScheduleInput {
pub schedule_id: String,
pub overlap_policy: ScheduleOverlapPolicy,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct BackfillScheduleInput {
pub schedule_id: String,
pub backfills: Vec<ScheduleBackfill>,
pub rpc_options: crate::RpcOptions,
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct CompleteAsyncActivityInput {
pub identifier: ActivityIdentifier,
#[debug(skip)]
result: Option<Box<dyn TemporalClientValue>>,
pub rpc_options: crate::RpcOptions,
}
impl CompleteAsyncActivityInput {
pub(crate) fn new<T>(
identifier: ActivityIdentifier,
result: Option<T>,
rpc_options: crate::RpcOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
identifier,
result: result.map(|value| Box::new(value) as Box<dyn TemporalClientValue>),
rpc_options,
}
}
pub(crate) fn into_parts(
self,
) -> (
ActivityIdentifier,
Option<Box<dyn TemporalClientValue>>,
crate::RpcOptions,
) {
(self.identifier, self.result, self.rpc_options)
}
pub fn result_ref<T: Any>(&self) -> Option<&T> {
self.result
.as_ref()
.and_then(|result| result.as_any().downcast_ref())
}
pub fn result_mut<T: Any>(&mut self) -> Option<&mut T> {
self.result
.as_mut()
.and_then(|result| result.as_any_mut().downcast_mut())
}
pub fn replace_result<T>(&mut self, result: Option<T>)
where
T: TemporalSerializable + Send + 'static,
{
self.result = result.map(|value| Box::new(value) as Box<dyn TemporalClientValue>);
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct FailAsyncActivityInput {
pub identifier: ActivityIdentifier,
pub failure: temporalio_common::error::ApplicationFailure,
#[debug(skip)]
last_heartbeat_details: Option<Box<dyn TemporalClientValue>>,
pub rpc_options: crate::RpcOptions,
}
impl FailAsyncActivityInput {
pub(crate) fn new<T>(
identifier: ActivityIdentifier,
failure: temporalio_common::error::ApplicationFailure,
last_heartbeat_details: Option<T>,
rpc_options: crate::RpcOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
identifier,
failure,
last_heartbeat_details: last_heartbeat_details
.map(|value| Box::new(value) as Box<dyn TemporalClientValue>),
rpc_options,
}
}
pub(crate) fn into_parts(
self,
) -> (
ActivityIdentifier,
temporalio_common::error::ApplicationFailure,
Option<Box<dyn TemporalClientValue>>,
crate::RpcOptions,
) {
(
self.identifier,
self.failure,
self.last_heartbeat_details,
self.rpc_options,
)
}
pub fn last_heartbeat_details_ref<T: Any>(&self) -> Option<&T> {
self.last_heartbeat_details
.as_ref()
.and_then(|details| details.as_any().downcast_ref())
}
pub fn last_heartbeat_details_mut<T: Any>(&mut self) -> Option<&mut T> {
self.last_heartbeat_details
.as_mut()
.and_then(|details| details.as_any_mut().downcast_mut())
}
pub fn replace_last_heartbeat_details<T>(&mut self, details: Option<T>)
where
T: TemporalSerializable + Send + 'static,
{
self.last_heartbeat_details =
details.map(|value| Box::new(value) as Box<dyn TemporalClientValue>);
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct ReportAsyncActivityCancellationInput {
pub identifier: ActivityIdentifier,
#[debug(skip)]
details: Option<Box<dyn TemporalClientValue>>,
pub rpc_options: crate::RpcOptions,
}
impl ReportAsyncActivityCancellationInput {
pub(crate) fn new<T>(
identifier: ActivityIdentifier,
details: Option<T>,
rpc_options: crate::RpcOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
identifier,
details: details.map(|value| Box::new(value) as Box<dyn TemporalClientValue>),
rpc_options,
}
}
pub(crate) fn into_parts(
self,
) -> (
ActivityIdentifier,
Option<Box<dyn TemporalClientValue>>,
crate::RpcOptions,
) {
(self.identifier, self.details, self.rpc_options)
}
pub fn details_ref<T: Any>(&self) -> Option<&T> {
self.details
.as_ref()
.and_then(|details| details.as_any().downcast_ref())
}
pub fn details_mut<T: Any>(&mut self) -> Option<&mut T> {
self.details
.as_mut()
.and_then(|details| details.as_any_mut().downcast_mut())
}
pub fn replace_details<T>(&mut self, details: Option<T>)
where
T: TemporalSerializable + Send + 'static,
{
self.details = details.map(|value| Box::new(value) as Box<dyn TemporalClientValue>);
}
}
#[non_exhaustive]
#[derive(derive_more::Debug)]
pub struct HeartbeatAsyncActivityInput {
pub identifier: ActivityIdentifier,
#[debug(skip)]
details: Option<Box<dyn TemporalClientValue>>,
pub rpc_options: crate::RpcOptions,
}
impl HeartbeatAsyncActivityInput {
pub(crate) fn new<T>(
identifier: ActivityIdentifier,
details: Option<T>,
rpc_options: crate::RpcOptions,
) -> Self
where
T: TemporalSerializable + Send + 'static,
{
Self {
identifier,
details: details.map(|value| Box::new(value) as Box<dyn TemporalClientValue>),
rpc_options,
}
}
pub(crate) fn into_parts(
self,
) -> (
ActivityIdentifier,
Option<Box<dyn TemporalClientValue>>,
crate::RpcOptions,
) {
(self.identifier, self.details, self.rpc_options)
}
pub fn details_ref<T: Any>(&self) -> Option<&T> {
self.details
.as_ref()
.and_then(|details| details.as_any().downcast_ref())
}
pub fn details_mut<T: Any>(&mut self) -> Option<&mut T> {
self.details
.as_mut()
.and_then(|details| details.as_any_mut().downcast_mut())
}
pub fn replace_details<T>(&mut self, details: Option<T>)
where
T: TemporalSerializable + Send + 'static,
{
self.details = details.map(|value| Box::new(value) as Box<dyn TemporalClientValue>);
}
}
pub trait ClientInterceptor: Send + Sync + 'static {
fn start_workflow<'a>(
&'a self,
input: StartWorkflowInput,
next: Next<
'a,
StartWorkflowInput,
BoxFuture<'a, Result<StartWorkflowOutput, WorkflowStartError>>,
>,
) -> BoxFuture<'a, Result<StartWorkflowOutput, WorkflowStartError>> {
next.run(input)
}
fn list_workflows_page<'a>(
&'a self,
input: ListWorkflowsPageInput,
next: Next<
'a,
ListWorkflowsPageInput,
BoxFuture<'a, Result<ListWorkflowsPageOutput, ClientError>>,
>,
) -> BoxFuture<'a, Result<ListWorkflowsPageOutput, ClientError>> {
next.run(input)
}
fn count_workflows<'a>(
&'a self,
input: CountWorkflowsInput,
next: Next<
'a,
CountWorkflowsInput,
BoxFuture<'a, Result<CountWorkflowsOutput, ClientError>>,
>,
) -> BoxFuture<'a, Result<CountWorkflowsOutput, ClientError>> {
next.run(input)
}
fn describe_workflow<'a>(
&'a self,
input: DescribeWorkflowInput,
next: Next<
'a,
DescribeWorkflowInput,
BoxFuture<'a, Result<DescribeWorkflowOutput, WorkflowInteractionError>>,
>,
) -> BoxFuture<'a, Result<DescribeWorkflowOutput, WorkflowInteractionError>> {
next.run(input)
}
fn fetch_workflow_history_page<'a>(
&'a self,
input: FetchWorkflowHistoryPageInput,
next: Next<
'a,
FetchWorkflowHistoryPageInput,
BoxFuture<'a, Result<FetchWorkflowHistoryPageOutput, WorkflowInteractionError>>,
>,
) -> BoxFuture<'a, Result<FetchWorkflowHistoryPageOutput, WorkflowInteractionError>> {
next.run(input)
}
fn signal_workflow<'a>(
&'a self,
input: SignalWorkflowInput,
next: Next<'a, SignalWorkflowInput, BoxFuture<'a, Result<(), WorkflowInteractionError>>>,
) -> BoxFuture<'a, Result<(), WorkflowInteractionError>> {
next.run(input)
}
fn query_workflow<'a>(
&'a self,
input: QueryWorkflowInput,
next: Next<
'a,
QueryWorkflowInput,
BoxFuture<'a, Result<QueryWorkflowOutput, WorkflowQueryError>>,
>,
) -> BoxFuture<'a, Result<QueryWorkflowOutput, WorkflowQueryError>> {
next.run(input)
}
fn start_workflow_update<'a>(
&'a self,
input: StartWorkflowUpdateInput,
next: Next<
'a,
StartWorkflowUpdateInput,
BoxFuture<'a, Result<StartWorkflowUpdateOutput, WorkflowUpdateError>>,
>,
) -> BoxFuture<'a, Result<StartWorkflowUpdateOutput, WorkflowUpdateError>> {
next.run(input)
}
fn poll_workflow_update<'a>(
&'a self,
input: PollWorkflowUpdateInput,
next: Next<
'a,
PollWorkflowUpdateInput,
BoxFuture<'a, Result<PollWorkflowUpdateOutput, WorkflowUpdateError>>,
>,
) -> BoxFuture<'a, Result<PollWorkflowUpdateOutput, WorkflowUpdateError>> {
next.run(input)
}
fn cancel_workflow<'a>(
&'a self,
input: CancelWorkflowInput,
next: Next<'a, CancelWorkflowInput, BoxFuture<'a, Result<(), WorkflowInteractionError>>>,
) -> BoxFuture<'a, Result<(), WorkflowInteractionError>> {
next.run(input)
}
fn terminate_workflow<'a>(
&'a self,
input: TerminateWorkflowInput,
next: Next<'a, TerminateWorkflowInput, BoxFuture<'a, Result<(), WorkflowInteractionError>>>,
) -> BoxFuture<'a, Result<(), WorkflowInteractionError>> {
next.run(input)
}
fn create_schedule<'a>(
&'a self,
input: CreateScheduleInput,
next: Next<
'a,
CreateScheduleInput,
BoxFuture<'a, Result<CreateScheduleOutput, ScheduleError>>,
>,
) -> BoxFuture<'a, Result<CreateScheduleOutput, ScheduleError>> {
next.run(input)
}
fn list_schedules_page<'a>(
&'a self,
input: ListSchedulesPageInput,
next: Next<
'a,
ListSchedulesPageInput,
BoxFuture<'a, Result<ListSchedulesPageOutput, ScheduleError>>,
>,
) -> BoxFuture<'a, Result<ListSchedulesPageOutput, ScheduleError>> {
next.run(input)
}
fn describe_schedule<'a>(
&'a self,
input: DescribeScheduleInput,
next: Next<
'a,
DescribeScheduleInput,
BoxFuture<'a, Result<DescribeScheduleOutput, ScheduleError>>,
>,
) -> BoxFuture<'a, Result<DescribeScheduleOutput, ScheduleError>> {
next.run(input)
}
fn update_schedule<'a>(
&'a self,
input: UpdateScheduleInput,
next: Next<'a, UpdateScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn send_schedule_update<'a>(
&'a self,
input: SendScheduleUpdateInput,
next: Next<'a, SendScheduleUpdateInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn delete_schedule<'a>(
&'a self,
input: DeleteScheduleInput,
next: Next<'a, DeleteScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn pause_schedule<'a>(
&'a self,
input: PauseScheduleInput,
next: Next<'a, PauseScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn unpause_schedule<'a>(
&'a self,
input: UnpauseScheduleInput,
next: Next<'a, UnpauseScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn trigger_schedule<'a>(
&'a self,
input: TriggerScheduleInput,
next: Next<'a, TriggerScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn backfill_schedule<'a>(
&'a self,
input: BackfillScheduleInput,
next: Next<'a, BackfillScheduleInput, BoxFuture<'a, Result<(), ScheduleError>>>,
) -> BoxFuture<'a, Result<(), ScheduleError>> {
next.run(input)
}
fn complete_async_activity<'a>(
&'a self,
input: CompleteAsyncActivityInput,
next: Next<'a, CompleteAsyncActivityInput, BoxFuture<'a, Result<(), AsyncActivityError>>>,
) -> BoxFuture<'a, Result<(), AsyncActivityError>> {
next.run(input)
}
fn fail_async_activity<'a>(
&'a self,
input: FailAsyncActivityInput,
next: Next<'a, FailAsyncActivityInput, BoxFuture<'a, Result<(), AsyncActivityError>>>,
) -> BoxFuture<'a, Result<(), AsyncActivityError>> {
next.run(input)
}
fn report_async_activity_cancellation<'a>(
&'a self,
input: ReportAsyncActivityCancellationInput,
next: Next<
'a,
ReportAsyncActivityCancellationInput,
BoxFuture<'a, Result<(), AsyncActivityError>>,
>,
) -> BoxFuture<'a, Result<(), AsyncActivityError>> {
next.run(input)
}
fn heartbeat_async_activity<'a>(
&'a self,
input: HeartbeatAsyncActivityInput,
next: Next<
'a,
HeartbeatAsyncActivityInput,
BoxFuture<'a, Result<ActivityHeartbeatResponse, AsyncActivityError>>,
>,
) -> BoxFuture<'a, Result<ActivityHeartbeatResponse, AsyncActivityError>> {
next.run(input)
}
}
macro_rules! interceptor_chain {
($fn_name:ident, $method:ident, $input:ty, $output:ty) => {
pub(crate) fn $fn_name<'a>(
interceptors: &'a [Arc<dyn ClientInterceptor>],
input: $input,
terminal: Next<'a, $input, $output>,
) -> $output {
if let Some((interceptor, remaining)) = interceptors.split_first() {
let next = Next::new(move |input| $fn_name(remaining, input, terminal));
interceptor.$method(input, next)
} else {
terminal.run(input)
}
}
};
}
interceptor_chain!(
call_start_workflow,
start_workflow,
StartWorkflowInput,
BoxFuture<'a, Result<StartWorkflowOutput, WorkflowStartError>>
);
interceptor_chain!(
call_list_workflows_page,
list_workflows_page,
ListWorkflowsPageInput,
BoxFuture<'a, Result<ListWorkflowsPageOutput, ClientError>>
);
interceptor_chain!(
call_count_workflows,
count_workflows,
CountWorkflowsInput,
BoxFuture<'a, Result<CountWorkflowsOutput, ClientError>>
);
interceptor_chain!(
call_describe_workflow,
describe_workflow,
DescribeWorkflowInput,
BoxFuture<'a, Result<DescribeWorkflowOutput, WorkflowInteractionError>>
);
interceptor_chain!(
call_fetch_workflow_history_page,
fetch_workflow_history_page,
FetchWorkflowHistoryPageInput,
BoxFuture<'a, Result<FetchWorkflowHistoryPageOutput, WorkflowInteractionError>>
);
interceptor_chain!(
call_signal_workflow,
signal_workflow,
SignalWorkflowInput,
BoxFuture<'a, Result<(), WorkflowInteractionError>>
);
interceptor_chain!(
call_query_workflow,
query_workflow,
QueryWorkflowInput,
BoxFuture<'a, Result<QueryWorkflowOutput, WorkflowQueryError>>
);
interceptor_chain!(
call_start_workflow_update,
start_workflow_update,
StartWorkflowUpdateInput,
BoxFuture<'a, Result<StartWorkflowUpdateOutput, WorkflowUpdateError>>
);
interceptor_chain!(
call_poll_workflow_update,
poll_workflow_update,
PollWorkflowUpdateInput,
BoxFuture<'a, Result<PollWorkflowUpdateOutput, WorkflowUpdateError>>
);
interceptor_chain!(
call_cancel_workflow,
cancel_workflow,
CancelWorkflowInput,
BoxFuture<'a, Result<(), WorkflowInteractionError>>
);
interceptor_chain!(
call_terminate_workflow,
terminate_workflow,
TerminateWorkflowInput,
BoxFuture<'a, Result<(), WorkflowInteractionError>>
);
interceptor_chain!(
call_create_schedule,
create_schedule,
CreateScheduleInput,
BoxFuture<'a, Result<CreateScheduleOutput, ScheduleError>>
);
interceptor_chain!(
call_list_schedules_page,
list_schedules_page,
ListSchedulesPageInput,
BoxFuture<'a, Result<ListSchedulesPageOutput, ScheduleError>>
);
interceptor_chain!(
call_describe_schedule,
describe_schedule,
DescribeScheduleInput,
BoxFuture<'a, Result<DescribeScheduleOutput, ScheduleError>>
);
interceptor_chain!(
call_update_schedule,
update_schedule,
UpdateScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_send_schedule_update,
send_schedule_update,
SendScheduleUpdateInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_delete_schedule,
delete_schedule,
DeleteScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_pause_schedule,
pause_schedule,
PauseScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_unpause_schedule,
unpause_schedule,
UnpauseScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_trigger_schedule,
trigger_schedule,
TriggerScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_backfill_schedule,
backfill_schedule,
BackfillScheduleInput,
BoxFuture<'a, Result<(), ScheduleError>>
);
interceptor_chain!(
call_complete_async_activity,
complete_async_activity,
CompleteAsyncActivityInput,
BoxFuture<'a, Result<(), AsyncActivityError>>
);
interceptor_chain!(
call_fail_async_activity,
fail_async_activity,
FailAsyncActivityInput,
BoxFuture<'a, Result<(), AsyncActivityError>>
);
interceptor_chain!(
call_report_async_activity_cancellation,
report_async_activity_cancellation,
ReportAsyncActivityCancellationInput,
BoxFuture<'a, Result<(), AsyncActivityError>>
);
interceptor_chain!(
call_heartbeat_async_activity,
heartbeat_async_activity,
HeartbeatAsyncActivityInput,
BoxFuture<'a, Result<ActivityHeartbeatResponse, AsyncActivityError>>
);