{-# 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
Description: Invoke and interact with Temporal Workflows.

Workflow Clients are embedded in your application code and connect to a Temporal Server.

They are used to start new workflows and to signal existing workflows.
-}
module Temporal.Client (
  -- * Workflow Client
  WorkflowClient,
  workflowClient,
  WorkflowClientConfig (..),
  mkWorkflowClientConfig,
  HasWorkflowClient (..),

  -- * Running Workflows
  StartWorkflowOptions (..),
  TimeoutOptions (..),
  startWorkflowOptions,
  Temporal.Client.start,
  startFromPayloads,
  WorkflowHandle,
  execute,
  waitWorkflowResult,

  -- * Closing Workflows
  TerminationOptions (..),
  terminate,

  -- * Querying Workflows
  QueryOptions (..),
  QueryRejectCondition (..),
  QueryRejected (..),
  Temporal.Client.Types.WorkflowExecutionStatus (..),
  defaultQueryOptions,
  query,

  -- * Sending Signals to Workflows
  SignalOptions (..),
  KnownSignal (..),
  signal,
  defaultSignalOptions,
  Temporal.Client.signalWithStart,

  -- * Producing handles for existing workflows
  getHandle,

  -- * Workflow history utilities
  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 stuff

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


{- | Run a workflow, synchronously waiting for it to complete.

This function will block until the workflow completes, and will return the result of the workflow
or throw a 'WorkflowExecutionClosed' exception if the workflow was closed without returning a result.
-}
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


{- | Given a 'WorkflowHandle', wait for the workflow to complete and return the result.

This function will block until the workflow completes, and will return the result of the workflow
or throw a 'WorkflowExecutionClosed' exception if the workflow was closed without returning a result.
-}
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)
          -- LMAO this is such a comical coercion
          --
          -- We just need to ignore payloads if the result type is unit to allow workflows to evolve
          -- such that they can return something else in the future.
          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
  -- ^ Used to de-dupe sent signals
  , SignalOptions -> Bool
skipGenerateWorkflowTask :: Bool
  -- ^ Indicates that a new workflow task should not be generated when this signal is received.
  --
  -- Defaults to False.
  --
  -- Generally this is not needed.
  , SignalOptions -> Map Text Payload
headers :: 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
    }


{- | A Signal is an asynchronous request to a Workflow Execution.

A Signal delivers data to a running Workflow Execution. It cannot return data to the caller;
to do so, use a Query instead. The Workflow code that handles a Signal can mutate Workflow state.
A Signal can be sent from a Temporal Client or a Workflow. When a Signal is sent, it is received
by the Cluster and recorded as an Event to the Workflow Execution Event History. A successful
response from the Cluster means that the Signal has been persisted and will be delivered at least
once to the Workflow Execution. The next scheduled Workflow Task will contain the Signal Event.

Signal handlers are Workflow functions that listen for Signals by the Signal name. Signals are delivered
in the order they are received by the Cluster. If multiple deliveries of a Signal would be a problem for
your Workflow, add idempotency logic to your Signal handler that checks for duplicates.
-}
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
        -- Deprecated, no need to set
        -- & WF.control .~ _
        -- TODO put other useful headers in here
        & 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
  { -- queryId :: Text
    -- ,
    QueryOptions -> QueryRejectCondition
queryRejectCondition :: QueryRejectCondition
  , QueryOptions -> Map Text Payload
queryHeaders :: 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
    }


{- | A Query is a synchronous operation that is used to get the state of a Workflow Execution. The state of a running Workflow Execution is constantly changing. You can use Queries to expose the internal Workflow Execution state to the external world. Queries are available for running or completed Workflows Executions only if the Worker is up and listening on the Task Queue.

Queries are sent from a Temporal Client to a Workflow Execution. The API call is synchronous. The Query is identified at both ends by a Query name. The Workflow must have a Query handler that is developed to handle that Query and provide data that represents the state of the Workflow Execution.

Queries are strongly consistent and are guaranteed to return the most recent state. This means that the data reflects the state of all confirmed Events that came in before the Query was sent. An Event is considered confirmed if the call creating the Event returned success. Events that are created while the Query is outstanding may or may not be reflected in the Workflow state the Query result is based on.

A Query can carry arguments to specify the data it is requesting. And each Workflow can expose data to multiple types of Queries.

A Query must never mutate the state of the Workflow Execution—that is, Queries are read-only and cannot contain any blocking code. This means, for example, that Query handling logic cannot schedule Activity Executions.

For the Haskell library, this means that the only state that is accessible to a Query is 'Info' and values in 'StateVar's.

Sending Queries to completed Workflow Executions is supported, though Query reject conditions can be configured per Query.
-}
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


