{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Use >=>" #-}
module Temporal.Client (
WorkflowClient,
workflowClient,
WorkflowClientConfig (..),
mkWorkflowClientConfig,
HasWorkflowClient (..),
StartWorkflowOptions (..),
TimeoutOptions (..),
startWorkflowOptions,
Temporal.Client.start,
startFromPayloads,
WorkflowHandle,
execute,
waitWorkflowResult,
TerminationOptions (..),
terminate,
QueryOptions (..),
QueryRejectCondition (..),
QueryRejected (..),
Temporal.Client.Types.WorkflowExecutionStatus (..),
defaultQueryOptions,
query,
SignalOptions (..),
KnownSignal (..),
signal,
defaultSignalOptions,
Temporal.Client.signalWithStart,
getHandle,
fetchHistory,
streamEvents,
FollowOption (..),
) where
import Conduit
import Control.Monad
import Control.Monad.Trans.Accum
import Control.Monad.Trans.Cont
import Control.Monad.Trans.Except
import Control.Monad.Trans.Identity
import Control.Monad.Trans.Maybe
import qualified Control.Monad.Trans.RWS.CPS as CRWS
import qualified Control.Monad.Trans.RWS.Lazy as LRWS
import qualified Control.Monad.Trans.RWS.Strict as SRWS
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Select
import qualified Control.Monad.Trans.State.Lazy as LS
import qualified Control.Monad.Trans.State.Strict as SS
import qualified Control.Monad.Trans.Writer.CPS as CW
import qualified Control.Monad.Trans.Writer.Lazy as LW
import qualified Control.Monad.Trans.Writer.Strict as SW
import Data.Foldable (for_)
import Data.Int (Int64)
import Data.Map (Map)
import Data.Maybe
import Data.ProtoLens.Field
import Data.ProtoLens.Message
import Data.Proxy
import Data.Text (Text)
import Data.Time.Clock.System (SystemTime)
import Data.Typeable
import qualified Data.UUID as UUID
import qualified Data.UUID.V4 as UUID
import qualified Data.Vector as V
import Lens.Family2
import qualified Proto.Temporal.Api.Common.V1.Message_Fields as Common
import qualified Proto.Temporal.Api.Enums.V1.Query as Query
import Proto.Temporal.Api.Enums.V1.TaskQueue (TaskQueueKind (..))
import Proto.Temporal.Api.Enums.V1.Workflow (HistoryEventFilterType (..), WorkflowExecutionStatus (..))
import Proto.Temporal.Api.History.V1.Message (History, HistoryEvent, HistoryEvent'Attributes (..))
import qualified Proto.Temporal.Api.History.V1.Message_Fields as History
import qualified Proto.Temporal.Api.Query.V1.Message_Fields as Query
import qualified Proto.Temporal.Api.Taskqueue.V1.Message_Fields as TQ
import Proto.Temporal.Api.Workflowservice.V1.RequestResponse (
GetWorkflowExecutionHistoryRequest,
GetWorkflowExecutionHistoryResponse,
QueryWorkflowRequest,
QueryWorkflowResponse,
)
import qualified Proto.Temporal.Api.Workflowservice.V1.RequestResponse_Fields as RR
import qualified Proto.Temporal.Api.Workflowservice.V1.RequestResponse_Fields as WF
import Temporal.Client.Types
import Temporal.Common
import qualified Temporal.Core.Client as Core
import Temporal.Core.Client.WorkflowService
import Temporal.Duration (Duration, durationToProto)
import Temporal.Exception
import Temporal.Payload
import Temporal.SearchAttributes.Internal
import Temporal.Workflow (KnownQuery (..), KnownSignal (..), QueryRef (..))
import Temporal.Workflow.Definition
import UnliftIO
import Unsafe.Coerce
workflowClient
:: MonadIO m
=> Core.Client
-> WorkflowClientConfig
-> m WorkflowClient
workflowClient :: forall (m :: * -> *).
MonadIO m =>
Client -> WorkflowClientConfig -> m WorkflowClient
workflowClient Client
c WorkflowClientConfig
conf = do
WorkflowClient -> m WorkflowClient
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
WorkflowClient
{ clientCore :: Client
clientCore = Client
c
, clientConfig :: WorkflowClientConfig
clientConfig = WorkflowClientConfig
conf
}
class HasWorkflowClient m where
askWorkflowClient :: m WorkflowClient
instance {-# OVERLAPS #-} Monad m => HasWorkflowClient (ReaderT WorkflowClient m) where
askWorkflowClient :: ReaderT WorkflowClient m WorkflowClient
askWorkflowClient = ReaderT WorkflowClient m WorkflowClient
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
instance (Monad m, HasWorkflowClient m, Monoid w) => HasWorkflowClient (AccumT w m) where
askWorkflowClient :: AccumT w m WorkflowClient
askWorkflowClient = m WorkflowClient -> AccumT w m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> AccumT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (ReaderT r m) where
askWorkflowClient :: ReaderT r m WorkflowClient
askWorkflowClient = m WorkflowClient -> ReaderT r m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (CRWS.RWST r w s m) where
askWorkflowClient :: RWST r w s m WorkflowClient
askWorkflowClient = m WorkflowClient -> RWST r w s m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance {-# OVERLAPS #-} (Monad m) => HasWorkflowClient (CRWS.RWST WorkflowClient w s m) where
askWorkflowClient :: RWST WorkflowClient w s m WorkflowClient
askWorkflowClient = RWST WorkflowClient w s m WorkflowClient
forall (m :: * -> *) r w s. Monad m => RWST r w s m r
CRWS.ask
instance (Monad m, HasWorkflowClient m, Monoid w) => HasWorkflowClient (LRWS.RWST r w s m) where
askWorkflowClient :: RWST r w s m WorkflowClient
askWorkflowClient = m WorkflowClient -> RWST r w s m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance {-# OVERLAPS #-} (Monad m, Monoid w) => HasWorkflowClient (LRWS.RWST WorkflowClient w s m) where
askWorkflowClient :: RWST WorkflowClient w s m WorkflowClient
askWorkflowClient = RWST WorkflowClient w s m WorkflowClient
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
LRWS.ask
instance (Monad m, HasWorkflowClient m, Monoid w) => HasWorkflowClient (SRWS.RWST r w s m) where
askWorkflowClient :: RWST r w s m WorkflowClient
askWorkflowClient = m WorkflowClient -> RWST r w s m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance {-# OVERLAPS #-} (Monad m, Monoid w) => HasWorkflowClient (SRWS.RWST WorkflowClient w s m) where
askWorkflowClient :: RWST WorkflowClient w s m WorkflowClient
askWorkflowClient = RWST WorkflowClient w s m WorkflowClient
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
SRWS.ask
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (CW.WriterT w m) where
askWorkflowClient :: WriterT w m WorkflowClient
askWorkflowClient = m WorkflowClient -> WriterT w m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m, Monoid w) => HasWorkflowClient (LW.WriterT w m) where
askWorkflowClient :: WriterT w m WorkflowClient
askWorkflowClient = m WorkflowClient -> WriterT w m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m, Monoid w) => HasWorkflowClient (SW.WriterT w m) where
askWorkflowClient :: WriterT w m WorkflowClient
askWorkflowClient = m WorkflowClient -> WriterT w m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (LS.StateT s m) where
askWorkflowClient :: StateT s m WorkflowClient
askWorkflowClient = m WorkflowClient -> StateT s m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (SS.StateT s m) where
askWorkflowClient :: StateT s m WorkflowClient
askWorkflowClient = m WorkflowClient -> StateT s m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (ExceptT e m) where
askWorkflowClient :: ExceptT e m WorkflowClient
askWorkflowClient = m WorkflowClient -> ExceptT e m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (IdentityT m) where
askWorkflowClient :: IdentityT m WorkflowClient
askWorkflowClient = m WorkflowClient -> IdentityT m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (ContT r m) where
askWorkflowClient :: ContT r m WorkflowClient
askWorkflowClient = m WorkflowClient -> ContT r m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (MaybeT m) where
askWorkflowClient :: MaybeT m WorkflowClient
askWorkflowClient = m WorkflowClient -> MaybeT m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (SelectT r m) where
askWorkflowClient :: SelectT r m WorkflowClient
askWorkflowClient = m WorkflowClient -> SelectT r m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> SelectT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance (Monad m, HasWorkflowClient m) => HasWorkflowClient (ConduitT i o m) where
askWorkflowClient :: ConduitT i o m WorkflowClient
askWorkflowClient = m WorkflowClient -> ConduitT i o m WorkflowClient
forall (m :: * -> *) a. Monad m => m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
instance HasWorkflowClient ((->) WorkflowClient) where
askWorkflowClient :: WorkflowClient -> WorkflowClient
askWorkflowClient = WorkflowClient -> WorkflowClient
forall a. a -> a
id
throwEither :: (MonadIO m, Exception e) => IO (Either e a) -> m a
throwEither :: forall (m :: * -> *) e a.
(MonadIO m, Exception e) =>
IO (Either e a) -> m a
throwEither = (e -> m a) -> (a -> m a) -> Either e a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either e -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either e a -> m a)
-> (IO (Either e a) -> m (Either e a)) -> IO (Either e a) -> m a
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< IO (Either e a) -> m (Either e a)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
execute
:: forall m wf
. (HasWorkflowClient m, MonadIO m, WorkflowRef wf)
=> wf
-> WorkflowId
-> StartWorkflowOptions
-> (WorkflowArgs wf :->: m (WorkflowResult wf))
execute :: forall (m :: * -> *) wf.
(HasWorkflowClient m, MonadIO m, WorkflowRef wf) =>
wf
-> WorkflowId
-> StartWorkflowOptions
-> WorkflowArgs wf :->: m (WorkflowResult wf)
execute (wf -> KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
forall f.
WorkflowRef f =>
f -> KnownWorkflow (WorkflowArgs f) (WorkflowResult f)
workflowRef -> k :: KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k@(KnownWorkflow codec
codec Text
_)) WorkflowId
wfId StartWorkflowOptions
opts = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(WorkflowArgs wf) @(m (WorkflowResult wf)) codec
codec ((Vector UnencodedPayload -> m (WorkflowResult wf))
-> WorkflowArgs wf :->: m (WorkflowResult wf))
-> (Vector UnencodedPayload -> m (WorkflowResult wf))
-> WorkflowArgs wf :->: m (WorkflowResult wf)
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
inputs -> do
h <- KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
-> WorkflowId
-> StartWorkflowOptions
-> Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf))
forall (m :: * -> *) (args :: [*]) result.
(MonadIO m, HasWorkflowClient m) =>
KnownWorkflow args result
-> WorkflowId
-> StartWorkflowOptions
-> Vector UnencodedPayload
-> m (WorkflowHandle result)
startFromPayloads KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k WorkflowId
wfId StartWorkflowOptions
opts Vector UnencodedPayload
inputs
waitWorkflowResult h
waitWorkflowResult :: (Typeable a, MonadIO m) => WorkflowHandle a -> m a
waitWorkflowResult :: forall a (m :: * -> *).
(Typeable a, MonadIO m) =>
WorkflowHandle a -> m a
waitWorkflowResult h :: WorkflowHandle a
h@(WorkflowHandle Payload -> IO a
readResult WorkflowType
_ WorkflowClient
c WorkflowId
wf Maybe RunId
r) = do
mev <- ReaderT WorkflowClient m (Maybe HistoryEvent)
-> WorkflowClient -> m (Maybe HistoryEvent)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (WorkflowId
-> Maybe RunId
-> Namespace
-> ReaderT WorkflowClient m (Maybe HistoryEvent)
forall (m :: * -> *).
(MonadIO m, HasWorkflowClient m) =>
WorkflowId -> Maybe RunId -> Namespace -> m (Maybe HistoryEvent)
waitResult WorkflowId
wf Maybe RunId
r WorkflowClient
c.clientConfig.namespace) WorkflowClient
c
case mev of
Maybe HistoryEvent
Nothing -> [Char] -> m a
forall a. HasCallStack => [Char] -> a
error [Char]
"Unexpected empty history"
Just HistoryEvent
ev -> case HistoryEvent
ev HistoryEvent
-> FoldLike
(Maybe HistoryEvent'Attributes)
HistoryEvent
HistoryEvent
(Maybe HistoryEvent'Attributes)
(Maybe HistoryEvent'Attributes)
-> Maybe HistoryEvent'Attributes
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
(Maybe HistoryEvent'Attributes)
HistoryEvent
HistoryEvent
(Maybe HistoryEvent'Attributes)
(Maybe HistoryEvent'Attributes)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'attributes" a) =>
LensLike' f s a
History.maybe'attributes of
Maybe HistoryEvent'Attributes
Nothing -> [Char] -> m a
forall a. HasCallStack => [Char] -> a
error [Char]
"Unrecognized history event"
Just HistoryEvent'Attributes
attrType -> case HistoryEvent'Attributes
attrType of
HistoryEvent'WorkflowExecutionCompletedEventAttributes WorkflowExecutionCompletedEventAttributes
attrs -> do
let payloads :: [Payload]
payloads = Payload -> Payload
convertFromProtoPayload (Payload -> Payload) -> [Payload] -> [Payload]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (WorkflowExecutionCompletedEventAttributes
attrs WorkflowExecutionCompletedEventAttributes
-> FoldLike
[Payload]
WorkflowExecutionCompletedEventAttributes
WorkflowExecutionCompletedEventAttributes
[Payload]
[Payload]
-> [Payload]
forall s a t b. s -> FoldLike a s t a b -> a
^. LensLike'
(Constant [Payload])
WorkflowExecutionCompletedEventAttributes
Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "result" a) =>
LensLike' f s a
History.result LensLike'
(Constant [Payload])
WorkflowExecutionCompletedEventAttributes
Payloads
-> (([Payload] -> Constant [Payload] [Payload])
-> Payloads -> Constant [Payload] Payloads)
-> FoldLike
[Payload]
WorkflowExecutionCompletedEventAttributes
WorkflowExecutionCompletedEventAttributes
[Payload]
[Payload]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Payload] -> Constant [Payload] [Payload])
-> Payloads -> Constant [Payload] Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "payloads" a) =>
LensLike' f s a
Common.payloads)
if WorkflowHandle a -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep WorkflowHandle a
h TypeRep -> TypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== () -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf ()
then a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> m a) -> a -> m a
forall a b. (a -> b) -> a -> b
$ () -> a
forall a b. a -> b
unsafeCoerce ()
else case [Payload]
payloads of
(Payload
a : [Payload]
_) -> IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> IO a -> m a
forall a b. (a -> b) -> a -> b
$ Payload -> IO a
readResult Payload
a
[Payload]
_ -> [Char] -> m a
forall a. HasCallStack => [Char] -> a
error [Char]
"Missing result payload"
HistoryEvent'WorkflowExecutionFailedEventAttributes WorkflowExecutionFailedEventAttributes
attrs ->
WorkflowExecutionClosed -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (WorkflowExecutionClosed -> m a) -> WorkflowExecutionClosed -> m a
forall a b. (a -> b) -> a -> b
$ WorkflowExecutionFailedEventAttributes -> WorkflowExecutionClosed
WorkflowExecutionFailed WorkflowExecutionFailedEventAttributes
attrs
HistoryEvent'WorkflowExecutionTimedOutEventAttributes WorkflowExecutionTimedOutEventAttributes
_attrs -> WorkflowExecutionClosed -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO WorkflowExecutionClosed
WorkflowExecutionTimedOut
HistoryEvent'WorkflowExecutionCanceledEventAttributes WorkflowExecutionCanceledEventAttributes
_attrs -> WorkflowExecutionClosed -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO WorkflowExecutionClosed
WorkflowExecutionCanceled
HistoryEvent'WorkflowExecutionTerminatedEventAttributes WorkflowExecutionTerminatedEventAttributes
_attrs -> WorkflowExecutionClosed -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO WorkflowExecutionClosed
WorkflowExecutionTerminated
HistoryEvent'WorkflowExecutionContinuedAsNewEventAttributes WorkflowExecutionContinuedAsNewEventAttributes
_attrs -> WorkflowExecutionClosed -> m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO WorkflowExecutionClosed
WorkflowExecutionContinuedAsNew
HistoryEvent'Attributes
e -> [Char] -> m a
forall a. HasCallStack => [Char] -> a
error ([Char]
"History event not supported " [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> HistoryEvent'Attributes -> [Char]
forall a. Show a => a -> [Char]
show HistoryEvent'Attributes
e)
data SignalOptions = SignalOptions
{ SignalOptions -> Maybe Text
requestId :: Maybe Text
, SignalOptions -> Bool
skipGenerateWorkflowTask :: Bool
, :: Map Text Payload
}
defaultSignalOptions :: SignalOptions
defaultSignalOptions :: SignalOptions
defaultSignalOptions =
SignalOptions
{ skipGenerateWorkflowTask :: Bool
skipGenerateWorkflowTask = Bool
False
, requestId :: Maybe Text
requestId = Maybe Text
forall a. Maybe a
Nothing
, headers :: Map Text Payload
headers = Map Text Payload
forall a. Monoid a => a
mempty
}
signal
:: forall m sig a
. (MonadIO m, SignalRef sig)
=> WorkflowHandle a
-> sig
-> SignalOptions
-> (SignalArgs sig :->: m ())
signal :: forall (m :: * -> *) sig a.
(MonadIO m, SignalRef sig) =>
WorkflowHandle a
-> sig -> SignalOptions -> SignalArgs sig :->: m ()
signal (WorkflowHandle Payload -> IO a
_ WorkflowType
_t WorkflowClient
c WorkflowId
wf Maybe RunId
r) (sig -> KnownSignal (SignalArgs sig)
forall sig. SignalRef sig => sig -> KnownSignal (SignalArgs sig)
signalRef -> (KnownSignal Text
sName codec
sCodec)) SignalOptions
opts = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(SignalArgs sig) @(m ()) codec
sCodec ((Vector UnencodedPayload -> m ()) -> SignalArgs sig :->: m ())
-> (Vector UnencodedPayload -> m ()) -> SignalArgs sig :->: m ()
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
inputs -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
inputs' <- PayloadProcessor -> Vector Payload -> IO (Vector Payload)
forall (m :: * -> *) (f :: * -> *).
(MonadIO m, Traversable f) =>
PayloadProcessor -> f Payload -> m (f Payload)
processorEncodePayloads WorkflowClient
c.clientConfig.payloadProcessor (Vector Payload -> IO (Vector Payload))
-> IO (Vector Payload) -> IO (Vector Payload)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO (Vector Payload) -> IO (Vector Payload)
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Vector UnencodedPayload -> IO (Vector Payload)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => Vector (m a) -> m (Vector a)
sequence Vector UnencodedPayload
inputs)
hdrs <- processorEncodePayloads c.clientConfig.payloadProcessor opts.headers
result <-
signalWorkflowExecution c.clientCore $
defMessage
& WF.namespace .~ rawNamespace c.clientConfig.namespace
& WF.workflowExecution
.~ ( defMessage
& Common.workflowId .~ rawWorkflowId wf
& Common.runId .~ maybe "" rawRunId r
)
& WF.signalName .~ sName
& WF.input .~ (defMessage & Common.vec'payloads .~ fmap convertToProtoPayload inputs')
& WF.identity .~ Core.identity (Core.clientConfig c.clientCore)
& WF.requestId .~ fromMaybe "" opts.requestId
& WF.header .~ headerToProto (fmap convertToProtoPayload hdrs)
& WF.skipGenerateWorkflowTask .~ opts.skipGenerateWorkflowTask
case result of
Left RpcError
err -> RpcError -> IO ()
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO RpcError
err
Right SignalWorkflowExecutionResponse
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
data QueryOptions = QueryOptions
{
QueryOptions -> QueryRejectCondition
queryRejectCondition :: QueryRejectCondition
, :: Map Text Payload
}
defaultQueryOptions :: QueryOptions
defaultQueryOptions :: QueryOptions
defaultQueryOptions =
QueryOptions
{ queryRejectCondition :: QueryRejectCondition
queryRejectCondition = QueryRejectCondition
QueryRejectConditionRejectNone
, queryHeaders :: Map Text Payload
queryHeaders = Map Text Payload
forall a. Monoid a => a
mempty
}
query
:: forall m query a
. (MonadIO m, QueryRef query)
=> WorkflowHandle a
-> query
-> QueryOptions
-> (QueryArgs query :->: m (Either QueryRejected (QueryResult query)))
query :: forall (m :: * -> *) query a.
(MonadIO m, QueryRef query) =>
WorkflowHandle a
-> query
-> QueryOptions
-> QueryArgs query
:->: m (Either QueryRejected (QueryResult query))
query WorkflowHandle a
h (query -> KnownQuery (QueryArgs query) (QueryResult query)
forall query.
QueryRef query =>
query -> KnownQuery (QueryArgs query) (QueryResult query)
queryRef -> KnownQuery Text
qn codec
codec) QueryOptions
opts = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(QueryArgs query) @(m (Either QueryRejected (QueryResult query))) codec
codec ((Vector UnencodedPayload
-> m (Either QueryRejected (QueryResult query)))
-> QueryArgs query
:->: m (Either QueryRejected (QueryResult query)))
-> (Vector UnencodedPayload
-> m (Either QueryRejected (QueryResult query)))
-> QueryArgs query
:->: m (Either QueryRejected (QueryResult query))
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
inputs -> IO (Either QueryRejected (QueryResult query))
-> m (Either QueryRejected (QueryResult query))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either QueryRejected (QueryResult query))
-> m (Either QueryRejected (QueryResult query)))
-> IO (Either QueryRejected (QueryResult query))
-> m (Either QueryRejected (QueryResult query))
forall a b. (a -> b) -> a -> b
$ do
inputs' <- Vector UnencodedPayload -> IO (Vector Payload)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => Vector (m a) -> m (Vector a)
sequence Vector UnencodedPayload
inputs
let processor = WorkflowHandle a
h.workflowHandleClient.clientConfig.payloadProcessor
baseInput =
QueryWorkflowInput
{ queryWorkflowType :: Text
queryWorkflowType = Text
qn
, queryWorkflowRunId :: Maybe RunId
queryWorkflowRunId = WorkflowHandle a
h.workflowHandleRunId
, queryWorkflowRejectCondition :: QueryRejectCondition
queryWorkflowRejectCondition = QueryOptions
opts.queryRejectCondition
, queryWorkflowWorkflowId :: WorkflowId
queryWorkflowWorkflowId = WorkflowHandle a
h.workflowHandleWorkflowId
, queryWorkflowHeaders :: Map Text Payload
queryWorkflowHeaders = QueryOptions
opts.queryHeaders
, queryWorkflowArgs :: Vector Payload
queryWorkflowArgs = Vector Payload
inputs'
}
eRes <- h.workflowHandleClient.clientConfig.interceptors.queryWorkflow baseInput $ \QueryWorkflowInput
input -> do
queryArgs <- PayloadProcessor -> Vector Payload -> IO (Vector Payload)
forall (m :: * -> *) (f :: * -> *).
(MonadIO m, Traversable f) =>
PayloadProcessor -> f Payload -> m (f Payload)
processorEncodePayloads PayloadProcessor
processor QueryWorkflowInput
input.queryWorkflowArgs
headerPayloads <- processorEncodePayloads processor input.queryWorkflowHeaders
let msg :: QueryWorkflowRequest
msg =
QueryWorkflowRequest
forall msg. Message msg => msg
defMessage
QueryWorkflowRequest
-> (QueryWorkflowRequest -> QueryWorkflowRequest)
-> QueryWorkflowRequest
forall s t. s -> (s -> t) -> t
& LensLike' f QueryWorkflowRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
WF.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest Text)
-> Text -> QueryWorkflowRequest -> QueryWorkflowRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Namespace -> Text
rawNamespace WorkflowHandle a
h.workflowHandleClient.clientConfig.namespace
QueryWorkflowRequest
-> (QueryWorkflowRequest -> QueryWorkflowRequest)
-> QueryWorkflowRequest
forall s t. s -> (s -> t) -> t
& LensLike' f QueryWorkflowRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
WF.execution
(forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest WorkflowExecution)
-> WorkflowExecution
-> QueryWorkflowRequest
-> QueryWorkflowRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowExecution
forall msg. Message msg => msg
defMessage
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
Common.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId QueryWorkflowInput
input.queryWorkflowWorkflowId
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
Common.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text -> (RunId -> Text) -> Maybe RunId -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" RunId -> Text
rawRunId QueryWorkflowInput
input.queryWorkflowRunId
)
QueryWorkflowRequest
-> (QueryWorkflowRequest -> QueryWorkflowRequest)
-> QueryWorkflowRequest
forall s t. s -> (s -> t) -> t
& LensLike' f QueryWorkflowRequest WorkflowQuery
forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest WorkflowQuery
forall (f :: * -> *) s a.
(Functor f, HasField s "query" a) =>
LensLike' f s a
WF.query
(forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest WorkflowQuery)
-> WorkflowQuery -> QueryWorkflowRequest -> QueryWorkflowRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowQuery
forall msg. Message msg => msg
defMessage
WorkflowQuery -> (WorkflowQuery -> WorkflowQuery) -> WorkflowQuery
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowQuery Text
forall {f :: * -> *}. Identical f => LensLike' f WorkflowQuery Text
forall (f :: * -> *) s a.
(Functor f, HasField s "queryType" a) =>
LensLike' f s a
Query.queryType (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowQuery Text)
-> Text -> WorkflowQuery -> WorkflowQuery
forall s t a b. Setter s t a b -> b -> s -> t
.~ QueryWorkflowInput
input.queryWorkflowType
WorkflowQuery -> (WorkflowQuery -> WorkflowQuery) -> WorkflowQuery
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowQuery Payloads
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowQuery Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "queryArgs" a) =>
LensLike' f s a
Query.queryArgs
(forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowQuery Payloads)
-> Payloads -> WorkflowQuery -> WorkflowQuery
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payloads
forall msg. Message msg => msg
defMessage Payloads -> (Payloads -> Payloads) -> Payloads
forall s t. s -> (s -> t) -> t
& LensLike' f Payloads (Vector Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'payloads" a) =>
LensLike' f s a
Common.vec'payloads (forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload))
-> Vector Payload -> Payloads -> Payloads
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payload -> Payload) -> Vector Payload -> Vector Payload
forall a b. (a -> b) -> Vector a -> Vector b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Vector Payload
queryArgs)
WorkflowQuery -> (WorkflowQuery -> WorkflowQuery) -> WorkflowQuery
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowQuery Header
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowQuery Header
forall (f :: * -> *) s a.
(Functor f, HasField s "header" a) =>
LensLike' f s a
Query.header (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowQuery Header)
-> Header -> WorkflowQuery -> WorkflowQuery
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload -> Header
headerToProto ((Payload -> Payload) -> Map Text Payload -> Map Text Payload
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Map Text Payload
headerPayloads)
)
QueryWorkflowRequest
-> (QueryWorkflowRequest -> QueryWorkflowRequest)
-> QueryWorkflowRequest
forall s t. s -> (s -> t) -> t
& LensLike' f QueryWorkflowRequest QueryRejectCondition
forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest QueryRejectCondition
forall (f :: * -> *) s a.
(Functor f, HasField s "queryRejectCondition" a) =>
LensLike' f s a
WF.queryRejectCondition (forall {f :: * -> *}.
Identical f =>
LensLike' f QueryWorkflowRequest QueryRejectCondition)
-> QueryRejectCondition
-> QueryWorkflowRequest
-> QueryWorkflowRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ case QueryOptions
opts.queryRejectCondition of
QueryRejectCondition
QueryRejectConditionRejectNone -> QueryRejectCondition
Query.QUERY_REJECT_CONDITION_NONE
QueryRejectCondition
QueryRejectConditionNotOpen -> QueryRejectCondition
Query.QUERY_REJECT_CONDITION_NOT_OPEN
QueryRejectCondition
QueryRejectConditionNotCompletedCleanly -> QueryRejectCondition
Query.QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY
(res :: QueryWorkflowResponse) <- either throwIO pure =<< Temporal.Core.Client.WorkflowService.queryWorkflow h.workflowHandleClient.clientCore msg
case res ^. WF.maybe'queryRejected of
Just QueryRejected
rejection -> do
let status :: WorkflowExecutionStatus
status = WorkflowExecutionStatus -> WorkflowExecutionStatus
queryRejectionStatusFromProto (QueryRejected
rejection QueryRejected
-> FoldLike
WorkflowExecutionStatus
QueryRejected
QueryRejected
WorkflowExecutionStatus
WorkflowExecutionStatus
-> WorkflowExecutionStatus
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
WorkflowExecutionStatus
QueryRejected
QueryRejected
WorkflowExecutionStatus
WorkflowExecutionStatus
forall (f :: * -> *) s a.
(Functor f, HasField s "status" a) =>
LensLike' f s a
Query.status)
Either QueryRejected Payload -> IO (Either QueryRejected Payload)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either QueryRejected Payload -> IO (Either QueryRejected Payload))
-> Either QueryRejected Payload
-> IO (Either QueryRejected Payload)
forall a b. (a -> b) -> a -> b
$ QueryRejected -> Either QueryRejected Payload
forall a b. a -> Either a b
Left (QueryRejected -> Either QueryRejected Payload)
-> QueryRejected -> Either QueryRejected Payload
forall a b. (a -> b) -> a -> b
$ QueryRejected {WorkflowExecutionStatus
status :: WorkflowExecutionStatus
status :: WorkflowExecutionStatus
..}
Maybe QueryRejected
Nothing -> case (QueryWorkflowResponse
res QueryWorkflowResponse
-> FoldLike
(Vector Payload)
QueryWorkflowResponse
QueryWorkflowResponse
(Vector Payload)
(Vector Payload)
-> Vector Payload
forall s a t b. s -> FoldLike a s t a b -> a
^. LensLike'
(Constant (Vector Payload)) QueryWorkflowResponse Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "queryResult" a) =>
LensLike' f s a
WF.queryResult LensLike'
(Constant (Vector Payload)) QueryWorkflowResponse Payloads
-> ((Vector Payload -> Constant (Vector Payload) (Vector Payload))
-> Payloads -> Constant (Vector Payload) Payloads)
-> FoldLike
(Vector Payload)
QueryWorkflowResponse
QueryWorkflowResponse
(Vector Payload)
(Vector Payload)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector Payload -> Constant (Vector Payload) (Vector Payload))
-> Payloads -> Constant (Vector Payload) Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'payloads" a) =>
LensLike' f s a
Common.vec'payloads) Vector Payload -> Int -> Maybe Payload
forall a. Vector a -> Int -> Maybe a
V.!? Int
0 of
Maybe Payload
Nothing -> ValueError -> IO (Either QueryRejected Payload)
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (ValueError -> IO (Either QueryRejected Payload))
-> ValueError -> IO (Either QueryRejected Payload)
forall a b. (a -> b) -> a -> b
$ [Char] -> ValueError
ValueError [Char]
"No return value payloads provided by query response"
Just Payload
p -> Either QueryRejected Payload -> IO (Either QueryRejected Payload)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either QueryRejected Payload -> IO (Either QueryRejected Payload))
-> Either QueryRejected Payload
-> IO (Either QueryRejected Payload)
forall a b. (a -> b) -> a -> b
$ Payload -> Either QueryRejected Payload
forall a b. b -> Either a b
Right (Payload -> Either QueryRejected Payload)
-> Payload -> Either QueryRejected Payload
forall a b. (a -> b) -> a -> b
$ Payload -> Payload
convertFromProtoPayload Payload
p
forM eRes $ \Payload
p ->
PayloadProcessor -> Payload -> IO (Either [Char] Payload)
payloadProcessorDecode PayloadProcessor
processor Payload
p IO (Either [Char] Payload)
-> (Either [Char] Payload -> UnencodedPayload) -> UnencodedPayload
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Char] -> UnencodedPayload)
-> (Payload -> UnencodedPayload)
-> Either [Char] Payload
-> UnencodedPayload
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ValueError -> UnencodedPayload
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (ValueError -> UnencodedPayload)
-> ([Char] -> ValueError) -> [Char] -> UnencodedPayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ValueError
ValueError) Payload -> UnencodedPayload
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UnencodedPayload
-> (Payload -> IO (Either [Char] (QueryResult query)))
-> IO (Either [Char] (QueryResult query))
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= codec -> Payload -> IO (Either [Char] (QueryResult query))
forall fmt a. Codec fmt a => fmt -> Payload -> IO (Either [Char] a)
decode codec
codec IO (Either [Char] (QueryResult query))
-> (Either [Char] (QueryResult query) -> IO (QueryResult query))
-> IO (QueryResult query)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Char] -> IO (QueryResult query))
-> (QueryResult query -> IO (QueryResult query))
-> Either [Char] (QueryResult query)
-> IO (QueryResult query)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ValueError -> IO (QueryResult query)
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (ValueError -> IO (QueryResult query))
-> ([Char] -> ValueError) -> [Char] -> IO (QueryResult query)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ValueError
ValueError) QueryResult query -> IO (QueryResult query)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
where
queryRejectionStatusFromProto :: WorkflowExecutionStatus -> WorkflowExecutionStatus
queryRejectionStatusFromProto = \case
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_UNSPECIFIED -> WorkflowExecutionStatus
UnknownStatus
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_RUNNING -> WorkflowExecutionStatus
Running
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_COMPLETED -> WorkflowExecutionStatus
Completed
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_FAILED -> WorkflowExecutionStatus
Failed
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_CANCELED -> WorkflowExecutionStatus
Canceled
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_TERMINATED -> WorkflowExecutionStatus
Terminated
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW -> WorkflowExecutionStatus
ContinuedAsNew
WorkflowExecutionStatus
WORKFLOW_EXECUTION_STATUS_TIMED_OUT -> WorkflowExecutionStatus
TimedOut
WorkflowExecutionStatus'Unrecognized WorkflowExecutionStatus'UnrecognizedValue
_ -> WorkflowExecutionStatus
UnknownStatus
getHandle
:: (HasWorkflowClient m, MonadIO m)
=> KnownWorkflow args a
-> WorkflowId
-> Maybe RunId
-> m (WorkflowHandle a)
getHandle :: forall (m :: * -> *) (args :: [*]) a.
(HasWorkflowClient m, MonadIO m) =>
KnownWorkflow args a
-> WorkflowId -> Maybe RunId -> m (WorkflowHandle a)
getHandle (KnownWorkflow {codec
knownWorkflowCodec :: codec
knownWorkflowCodec :: ()
knownWorkflowCodec, Text
knownWorkflowName :: Text
knownWorkflowName :: forall (args :: [*]) result. KnownWorkflow args result -> Text
knownWorkflowName}) WorkflowId
wfId Maybe RunId
runId = do
c <- m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
pure $
WorkflowHandle
{ workflowHandleReadResult = \Payload
a -> do
result <- codec -> Payload -> IO (Either [Char] a)
forall fmt a. Codec fmt a => fmt -> Payload -> IO (Either [Char] a)
decode codec
knownWorkflowCodec (Payload -> IO (Either [Char] a))
-> UnencodedPayload -> IO (Either [Char] a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ([Char] -> UnencodedPayload)
-> (Payload -> UnencodedPayload)
-> Either [Char] Payload
-> UnencodedPayload
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ValueError -> UnencodedPayload
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (ValueError -> UnencodedPayload)
-> ([Char] -> ValueError) -> [Char] -> UnencodedPayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ValueError
ValueError) Payload -> UnencodedPayload
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either [Char] Payload -> UnencodedPayload)
-> IO (Either [Char] Payload) -> UnencodedPayload
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PayloadProcessor -> Payload -> IO (Either [Char] Payload)
payloadProcessorDecode WorkflowClient
c.clientConfig.payloadProcessor Payload
a
either (throwIO . ValueError) pure result
, workflowHandleClient = c
, workflowHandleWorkflowId = wfId
, workflowHandleRunId = runId
, workflowHandleType = WorkflowType knownWorkflowName
}
startFromPayloads
:: (MonadIO m, HasWorkflowClient m)
=> KnownWorkflow args result
-> WorkflowId
-> StartWorkflowOptions
-> V.Vector UnencodedPayload
-> m (WorkflowHandle result)
startFromPayloads :: forall (m :: * -> *) (args :: [*]) result.
(MonadIO m, HasWorkflowClient m) =>
KnownWorkflow args result
-> WorkflowId
-> StartWorkflowOptions
-> Vector UnencodedPayload
-> m (WorkflowHandle result)
startFromPayloads k :: KnownWorkflow args result
k@(KnownWorkflow codec
codec Text
_) WorkflowId
wfId StartWorkflowOptions
opts Vector UnencodedPayload
payloads = do
c <- m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
ps <- liftIO $ sequence payloads
wfH <- liftIO $ Temporal.Client.Types.start c.clientConfig.interceptors (WorkflowType $ knownWorkflowName k) wfId opts ps $ \WorkflowType
wfName WorkflowId
wfId' StartWorkflowOptions
opts' Vector Payload
payloads' -> do
reqId <- IO UUID
UUID.nextRandom
searchAttrs <- searchAttributesToProto opts'.searchAttributes
payloads'' <- processorEncodePayloads c.clientConfig.payloadProcessor payloads'
hdrs <- processorEncodePayloads c.clientConfig.payloadProcessor opts'.headers
let tq = TaskQueue -> Text
rawTaskQueue StartWorkflowOptions
opts'.taskQueue
req =
StartWorkflowExecutionRequest
forall msg. Message msg => msg
defMessage
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
WF.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text)
-> Text
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Namespace -> Text
rawNamespace WorkflowClient
c.clientConfig.namespace
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
WF.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text)
-> Text
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId WorkflowId
wfId'
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest WorkflowType
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest WorkflowType
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowType" a) =>
LensLike' f s a
WF.workflowType
(forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest WorkflowType)
-> WorkflowType
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowType
forall msg. Message msg => msg
defMessage WorkflowType -> (WorkflowType -> WorkflowType) -> WorkflowType
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowType Text
forall {f :: * -> *}. Identical f => LensLike' f WorkflowType Text
forall (f :: * -> *) s a.
(Functor f, HasField s "name" a) =>
LensLike' f s a
Common.name (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowType Text)
-> Text -> WorkflowType -> WorkflowType
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowType -> Text
rawWorkflowType WorkflowType
wfName
)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest TaskQueue
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest TaskQueue
forall (f :: * -> *) s a.
(Functor f, HasField s "taskQueue" a) =>
LensLike' f s a
WF.taskQueue
(forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest TaskQueue)
-> TaskQueue
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( TaskQueue
forall msg. Message msg => msg
defMessage
TaskQueue -> (TaskQueue -> TaskQueue) -> TaskQueue
forall s t. s -> (s -> t) -> t
& LensLike' f TaskQueue Text
forall {f :: * -> *}. Identical f => LensLike' f TaskQueue Text
forall (f :: * -> *) s a.
(Functor f, HasField s "name" a) =>
LensLike' f s a
Common.name (forall {f :: * -> *}. Identical f => LensLike' f TaskQueue Text)
-> Text -> TaskQueue -> TaskQueue
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text
tq
TaskQueue -> (TaskQueue -> TaskQueue) -> TaskQueue
forall s t. s -> (s -> t) -> t
& LensLike' f TaskQueue TaskQueueKind
forall {f :: * -> *}.
Identical f =>
LensLike' f TaskQueue TaskQueueKind
forall (f :: * -> *) s a.
(Functor f, HasField s "kind" a) =>
LensLike' f s a
TQ.kind (forall {f :: * -> *}.
Identical f =>
LensLike' f TaskQueue TaskQueueKind)
-> TaskQueueKind -> TaskQueue -> TaskQueue
forall s t a b. Setter s t a b -> b -> s -> t
.~ TaskQueueKind
TASK_QUEUE_KIND_UNSPECIFIED
)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Payloads
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "input" a) =>
LensLike' f s a
WF.input
(forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Payloads)
-> Payloads
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( Payloads
forall msg. Message msg => msg
defMessage Payloads -> (Payloads -> Payloads) -> Payloads
forall s t. s -> (s -> t) -> t
& LensLike' f Payloads (Vector Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'payloads" a) =>
LensLike' f s a
Common.vec'payloads (forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload))
-> Vector Payload -> Payloads -> Payloads
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payload -> Payload
convertToProtoPayload (Payload -> Payload) -> Vector Payload -> Vector Payload
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Vector Payload
payloads'')
)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowExecutionTimeout" a) =>
LensLike' f s a
WF.maybe'workflowExecutionTimeout (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StartWorkflowOptions
opts'.timeouts.executionTimeout)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowRunTimeout" a) =>
LensLike' f s a
WF.maybe'workflowRunTimeout (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StartWorkflowOptions
opts'.timeouts.runTimeout)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowTaskTimeout" a) =>
LensLike' f s a
WF.maybe'workflowTaskTimeout (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StartWorkflowOptions
opts'.timeouts.taskTimeout)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "identity" a) =>
LensLike' f s a
WF.identity (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text)
-> Text
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ClientConfig -> Text
Core.identity (Client -> ClientConfig
Core.clientConfig WorkflowClient
c.clientCore)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "requestId" a) =>
LensLike' f s a
WF.requestId (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text)
-> Text
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ UUID -> Text
UUID.toText UUID
reqId
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest WorkflowIdReusePolicy
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest WorkflowIdReusePolicy
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowIdReusePolicy" a) =>
LensLike' f s a
WF.workflowIdReusePolicy
(forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest WorkflowIdReusePolicy)
-> WorkflowIdReusePolicy
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowIdReusePolicy -> WorkflowIdReusePolicy
workflowIdReusePolicyToProto
(WorkflowIdReusePolicy
-> Maybe WorkflowIdReusePolicy -> WorkflowIdReusePolicy
forall a. a -> Maybe a -> a
fromMaybe WorkflowIdReusePolicy
WorkflowIdReusePolicyAllowDuplicateFailedOnly StartWorkflowOptions
opts'.workflowIdReusePolicy)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest (Maybe RetryPolicy)
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe RetryPolicy)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'retryPolicy" a) =>
LensLike' f s a
WF.maybe'retryPolicy (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe RetryPolicy))
-> Maybe RetryPolicy
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (RetryPolicy -> RetryPolicy
retryPolicyToProto (RetryPolicy -> RetryPolicy)
-> Maybe RetryPolicy -> Maybe RetryPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StartWorkflowOptions
opts'.retryPolicy)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "cronSchedule" a) =>
LensLike' f s a
WF.cronSchedule (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Text)
-> Text
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" StartWorkflowOptions
opts'.cronSchedule
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Memo
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Memo
forall (f :: * -> *) s a.
(Functor f, HasField s "memo" a) =>
LensLike' f s a
WF.memo (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Memo)
-> Memo
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload -> Memo
convertToProtoMemo StartWorkflowOptions
opts'.memo
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest SearchAttributes
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest SearchAttributes
forall (f :: * -> *) s a.
(Functor f, HasField s "searchAttributes" a) =>
LensLike' f s a
WF.searchAttributes (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest SearchAttributes)
-> SearchAttributes
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (SearchAttributes
forall msg. Message msg => msg
defMessage SearchAttributes
-> (SearchAttributes -> SearchAttributes) -> SearchAttributes
forall s t. s -> (s -> t) -> t
& LensLike' f SearchAttributes (Map Text Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f SearchAttributes (Map Text Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "indexedFields" a) =>
LensLike' f s a
Common.indexedFields (forall {f :: * -> *}.
Identical f =>
LensLike' f SearchAttributes (Map Text Payload))
-> Map Text Payload -> SearchAttributes -> SearchAttributes
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload
searchAttrs)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Header
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Header
forall (f :: * -> *) s a.
(Functor f, HasField s "header" a) =>
LensLike' f s a
WF.header (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Header)
-> Header
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload -> Header
headerToProto ((Payload -> Payload) -> Map Text Payload -> Map Text Payload
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Map Text Payload
hdrs)
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest Bool
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "requestEagerExecution" a) =>
LensLike' f s a
WF.requestEagerExecution (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest Bool)
-> Bool
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ StartWorkflowOptions
opts'.requestEagerExecution
StartWorkflowExecutionRequest
-> (StartWorkflowExecutionRequest -> StartWorkflowExecutionRequest)
-> StartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowStartDelay" a) =>
LensLike' f s a
WF.maybe'workflowStartDelay (forall {f :: * -> *}.
Identical f =>
LensLike' f StartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> StartWorkflowExecutionRequest
-> StartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StartWorkflowOptions -> Maybe Duration
workflowStartDelay StartWorkflowOptions
opts')
res <- startWorkflowExecution c.clientCore req
case res of
Left RpcError
err -> RpcError -> IO (WorkflowHandle Payload)
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO RpcError
err
Right StartWorkflowExecutionResponse
swer ->
WorkflowHandle Payload -> IO (WorkflowHandle Payload)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WorkflowHandle Payload -> IO (WorkflowHandle Payload))
-> WorkflowHandle Payload -> IO (WorkflowHandle Payload)
forall a b. (a -> b) -> a -> b
$
WorkflowHandle
{ workflowHandleReadResult :: Payload -> UnencodedPayload
workflowHandleReadResult = Payload -> UnencodedPayload
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
, workflowHandleType :: WorkflowType
workflowHandleType = Text -> WorkflowType
WorkflowType (Text -> WorkflowType) -> Text -> WorkflowType
forall a b. (a -> b) -> a -> b
$ KnownWorkflow args result -> Text
forall (args :: [*]) result. KnownWorkflow args result -> Text
knownWorkflowName KnownWorkflow args result
k
, workflowHandleClient :: WorkflowClient
workflowHandleClient = WorkflowClient
c
, workflowHandleWorkflowId :: WorkflowId
workflowHandleWorkflowId = WorkflowId
wfId'
, workflowHandleRunId :: Maybe RunId
workflowHandleRunId = RunId -> Maybe RunId
forall a. a -> Maybe a
Just (Text -> RunId
RunId (Text -> RunId) -> Text -> RunId
forall a b. (a -> b) -> a -> b
$ StartWorkflowExecutionResponse
swer StartWorkflowExecutionResponse
-> FoldLike
Text
StartWorkflowExecutionResponse
StartWorkflowExecutionResponse
Text
Text
-> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
Text
StartWorkflowExecutionResponse
StartWorkflowExecutionResponse
Text
Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
WF.runId)
}
pure $
wfH
{ workflowHandleReadResult = \Payload
a ->
WorkflowHandle Payload -> Payload -> UnencodedPayload
forall a. WorkflowHandle a -> Payload -> IO a
workflowHandleReadResult WorkflowHandle Payload
wfH Payload
a UnencodedPayload -> (Payload -> IO result) -> IO result
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Payload
b -> do
result <- codec -> Payload -> IO (Either [Char] result)
forall fmt a. Codec fmt a => fmt -> Payload -> IO (Either [Char] a)
decode codec
codec (Payload -> IO (Either [Char] result))
-> UnencodedPayload -> IO (Either [Char] result)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ([Char] -> UnencodedPayload)
-> (Payload -> UnencodedPayload)
-> Either [Char] Payload
-> UnencodedPayload
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ValueError -> UnencodedPayload
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO (ValueError -> UnencodedPayload)
-> ([Char] -> ValueError) -> [Char] -> UnencodedPayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ValueError
ValueError) Payload -> UnencodedPayload
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either [Char] Payload -> UnencodedPayload)
-> IO (Either [Char] Payload) -> UnencodedPayload
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PayloadProcessor -> Payload -> IO (Either [Char] Payload)
payloadProcessorDecode WorkflowClient
c.clientConfig.payloadProcessor Payload
b
either (throwIO . ValueError) pure result
}
start
:: forall m wf
. (MonadIO m, HasWorkflowClient m, WorkflowRef wf)
=> wf
-> WorkflowId
-> StartWorkflowOptions
-> (WorkflowArgs wf :->: m (WorkflowHandle (WorkflowResult wf)))
start :: forall (m :: * -> *) wf.
(MonadIO m, HasWorkflowClient m, WorkflowRef wf) =>
wf
-> WorkflowId
-> StartWorkflowOptions
-> WorkflowArgs wf :->: m (WorkflowHandle (WorkflowResult wf))
start (wf -> KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
forall f.
WorkflowRef f =>
f -> KnownWorkflow (WorkflowArgs f) (WorkflowResult f)
workflowRef -> k :: KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k@(KnownWorkflow codec
codec Text
_)) WorkflowId
wfId StartWorkflowOptions
opts = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(WorkflowArgs wf) @(m (WorkflowHandle (WorkflowResult wf))) codec
codec ((Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf)))
-> WorkflowArgs wf :->: m (WorkflowHandle (WorkflowResult wf)))
-> (Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf)))
-> WorkflowArgs wf :->: m (WorkflowHandle (WorkflowResult wf))
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
inputs -> do
KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
-> WorkflowId
-> StartWorkflowOptions
-> Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf))
forall (m :: * -> *) (args :: [*]) result.
(MonadIO m, HasWorkflowClient m) =>
KnownWorkflow args result
-> WorkflowId
-> StartWorkflowOptions
-> Vector UnencodedPayload
-> m (WorkflowHandle result)
startFromPayloads KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k WorkflowId
wfId StartWorkflowOptions
opts Vector UnencodedPayload
inputs
signalWithStart
:: forall wf sig m
. (MonadIO m, HasWorkflowClient m, WorkflowRef wf, SignalRef sig)
=> wf
-> WorkflowId
-> StartWorkflowOptions
-> sig
-> (WorkflowArgs wf :->: (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))))
signalWithStart :: forall wf sig (m :: * -> *).
(MonadIO m, HasWorkflowClient m, WorkflowRef wf, SignalRef sig) =>
wf
-> WorkflowId
-> StartWorkflowOptions
-> sig
-> WorkflowArgs wf
:->: (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
signalWithStart (wf -> KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
forall f.
WorkflowRef f =>
f -> KnownWorkflow (WorkflowArgs f) (WorkflowResult f)
workflowRef -> k :: KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k@(KnownWorkflow codec
codec Text
_)) WorkflowId
wfId StartWorkflowOptions
opts (sig -> KnownSignal (SignalArgs sig)
forall sig. SignalRef sig => sig -> KnownSignal (SignalArgs sig)
signalRef -> KnownSignal Text
n codec
sigCodec) = WorkflowArgs wf
:->: (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
unnestedArgs
where
signalArgsMaker :: m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))) -> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
signalArgsMaker :: m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
-> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
signalArgsMaker = forall (args :: [*]) (m :: * -> *) result.
(VarArgs args, Monad m) =>
Proxy (m result) -> m (args :->: m result) -> args :->: m result
sequenceArgs @(SignalArgs sig) @m (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(m (WorkflowHandle (WorkflowResult wf))))
unnestedArgs :: WorkflowArgs wf :->: (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
unnestedArgs :: WorkflowArgs wf
:->: (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
unnestedArgs =
forall (args :: [*]) result result'.
VarArgs args =>
(result -> result') -> (args :->: result) -> args :->: result'
mapResult
@(WorkflowArgs wf)
m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
-> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
signalArgsMaker
WorkflowArgs wf
:->: m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
nestedArgs
nestedArgs :: WorkflowArgs wf
:->: m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
nestedArgs = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(WorkflowArgs wf) @(m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))) codec
codec ((Vector UnencodedPayload
-> m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))))
-> WorkflowArgs wf
:->: m (SignalArgs sig
:->: m (WorkflowHandle (WorkflowResult wf))))
-> (Vector UnencodedPayload
-> m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))))
-> WorkflowArgs wf
:->: m (SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
wfArgs -> do
c <- m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
wfArgs' <- processorEncodePayloads c.clientConfig.payloadProcessor =<< liftIO (sequence wfArgs)
pure $ signalArgs wfArgs'
signalArgs :: V.Vector Payload -> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
signalArgs :: Vector Payload
-> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
signalArgs Vector Payload
wfArgs = forall (args :: [*]) result codec.
(VarArgs args, AllArgs (Codec codec) args) =>
codec -> (Vector UnencodedPayload -> result) -> args :->: result
withArgs @(SignalArgs sig) @(m (WorkflowHandle (WorkflowResult wf))) codec
sigCodec ((Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf)))
-> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf)))
-> (Vector UnencodedPayload
-> m (WorkflowHandle (WorkflowResult wf)))
-> SignalArgs sig :->: m (WorkflowHandle (WorkflowResult wf))
forall a b. (a -> b) -> a -> b
$ \Vector UnencodedPayload
sa -> do
c <- m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient
sigArgs' <- liftIO $ sequence sa
let processor = WorkflowClient
c.clientConfig.payloadProcessor
interceptorOpts =
SignalWithStartWorkflowInput
{ signalWithStartWorkflowType :: WorkflowType
signalWithStartWorkflowType = Text -> WorkflowType
WorkflowType (Text -> WorkflowType) -> Text -> WorkflowType
forall a b. (a -> b) -> a -> b
$ KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf) -> Text
forall (args :: [*]) result. KnownWorkflow args result -> Text
knownWorkflowName KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k
, signalWithStartSignalName :: Text
signalWithStartSignalName = Text
n
, signalWithStartSignalArgs :: Vector Payload
signalWithStartSignalArgs = Vector Payload
sigArgs'
, signalWithStartArgs :: Vector Payload
signalWithStartArgs = Vector Payload
wfArgs
, signalWithStartOptions :: StartWorkflowOptions
signalWithStartOptions = StartWorkflowOptions
opts
, signalWithStartWorkflowId :: WorkflowId
signalWithStartWorkflowId = WorkflowId
wfId
}
wfH <- liftIO $ Temporal.Client.Types.signalWithStart c.clientConfig.interceptors interceptorOpts $ \SignalWithStartWorkflowInput
opts' -> do
reqId <- IO UUID
UUID.nextRandom
searchAttrs <- searchAttributesToProto opts'.signalWithStartOptions.searchAttributes
signalArgs' <- processorEncodePayloads processor opts'.signalWithStartSignalArgs
wfArgs' <- processorEncodePayloads processor opts'.signalWithStartArgs
hdrs <- processorEncodePayloads processor opts'.signalWithStartOptions.headers
memo' <- processorEncodePayloads processor opts'.signalWithStartOptions.memo
let tq = TaskQueue -> Text
rawTaskQueue SignalWithStartWorkflowInput
opts'.signalWithStartOptions.taskQueue
msg =
SignalWithStartWorkflowExecutionRequest
forall msg. Message msg => msg
defMessage
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
RR.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Namespace -> Text
rawNamespace WorkflowClient
c.clientConfig.namespace
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
RR.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId SignalWithStartWorkflowInput
opts'.signalWithStartWorkflowId
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest WorkflowType
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest WorkflowType
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowType" a) =>
LensLike' f s a
RR.workflowType
(forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest WorkflowType)
-> WorkflowType
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowType
forall msg. Message msg => msg
defMessage WorkflowType -> (WorkflowType -> WorkflowType) -> WorkflowType
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowType Text
forall {f :: * -> *}. Identical f => LensLike' f WorkflowType Text
forall (f :: * -> *) s a.
(Functor f, HasField s "name" a) =>
LensLike' f s a
Common.name (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowType Text)
-> Text -> WorkflowType -> WorkflowType
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowType -> Text
rawWorkflowType SignalWithStartWorkflowInput
opts'.signalWithStartWorkflowType
)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "requestId" a) =>
LensLike' f s a
WF.requestId (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ UUID -> Text
UUID.toText UUID
reqId
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest SearchAttributes
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest SearchAttributes
forall (f :: * -> *) s a.
(Functor f, HasField s "searchAttributes" a) =>
LensLike' f s a
RR.searchAttributes (forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest SearchAttributes)
-> SearchAttributes
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (SearchAttributes
forall msg. Message msg => msg
defMessage SearchAttributes
-> (SearchAttributes -> SearchAttributes) -> SearchAttributes
forall s t. s -> (s -> t) -> t
& LensLike' f SearchAttributes (Map Text Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f SearchAttributes (Map Text Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "indexedFields" a) =>
LensLike' f s a
Common.indexedFields (forall {f :: * -> *}.
Identical f =>
LensLike' f SearchAttributes (Map Text Payload))
-> Map Text Payload -> SearchAttributes -> SearchAttributes
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload
searchAttrs)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest TaskQueue
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest TaskQueue
forall (f :: * -> *) s a.
(Functor f, HasField s "taskQueue" a) =>
LensLike' f s a
RR.taskQueue
(forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest TaskQueue)
-> TaskQueue
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( TaskQueue
forall msg. Message msg => msg
defMessage
TaskQueue -> (TaskQueue -> TaskQueue) -> TaskQueue
forall s t. s -> (s -> t) -> t
& LensLike' f TaskQueue Text
forall {f :: * -> *}. Identical f => LensLike' f TaskQueue Text
forall (f :: * -> *) s a.
(Functor f, HasField s "name" a) =>
LensLike' f s a
Common.name (forall {f :: * -> *}. Identical f => LensLike' f TaskQueue Text)
-> Text -> TaskQueue -> TaskQueue
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text
tq
TaskQueue -> (TaskQueue -> TaskQueue) -> TaskQueue
forall s t. s -> (s -> t) -> t
& LensLike' f TaskQueue TaskQueueKind
forall {f :: * -> *}.
Identical f =>
LensLike' f TaskQueue TaskQueueKind
forall (f :: * -> *) s a.
(Functor f, HasField s "kind" a) =>
LensLike' f s a
TQ.kind (forall {f :: * -> *}.
Identical f =>
LensLike' f TaskQueue TaskQueueKind)
-> TaskQueueKind -> TaskQueue -> TaskQueue
forall s t a b. Setter s t a b -> b -> s -> t
.~ TaskQueueKind
TASK_QUEUE_KIND_UNSPECIFIED
)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Payloads
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "input" a) =>
LensLike' f s a
RR.input
(forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Payloads)
-> Payloads
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( Payloads
forall msg. Message msg => msg
defMessage Payloads -> (Payloads -> Payloads) -> Payloads
forall s t. s -> (s -> t) -> t
& LensLike' f Payloads (Vector Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'payloads" a) =>
LensLike' f s a
Common.vec'payloads (forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload))
-> Vector Payload -> Payloads -> Payloads
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payload -> Payload) -> Vector Payload -> Vector Payload
forall a b. (a -> b) -> Vector a -> Vector b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Vector Payload
wfArgs'
)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowExecutionTimeout" a) =>
LensLike' f s a
RR.maybe'workflowExecutionTimeout (forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SignalWithStartWorkflowInput
opts'.signalWithStartOptions.timeouts.executionTimeout)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowRunTimeout" a) =>
LensLike' f s a
RR.maybe'workflowRunTimeout (forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SignalWithStartWorkflowInput
opts'.signalWithStartOptions.timeouts.runTimeout)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'workflowTaskTimeout" a) =>
LensLike' f s a
RR.maybe'workflowTaskTimeout (forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe Duration))
-> Maybe Duration
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Duration -> Duration
durationToProto (Duration -> Duration) -> Maybe Duration -> Maybe Duration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SignalWithStartWorkflowInput
opts'.signalWithStartOptions.timeouts.taskTimeout)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "identity" a) =>
LensLike' f s a
RR.identity (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ClientConfig -> Text
Core.identity (Client -> ClientConfig
Core.clientConfig WorkflowClient
c.clientCore)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "requestId" a) =>
LensLike' f s a
RR.requestId (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ UUID -> Text
UUID.toText UUID
reqId
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest WorkflowIdReusePolicy
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest WorkflowIdReusePolicy
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowIdReusePolicy" a) =>
LensLike' f s a
RR.workflowIdReusePolicy
(forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest WorkflowIdReusePolicy)
-> WorkflowIdReusePolicy
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowIdReusePolicy -> WorkflowIdReusePolicy
workflowIdReusePolicyToProto
(WorkflowIdReusePolicy
-> Maybe WorkflowIdReusePolicy -> WorkflowIdReusePolicy
forall a. a -> Maybe a -> a
fromMaybe WorkflowIdReusePolicy
WorkflowIdReusePolicyAllowDuplicateFailedOnly SignalWithStartWorkflowInput
opts'.signalWithStartOptions.workflowIdReusePolicy)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "signalName" a) =>
LensLike' f s a
RR.signalName (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text
n
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Payloads
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "signalInput" a) =>
LensLike' f s a
RR.signalInput (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Payloads)
-> Payloads
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payloads
forall msg. Message msg => msg
defMessage Payloads -> (Payloads -> Payloads) -> Payloads
forall s t. s -> (s -> t) -> t
& LensLike' f Payloads (Vector Payload)
forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload)
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'payloads" a) =>
LensLike' f s a
Common.vec'payloads (forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads (Vector Payload))
-> Vector Payload -> Payloads -> Payloads
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payload -> Payload) -> Vector Payload -> Vector Payload
forall a b. (a -> b) -> Vector a -> Vector b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Vector Payload
signalArgs')
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe RetryPolicy)
forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe RetryPolicy)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'retryPolicy" a) =>
LensLike' f s a
RR.maybe'retryPolicy (forall {f :: * -> *}.
Identical f =>
LensLike'
f SignalWithStartWorkflowExecutionRequest (Maybe RetryPolicy))
-> Maybe RetryPolicy
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (RetryPolicy -> RetryPolicy
retryPolicyToProto (RetryPolicy -> RetryPolicy)
-> Maybe RetryPolicy -> Maybe RetryPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SignalWithStartWorkflowInput
opts'.signalWithStartOptions.retryPolicy)
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "cronSchedule" a) =>
LensLike' f s a
RR.cronSchedule (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Text)
-> Text
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" SignalWithStartWorkflowInput
opts'.signalWithStartOptions.cronSchedule
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Memo
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Memo
forall (f :: * -> *) s a.
(Functor f, HasField s "memo" a) =>
LensLike' f s a
RR.memo (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Memo)
-> Memo
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload -> Memo
convertToProtoMemo Map Text Payload
memo'
SignalWithStartWorkflowExecutionRequest
-> (SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest)
-> SignalWithStartWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f SignalWithStartWorkflowExecutionRequest Header
forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Header
forall (f :: * -> *) s a.
(Functor f, HasField s "header" a) =>
LensLike' f s a
RR.header (forall {f :: * -> *}.
Identical f =>
LensLike' f SignalWithStartWorkflowExecutionRequest Header)
-> Header
-> SignalWithStartWorkflowExecutionRequest
-> SignalWithStartWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Map Text Payload -> Header
headerToProto ((Payload -> Payload) -> Map Text Payload -> Map Text Payload
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload Map Text Payload
hdrs)
res <-
signalWithStartWorkflowExecution
c.clientCore
msg
case res of
Left RpcError
err -> RpcError -> IO (WorkflowHandle Payload)
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO RpcError
err
Right SignalWithStartWorkflowExecutionResponse
swer ->
WorkflowHandle Payload -> IO (WorkflowHandle Payload)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (WorkflowHandle Payload -> IO (WorkflowHandle Payload))
-> WorkflowHandle Payload -> IO (WorkflowHandle Payload)
forall a b. (a -> b) -> a -> b
$
WorkflowHandle
{ workflowHandleReadResult :: Payload -> UnencodedPayload
workflowHandleReadResult = Payload -> UnencodedPayload
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
, workflowHandleType :: WorkflowType
workflowHandleType = Text -> WorkflowType
WorkflowType (Text -> WorkflowType) -> Text -> WorkflowType
forall a b. (a -> b) -> a -> b
$ KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf) -> Text
forall (args :: [*]) result. KnownWorkflow args result -> Text
knownWorkflowName KnownWorkflow (WorkflowArgs wf) (WorkflowResult wf)
k
, workflowHandleClient :: WorkflowClient
workflowHandleClient = WorkflowClient
c
, workflowHandleWorkflowId :: WorkflowId
workflowHandleWorkflowId = SignalWithStartWorkflowInput
opts'.signalWithStartWorkflowId
, workflowHandleRunId :: Maybe RunId
workflowHandleRunId = RunId -> Maybe RunId
forall a. a -> Maybe a
Just (Text -> RunId
RunId (Text -> RunId) -> Text -> RunId
forall a b. (a -> b) -> a -> b
$ SignalWithStartWorkflowExecutionResponse
swer SignalWithStartWorkflowExecutionResponse
-> FoldLike
Text
SignalWithStartWorkflowExecutionResponse
SignalWithStartWorkflowExecutionResponse
Text
Text
-> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
Text
SignalWithStartWorkflowExecutionResponse
SignalWithStartWorkflowExecutionResponse
Text
Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
WF.runId)
}
pure $
wfH
{ workflowHandleReadResult = \Payload
a ->
WorkflowHandle Payload -> Payload -> UnencodedPayload
forall a. WorkflowHandle a -> Payload -> IO a
workflowHandleReadResult WorkflowHandle Payload
wfH Payload
a UnencodedPayload
-> (Payload -> IO (WorkflowResult wf)) -> IO (WorkflowResult wf)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Payload
b -> do
result <- codec -> Payload -> IO (Either [Char] (WorkflowResult wf))
forall fmt a. Codec fmt a => fmt -> Payload -> IO (Either [Char] a)
decode codec
codec Payload
b
either (throwIO . ValueError) pure result
}
data TerminationOptions = TerminationOptions
{ TerminationOptions -> Text
terminationReason :: Text
, TerminationOptions -> [Payload]
terminationDetails :: [Payload]
, TerminationOptions -> Maybe RunId
firstExecutionRunId :: Maybe RunId
}
terminate :: MonadIO m => WorkflowHandle a -> TerminationOptions -> m ()
terminate :: forall (m :: * -> *) a.
MonadIO m =>
WorkflowHandle a -> TerminationOptions -> m ()
terminate WorkflowHandle a
h TerminationOptions
req =
m TerminateWorkflowExecutionResponse -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m TerminateWorkflowExecutionResponse -> m ())
-> m TerminateWorkflowExecutionResponse -> m ()
forall a b. (a -> b) -> a -> b
$
IO (Either RpcError TerminateWorkflowExecutionResponse)
-> m TerminateWorkflowExecutionResponse
forall (m :: * -> *) e a.
(MonadIO m, Exception e) =>
IO (Either e a) -> m a
throwEither (IO (Either RpcError TerminateWorkflowExecutionResponse)
-> m TerminateWorkflowExecutionResponse)
-> IO (Either RpcError TerminateWorkflowExecutionResponse)
-> m TerminateWorkflowExecutionResponse
forall a b. (a -> b) -> a -> b
$
Client
-> TerminateWorkflowExecutionRequest
-> IO (Either RpcError TerminateWorkflowExecutionResponse)
terminateWorkflowExecution
WorkflowHandle a
h.workflowHandleClient.clientCore
TerminateWorkflowExecutionRequest
msg
where
msg :: TerminateWorkflowExecutionRequest
msg =
TerminateWorkflowExecutionRequest
forall msg. Message msg => msg
defMessage
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
RR.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text)
-> Text
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Namespace -> Text
rawNamespace WorkflowHandle a
h.workflowHandleClient.clientConfig.namespace
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowExecution" a) =>
LensLike' f s a
RR.workflowExecution
(forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest WorkflowExecution)
-> WorkflowExecution
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowExecution
forall msg. Message msg => msg
defMessage
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
Common.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId WorkflowHandle a
h.workflowHandleWorkflowId
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
Common.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text -> (RunId -> Text) -> Maybe RunId -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" RunId -> Text
rawRunId WorkflowHandle a
h.workflowHandleRunId
)
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "reason" a) =>
LensLike' f s a
RR.reason (forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text)
-> Text
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ TerminationOptions
req.terminationReason
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest Payloads
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Payloads
forall (f :: * -> *) s a.
(Functor f, HasField s "details" a) =>
LensLike' f s a
RR.details
(forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Payloads)
-> Payloads
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payloads
forall msg. Message msg => msg
defMessage Payloads -> (Payloads -> Payloads) -> Payloads
forall s t. s -> (s -> t) -> t
& LensLike' f Payloads [Payload]
forall {f :: * -> *}. Identical f => LensLike' f Payloads [Payload]
forall (f :: * -> *) s a.
(Functor f, HasField s "payloads" a) =>
LensLike' f s a
Common.payloads (forall {f :: * -> *}.
Identical f =>
LensLike' f Payloads [Payload])
-> [Payload] -> Payloads -> Payloads
forall s t a b. Setter s t a b -> b -> s -> t
.~ (Payload -> Payload) -> [Payload] -> [Payload]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Payload -> Payload
convertToProtoPayload TerminationOptions
req.terminationDetails)
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "identity" a) =>
LensLike' f s a
RR.identity (forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text)
-> Text
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ClientConfig -> Text
Core.identity (Client -> ClientConfig
Core.clientConfig WorkflowHandle a
h.workflowHandleClient.clientCore)
TerminateWorkflowExecutionRequest
-> (TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest)
-> TerminateWorkflowExecutionRequest
forall s t. s -> (s -> t) -> t
& LensLike' f TerminateWorkflowExecutionRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "firstExecutionRunId" a) =>
LensLike' f s a
RR.firstExecutionRunId (forall {f :: * -> *}.
Identical f =>
LensLike' f TerminateWorkflowExecutionRequest Text)
-> Text
-> TerminateWorkflowExecutionRequest
-> TerminateWorkflowExecutionRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text -> (RunId -> Text) -> Maybe RunId -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" RunId -> Text
rawRunId TerminationOptions
req.firstExecutionRunId
data FollowOption = FollowRuns | ThisRunOnly
data WorkflowContinuedAsNewException = WorkflowContinuedAsNewException
{ WorkflowContinuedAsNewException -> RunId
workflowContinuedAsNewExceptionRunId :: RunId
}
deriving stock (Int -> WorkflowContinuedAsNewException -> [Char] -> [Char]
[WorkflowContinuedAsNewException] -> [Char] -> [Char]
WorkflowContinuedAsNewException -> [Char]
(Int -> WorkflowContinuedAsNewException -> [Char] -> [Char])
-> (WorkflowContinuedAsNewException -> [Char])
-> ([WorkflowContinuedAsNewException] -> [Char] -> [Char])
-> Show WorkflowContinuedAsNewException
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> WorkflowContinuedAsNewException -> [Char] -> [Char]
showsPrec :: Int -> WorkflowContinuedAsNewException -> [Char] -> [Char]
$cshow :: WorkflowContinuedAsNewException -> [Char]
show :: WorkflowContinuedAsNewException -> [Char]
$cshowList :: [WorkflowContinuedAsNewException] -> [Char] -> [Char]
showList :: [WorkflowContinuedAsNewException] -> [Char] -> [Char]
Show)
instance Exception WorkflowContinuedAsNewException
fetchHistory :: MonadIO m => WorkflowHandle a -> m History
fetchHistory :: forall (m :: * -> *) a. MonadIO m => WorkflowHandle a -> m History
fetchHistory WorkflowHandle a
h = do
let startingReq :: GetWorkflowExecutionHistoryRequest
startingReq :: GetWorkflowExecutionHistoryRequest
startingReq =
GetWorkflowExecutionHistoryRequest
forall msg. Message msg => msg
defMessage
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
RR.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Text)
-> Text
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Namespace -> Text
rawNamespace WorkflowHandle a
h.workflowHandleClient.clientConfig.namespace
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
RR.execution
(forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution)
-> WorkflowExecution
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowExecution
forall msg. Message msg => msg
defMessage
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
Common.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId WorkflowHandle a
h.workflowHandleWorkflowId
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& case WorkflowHandle a
h.workflowHandleRunId of
Maybe RunId
Nothing -> WorkflowExecution -> WorkflowExecution
forall a. a -> a
Prelude.id
Just RunId
rId -> LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
Common.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ RunId -> Text
rawRunId RunId
rId
)
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Int32
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Int32
forall (f :: * -> *) s a.
(Functor f, HasField s "maximumPageSize" a) =>
LensLike' f s a
RR.maximumPageSize (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Int32)
-> Int32
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Int32
100
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "waitNewEvent" a) =>
LensLike' f s a
RR.waitNewEvent (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool)
-> Bool
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Bool
False
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType
forall {f :: * -> *}.
Identical f =>
LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType
forall (f :: * -> *) s a.
(Functor f, HasField s "historyEventFilterType" a) =>
LensLike' f s a
RR.historyEventFilterType (forall {f :: * -> *}.
Identical f =>
LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType)
-> HistoryEventFilterType
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ HistoryEventFilterType
HISTORY_EVENT_FILTER_TYPE_ALL_EVENT
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "skipArchival" a) =>
LensLike' f s a
RR.skipArchival (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool)
-> Bool
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Bool
True
allEvents <- ReaderT WorkflowClient m [HistoryEvent]
-> WorkflowClient -> m [HistoryEvent]
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (ConduitT () HistoryEvent (ReaderT WorkflowClient m) ()
-> ReaderT WorkflowClient m [HistoryEvent]
forall (m :: * -> *) a. Monad m => ConduitT () a m () -> m [a]
sourceToList (FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent (ReaderT WorkflowClient m) ()
forall (m :: * -> *).
(MonadIO m, HasWorkflowClient m) =>
FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
streamEvents FollowOption
FollowRuns GetWorkflowExecutionHistoryRequest
startingReq)) WorkflowHandle a
h.workflowHandleClient
pure $ build (History.events .~ allEvents)
applyNewExecutionRunId
:: HasField s "newExecutionRunId" Text
=> s
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
applyNewExecutionRunId :: forall s.
HasField s "newExecutionRunId" Text =>
s
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
applyNewExecutionRunId s
attrs GetWorkflowExecutionHistoryRequest
req Maybe GetWorkflowExecutionHistoryRequest
alt =
if s
attrs s -> FoldLike Text s s Text Text -> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike Text s s Text Text
forall (f :: * -> *) s a.
(Functor f, HasField s "newExecutionRunId" a) =>
LensLike' f s a
History.newExecutionRunId Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
""
then Maybe GetWorkflowExecutionHistoryRequest
alt
else
let exec :: WorkflowExecution
exec = GetWorkflowExecutionHistoryRequest
req GetWorkflowExecutionHistoryRequest
-> FoldLike
WorkflowExecution
GetWorkflowExecutionHistoryRequest
GetWorkflowExecutionHistoryRequest
WorkflowExecution
WorkflowExecution
-> WorkflowExecution
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
WorkflowExecution
GetWorkflowExecutionHistoryRequest
GetWorkflowExecutionHistoryRequest
WorkflowExecution
WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
RR.execution
in GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall a. a -> Maybe a
Just
( GetWorkflowExecutionHistoryRequest
req
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
RR.execution (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution)
-> WorkflowExecution
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (WorkflowExecution
exec WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
RR.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ (s
attrs s -> FoldLike Text s s Text Text -> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike Text s s Text Text
forall (f :: * -> *) s a.
(Functor f, HasField s "newExecutionRunId" a) =>
LensLike' f s a
History.newExecutionRunId))
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "nextPageToken" a) =>
LensLike' f s a
RR.nextPageToken (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString)
-> ByteString
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ByteString
""
)
streamEvents
:: (MonadIO m, HasWorkflowClient m)
=> FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
streamEvents :: forall (m :: * -> *).
(MonadIO m, HasWorkflowClient m) =>
FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
streamEvents FollowOption
followOpt GetWorkflowExecutionHistoryRequest
baseReq = ConduitT () HistoryEvent m WorkflowClient
forall (m :: * -> *). HasWorkflowClient m => m WorkflowClient
askWorkflowClient ConduitT () HistoryEvent m WorkflowClient
-> (WorkflowClient -> ConduitT () HistoryEvent m ())
-> ConduitT () HistoryEvent m ()
forall a b.
ConduitT () HistoryEvent m a
-> (a -> ConduitT () HistoryEvent m b)
-> ConduitT () HistoryEvent m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \WorkflowClient
c -> WorkflowClient
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
go WorkflowClient
c GetWorkflowExecutionHistoryRequest
baseReq
where
go :: WorkflowClient
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
go WorkflowClient
c GetWorkflowExecutionHistoryRequest
req = do
res <- IO (Either RpcError GetWorkflowExecutionHistoryResponse)
-> ConduitT
()
HistoryEvent
m
(Either RpcError GetWorkflowExecutionHistoryResponse)
forall a. IO a -> ConduitT () HistoryEvent m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either RpcError GetWorkflowExecutionHistoryResponse)
-> ConduitT
()
HistoryEvent
m
(Either RpcError GetWorkflowExecutionHistoryResponse))
-> IO (Either RpcError GetWorkflowExecutionHistoryResponse)
-> ConduitT
()
HistoryEvent
m
(Either RpcError GetWorkflowExecutionHistoryResponse)
forall a b. (a -> b) -> a -> b
$ Client
-> GetWorkflowExecutionHistoryRequest
-> IO (Either RpcError GetWorkflowExecutionHistoryResponse)
getWorkflowExecutionHistory WorkflowClient
c.clientCore GetWorkflowExecutionHistoryRequest
req
case res of
Left RpcError
err -> RpcError -> ConduitT () HistoryEvent m ()
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO RpcError
err
Right GetWorkflowExecutionHistoryResponse
x -> do
[HistoryEvent] -> ConduitT () (Element [HistoryEvent]) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany (GetWorkflowExecutionHistoryResponse
x GetWorkflowExecutionHistoryResponse
-> FoldLike
[HistoryEvent]
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
[HistoryEvent]
[HistoryEvent]
-> [HistoryEvent]
forall s a t b. s -> FoldLike a s t a b -> a
^. LensLike'
(Constant [HistoryEvent])
GetWorkflowExecutionHistoryResponse
History
forall (f :: * -> *) s a.
(Functor f, HasField s "history" a) =>
LensLike' f s a
RR.history LensLike'
(Constant [HistoryEvent])
GetWorkflowExecutionHistoryResponse
History
-> (([HistoryEvent] -> Constant [HistoryEvent] [HistoryEvent])
-> History -> Constant [HistoryEvent] History)
-> FoldLike
[HistoryEvent]
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
[HistoryEvent]
[HistoryEvent]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([HistoryEvent] -> Constant [HistoryEvent] [HistoryEvent])
-> History -> Constant [HistoryEvent] History
forall (f :: * -> *) s a.
(Functor f, HasField s "events" a) =>
LensLike' f s a
History.events)
Maybe GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ())
-> ConduitT () HistoryEvent m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryResponse
-> Maybe GetWorkflowExecutionHistoryRequest
decideLoop GetWorkflowExecutionHistoryRequest
baseReq GetWorkflowExecutionHistoryResponse
x) (WorkflowClient
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
go WorkflowClient
c)
decideLoop :: GetWorkflowExecutionHistoryRequest -> GetWorkflowExecutionHistoryResponse -> Maybe GetWorkflowExecutionHistoryRequest
decideLoop :: GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryResponse
-> Maybe GetWorkflowExecutionHistoryRequest
decideLoop GetWorkflowExecutionHistoryRequest
req GetWorkflowExecutionHistoryResponse
res =
if Vector HistoryEvent -> Bool
forall a. Vector a -> Bool
V.null (GetWorkflowExecutionHistoryResponse
res GetWorkflowExecutionHistoryResponse
-> FoldLike
(Vector HistoryEvent)
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
(Vector HistoryEvent)
(Vector HistoryEvent)
-> Vector HistoryEvent
forall s a t b. s -> FoldLike a s t a b -> a
^. LensLike'
(Constant (Vector HistoryEvent))
GetWorkflowExecutionHistoryResponse
History
forall (f :: * -> *) s a.
(Functor f, HasField s "history" a) =>
LensLike' f s a
RR.history LensLike'
(Constant (Vector HistoryEvent))
GetWorkflowExecutionHistoryResponse
History
-> ((Vector HistoryEvent
-> Constant (Vector HistoryEvent) (Vector HistoryEvent))
-> History -> Constant (Vector HistoryEvent) History)
-> FoldLike
(Vector HistoryEvent)
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
(Vector HistoryEvent)
(Vector HistoryEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector HistoryEvent
-> Constant (Vector HistoryEvent) (Vector HistoryEvent))
-> History -> Constant (Vector HistoryEvent) History
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'events" a) =>
LensLike' f s a
History.vec'events)
then Maybe GetWorkflowExecutionHistoryRequest
nextPage
else case Vector HistoryEvent -> HistoryEvent
forall a. Vector a -> a
V.last (GetWorkflowExecutionHistoryResponse
res GetWorkflowExecutionHistoryResponse
-> FoldLike
(Vector HistoryEvent)
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
(Vector HistoryEvent)
(Vector HistoryEvent)
-> Vector HistoryEvent
forall s a t b. s -> FoldLike a s t a b -> a
^. LensLike'
(Constant (Vector HistoryEvent))
GetWorkflowExecutionHistoryResponse
History
forall (f :: * -> *) s a.
(Functor f, HasField s "history" a) =>
LensLike' f s a
RR.history LensLike'
(Constant (Vector HistoryEvent))
GetWorkflowExecutionHistoryResponse
History
-> ((Vector HistoryEvent
-> Constant (Vector HistoryEvent) (Vector HistoryEvent))
-> History -> Constant (Vector HistoryEvent) History)
-> FoldLike
(Vector HistoryEvent)
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
(Vector HistoryEvent)
(Vector HistoryEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector HistoryEvent
-> Constant (Vector HistoryEvent) (Vector HistoryEvent))
-> History -> Constant (Vector HistoryEvent) History
forall (f :: * -> *) s a.
(Functor f, HasField s "vec'events" a) =>
LensLike' f s a
History.vec'events) HistoryEvent
-> FoldLike
(Maybe HistoryEvent'Attributes)
HistoryEvent
HistoryEvent
(Maybe HistoryEvent'Attributes)
(Maybe HistoryEvent'Attributes)
-> Maybe HistoryEvent'Attributes
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
(Maybe HistoryEvent'Attributes)
HistoryEvent
HistoryEvent
(Maybe HistoryEvent'Attributes)
(Maybe HistoryEvent'Attributes)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'attributes" a) =>
LensLike' f s a
History.maybe'attributes of
Maybe HistoryEvent'Attributes
Nothing -> Maybe GetWorkflowExecutionHistoryRequest
nextPage
Just HistoryEvent'Attributes
attrType ->
case HistoryEvent'Attributes
attrType of
HistoryEvent'WorkflowExecutionCompletedEventAttributes WorkflowExecutionCompletedEventAttributes
attrs -> case FollowOption
followOpt of
FollowOption
FollowRuns -> WorkflowExecutionCompletedEventAttributes
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall s.
HasField s "newExecutionRunId" Text =>
s
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
applyNewExecutionRunId WorkflowExecutionCompletedEventAttributes
attrs GetWorkflowExecutionHistoryRequest
req Maybe GetWorkflowExecutionHistoryRequest
nextPage
FollowOption
ThisRunOnly -> Maybe GetWorkflowExecutionHistoryRequest
nextPage
HistoryEvent'WorkflowExecutionFailedEventAttributes WorkflowExecutionFailedEventAttributes
attrs -> case FollowOption
followOpt of
FollowOption
FollowRuns -> WorkflowExecutionFailedEventAttributes
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall s.
HasField s "newExecutionRunId" Text =>
s
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
applyNewExecutionRunId WorkflowExecutionFailedEventAttributes
attrs GetWorkflowExecutionHistoryRequest
req Maybe GetWorkflowExecutionHistoryRequest
nextPage
FollowOption
ThisRunOnly -> Maybe GetWorkflowExecutionHistoryRequest
nextPage
HistoryEvent'WorkflowExecutionTimedOutEventAttributes WorkflowExecutionTimedOutEventAttributes
attrs -> case FollowOption
followOpt of
FollowOption
FollowRuns -> WorkflowExecutionTimedOutEventAttributes
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall s.
HasField s "newExecutionRunId" Text =>
s
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
applyNewExecutionRunId WorkflowExecutionTimedOutEventAttributes
attrs GetWorkflowExecutionHistoryRequest
req Maybe GetWorkflowExecutionHistoryRequest
nextPage
FollowOption
ThisRunOnly -> Maybe GetWorkflowExecutionHistoryRequest
nextPage
HistoryEvent'WorkflowExecutionContinuedAsNewEventAttributes WorkflowExecutionContinuedAsNewEventAttributes
attrs -> case FollowOption
followOpt of
FollowOption
FollowRuns ->
if WorkflowExecutionContinuedAsNewEventAttributes
attrs WorkflowExecutionContinuedAsNewEventAttributes
-> FoldLike
Text
WorkflowExecutionContinuedAsNewEventAttributes
WorkflowExecutionContinuedAsNewEventAttributes
Text
Text
-> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
Text
WorkflowExecutionContinuedAsNewEventAttributes
WorkflowExecutionContinuedAsNewEventAttributes
Text
Text
forall (f :: * -> *) s a.
(Functor f, HasField s "newExecutionRunId" a) =>
LensLike' f s a
History.newExecutionRunId Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
""
then [Char] -> Maybe GetWorkflowExecutionHistoryRequest
forall a. HasCallStack => [Char] -> a
error [Char]
"Expected newExecutionRunId in WorkflowExecutionContinuedAsNewEventAttributes"
else
GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall a. a -> Maybe a
Just (GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall a b. (a -> b) -> a -> b
$
GetWorkflowExecutionHistoryRequest
req
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "nextPageToken" a) =>
LensLike' f s a
RR.nextPageToken (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString)
-> ByteString
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ByteString
""
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
RR.execution (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution)
-> (WorkflowExecution -> WorkflowExecution)
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> (a -> b) -> s -> t
%~ (LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
RR.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ (WorkflowExecutionContinuedAsNewEventAttributes
attrs WorkflowExecutionContinuedAsNewEventAttributes
-> FoldLike
Text
WorkflowExecutionContinuedAsNewEventAttributes
WorkflowExecutionContinuedAsNewEventAttributes
Text
Text
-> Text
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
Text
WorkflowExecutionContinuedAsNewEventAttributes
WorkflowExecutionContinuedAsNewEventAttributes
Text
Text
forall (f :: * -> *) s a.
(Functor f, HasField s "newExecutionRunId" a) =>
LensLike' f s a
History.newExecutionRunId))
FollowOption
ThisRunOnly -> Maybe GetWorkflowExecutionHistoryRequest
forall a. Maybe a
Nothing
HistoryEvent'Attributes
_ -> Maybe GetWorkflowExecutionHistoryRequest
forall a. Maybe a
Nothing
where
nextPage :: Maybe GetWorkflowExecutionHistoryRequest
nextPage =
if GetWorkflowExecutionHistoryResponse
res GetWorkflowExecutionHistoryResponse
-> FoldLike
ByteString
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
ByteString
ByteString
-> ByteString
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
ByteString
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
ByteString
ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "nextPageToken" a) =>
LensLike' f s a
RR.nextPageToken ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
""
then Maybe GetWorkflowExecutionHistoryRequest
forall a. Maybe a
Nothing
else GetWorkflowExecutionHistoryRequest
-> Maybe GetWorkflowExecutionHistoryRequest
forall a. a -> Maybe a
Just (GetWorkflowExecutionHistoryRequest
req GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "nextPageToken" a) =>
LensLike' f s a
RR.nextPageToken (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest ByteString)
-> ByteString
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ (GetWorkflowExecutionHistoryResponse
res GetWorkflowExecutionHistoryResponse
-> FoldLike
ByteString
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
ByteString
ByteString
-> ByteString
forall s a t b. s -> FoldLike a s t a b -> a
^. FoldLike
ByteString
GetWorkflowExecutionHistoryResponse
GetWorkflowExecutionHistoryResponse
ByteString
ByteString
forall (f :: * -> *) s a.
(Functor f, HasField s "nextPageToken" a) =>
LensLike' f s a
RR.nextPageToken))
waitResult
:: (MonadIO m, HasWorkflowClient m)
=> WorkflowId
-> Maybe RunId
-> Namespace
-> m (Maybe HistoryEvent)
waitResult :: forall (m :: * -> *).
(MonadIO m, HasWorkflowClient m) =>
WorkflowId -> Maybe RunId -> Namespace -> m (Maybe HistoryEvent)
waitResult WorkflowId
wfId Maybe RunId
mrId (Namespace Text
ns) = do
let startingReq :: GetWorkflowExecutionHistoryRequest
startingReq :: GetWorkflowExecutionHistoryRequest
startingReq =
GetWorkflowExecutionHistoryRequest
forall msg. Message msg => msg
defMessage
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Text
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Text
forall (f :: * -> *) s a.
(Functor f, HasField s "namespace" a) =>
LensLike' f s a
RR.namespace (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Text)
-> Text
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Text
ns
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution
forall (f :: * -> *) s a.
(Functor f, HasField s "execution" a) =>
LensLike' f s a
RR.execution
(forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest WorkflowExecution)
-> WorkflowExecution
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ ( WorkflowExecution
forall msg. Message msg => msg
defMessage
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "workflowId" a) =>
LensLike' f s a
Common.workflowId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ WorkflowId -> Text
rawWorkflowId WorkflowId
wfId
WorkflowExecution
-> (WorkflowExecution -> WorkflowExecution) -> WorkflowExecution
forall s t. s -> (s -> t) -> t
& case Maybe RunId
mrId of
Maybe RunId
Nothing -> WorkflowExecution -> WorkflowExecution
forall a. a -> a
Prelude.id
Just RunId
rId -> LensLike' f WorkflowExecution Text
forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text
forall (f :: * -> *) s a.
(Functor f, HasField s "runId" a) =>
LensLike' f s a
Common.runId (forall {f :: * -> *}.
Identical f =>
LensLike' f WorkflowExecution Text)
-> Text -> WorkflowExecution -> WorkflowExecution
forall s t a b. Setter s t a b -> b -> s -> t
.~ RunId -> Text
rawRunId RunId
rId
)
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Int32
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Int32
forall (f :: * -> *) s a.
(Functor f, HasField s "maximumPageSize" a) =>
LensLike' f s a
RR.maximumPageSize (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Int32)
-> Int32
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Int32
100
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "waitNewEvent" a) =>
LensLike' f s a
RR.waitNewEvent (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool)
-> Bool
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Bool
True
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType
forall {f :: * -> *}.
Identical f =>
LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType
forall (f :: * -> *) s a.
(Functor f, HasField s "historyEventFilterType" a) =>
LensLike' f s a
RR.historyEventFilterType (forall {f :: * -> *}.
Identical f =>
LensLike'
f GetWorkflowExecutionHistoryRequest HistoryEventFilterType)
-> HistoryEventFilterType
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ HistoryEventFilterType
HISTORY_EVENT_FILTER_TYPE_CLOSE_EVENT
GetWorkflowExecutionHistoryRequest
-> (GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest)
-> GetWorkflowExecutionHistoryRequest
forall s t. s -> (s -> t) -> t
& LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "skipArchival" a) =>
LensLike' f s a
RR.skipArchival (forall {f :: * -> *}.
Identical f =>
LensLike' f GetWorkflowExecutionHistoryRequest Bool)
-> Bool
-> GetWorkflowExecutionHistoryRequest
-> GetWorkflowExecutionHistoryRequest
forall s t a b. Setter s t a b -> b -> s -> t
.~ Bool
True
ConduitT () HistoryEvent m ()
-> ConduitT HistoryEvent Void m (Maybe HistoryEvent)
-> m (Maybe HistoryEvent)
forall (m :: * -> *) a r.
Monad m =>
ConduitT () a m () -> ConduitT a Void m r -> m r
connect (FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
forall (m :: * -> *).
(MonadIO m, HasWorkflowClient m) =>
FollowOption
-> GetWorkflowExecutionHistoryRequest
-> ConduitT () HistoryEvent m ()
streamEvents FollowOption
FollowRuns GetWorkflowExecutionHistoryRequest
startingReq) ConduitT HistoryEvent Void m (Maybe HistoryEvent)
forall (m :: * -> *) a o. Monad m => ConduitT a o m (Maybe a)
lastC