{- | Sometimes you know that a Workflow exists or existed, but you didn't create the workflow from
the current process or code path. In this case, you can use 'getHandle' to get a handle to the
workflow so that you can interact with it.

Note that it is possible for a workflow to be closed or archived by the time you get a handle,
so you should be prepared to handle 'WorkflowExecutionClosed' exceptions.
-}
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
      }


-- TODO
-- list
--   :: MonadIO m
--   => WorkflowClient
--   -> ListWorkflowOptions
--   -> m [WorkflowId]

{- | Start a new Workflow Execution from an unchecked list of payloads. This can be useful if you are forwarding
execution from another Workflow or from an external source, but no checking to make sure that the input
types are correct is performed.
-}
startFromPayloads
  :: (MonadIO m, HasWorkflowClient m)
  => KnownWorkflow args result
  -> WorkflowId
  -- ^ A Workflow Id is a customizable, application-level identifier for a Workflow Execution that is unique to an Open Workflow Execution within a Namespace.
  --
  -- A Workflow Id is meant to be a business-process identifier such as customer identifier or order identifier.
  --
  -- A Workflow Id Reuse Policy can be used to manage whether a Workflow Id can be re-used. The Temporal Platform guarantees uniqueness of the Workflow Id within a Namespace based on the Workflow Id Reuse Policy.
  --
  -- A Workflow Execution can be uniquely identified across all Namespaces by its Namespace, Workflow Id, and Run Id.
  -> 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)
            --     TODO Not sure how to use these yet
            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
            {-
              These values will be available as ContinuedFailure and LastCompletionResult in the
              WorkflowExecutionStarted event and through SDKs. The are currently only used by the
              server itself (for the schedules feature) and are not intended to be exposed in
              StartWorkflowExecution.

              WF.continuedFailure
              WF.lastCompletionResult
            -}
            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
      }


{- | Begin a new Workflow Execution.

This function does not wait for the Workflow to complete. Instead, it returns a 'WorkflowHandle'
that can be used to wait for the Workflow to complete or perform other operations.

This can be used to "fire-and-forget" a Workflow by discarding the handle.
-}
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


{- | If there is a running Workflow Execution with the given Workflow Id, it will be Signaled.

Otherwise, a new Workflow Execution is started and immediately send the Signal.
-}
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')
                -- Deprecated, no need to set
                -- & RR.control .~ _
                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)
        -- & RR.workflowStartDelay .~ _
        -- & RR.skipGenerateWorkflowTask .~ _
        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
  -- ^ If set, this call will error if the (most recent | specified workflow run id in the WorkflowHandle) is not part of the same
  -- execution chain as this id.
  }


{- | Terminating a workflow immediately signals to the worker that the workflow should
cease execution. The workflow will not be given a chance to react to the termination.
-}
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


-- | Thrown when 'FollowOption' is 'ThisRunOnly' and the workflow continues as new.
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


{- | Fetch the history of a Workflow execution as it currently stands.

This is useful for Workflow replay tests.
-}
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
""
          )


{- | Workflow execution history is represented as a series of events. This function allows you to
subscribe to those events and process them as they are received. As an example, this is used to implement
'waitWorkflowResult'.
-}
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 {- options incl 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

-- listOpenWorkflowExecutions
--   :: (MonadIO m, HasWorkflowClient m)
--   => ListOpenWorkflowExecutionsRequest
--   -> ConduitT () WorkflowExecutionInfo m ()

-- listClosedWorkflowExecutions
--   :: (MonadIO m, HasWorkflowClient m)
--   => ListClosedWorkflowExecutionsRequest
--   -> ConduitT () WorkflowExecutionInfo m ()

-- scanWorkflowExecutions
--   :: (MonadIO m, HasWorkflowClient m)
--   => ScanWorkflowExecutionsRequest
--   -> ConduitT () WorkflowExecutionInfo m ()

-- countWorkflowExecutions
--   :: (MonadIO m, HasWorkflowClient m)
--   => CountWorkflowExecutionsRequest
--   -> m Int64