{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Arbiter.Core.HighLevel
(
QueueOperation
, JobOperation
, queueTable
, RegistryAdmissionPolicies
, insertJob
, insertJobsBatch
, insertJobsBatch_
, claimNextVisibleJobs
, claimNextVisibleJobsAs
, claimNextVisibleJobsBatched
, mkClaimSql
, addRateLimitTokens
, pruneRateLimitBuckets
, resetRateLimitBuckets
, listRateLimitPolicies
, getRateLimitPolicy
, rateLimitPolicyExists
, listRateLimitBuckets
, listConcurrencyPolicies
, getConcurrencyPolicy
, listConcurrencyKeys
, updateRateLimitPolicyOverrides
, setRateLimit
, clearRateLimit
, updateConcurrencyPolicyOverrides
, setConcurrencyLimit
, clearConcurrencyLimit
, pruneConcurrencyKeys
, reconcileConcurrencyCounts
, reconcileConcurrencyCountsIfStale
, reconcileAndPruneConcurrency
, ackJob
, ackJobsBatch
, updateJobForRetry
, nackJob
, nackJobsBatch
, setVisibilityTimeout
, setVisibilityTimeoutBatch
, SetVisibilityResult (..)
, Ops.JobFilter (..)
, listJobsFiltered
, countJobsFiltered
, listDLQFiltered
, countDLQFiltered
, moveToDLQ
, moveToDLQBatch
, listDLQJobs
, listArchiveJobs
, getArchivedJobById
, listArchivedJobsByGroupKey
, deleteArchiveJob
, deleteArchiveJobsBatch
, reEnqueueFromArchive
, retryFromDLQ
, dlqJobExists
, deleteDLQJob
, deleteDLQJobsBatch
, listJobs
, getJobById
, jobExists
, getJobsByGroup
, getJobsByParent
, cancelJob
, cancelJobsBatch
, forceCancelJob
, promoteJob
, Ops.QueueStats (..)
, getQueueStats
, countJobs
, countJobsByGroup
, countJobsByParent
, countDLQJobs
, countChildrenBatch
, countDLQChildren
, countDLQChildrenBatch
, pauseChildren
, resumeChildren
, cancelJobCascade
, suspendJob
, resumeJob
, insertResult
, insertResultUnsafe
, getResultsByParent
, getDLQChildErrorsByParent
, readChildResultsRaw
, Ops.mergeRawChildResults
, persistParentState
, getParentStateSnapshot
, refreshAllGroupsFully
, registerWorker
, heartbeatWorker
, setWorkerPaused
, markWorkerShuttingDown
, deregisterWorker
, listWorkers
, sweepStaleWorkers
, WorkerRow (..)
, ensureQueue
, setQueuePaused
, getQueue
, listQueues
, QueueRow (..)
, listCronSchedules
, getCronScheduleByName
, updateCronScheduleUnchecked
, runGated
, insertJobTree
, getSchema
) where
import Control.Monad (void, when)
import Data.Aeson (Value)
import Data.Int (Int32, Int64)
import Data.List.NonEmpty (NonEmpty (..))
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe (fromMaybe)
import Data.Proxy (Proxy (..))
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time (NominalDiffTime)
import Data.UUID.Types (UUID)
import GHC.TypeLits (KnownSymbol, symbolVal)
import UnliftIO (MonadUnliftIO)
import Arbiter.Core.Admission (AdmissionPolicy (..))
import Arbiter.Core.Concurrency.Spec (ConcurrencyPolicy)
import Arbiter.Core.Concurrency.Stats (ConcurrencyKeyView, ConcurrencyPolicyUpdate (..), ConcurrencyPolicyView)
import Arbiter.Core.CronSchedule (CronScheduleRow, CronScheduleUpdate)
import Arbiter.Core.HighLevel.Runtime
( deregisterWorker
, ensureQueue
, getQueue
, heartbeatWorker
, listQueues
, listWorkers
, markWorkerShuttingDown
, registerWorker
, setQueuePaused
, setWorkerPaused
, sweepStaleWorkers
)
import Arbiter.Core.Job.Archive qualified as Archive
import Arbiter.Core.Job.DLQ qualified as DLQ
import Arbiter.Core.Job.Types
( ClaimSeq
, HasKind
, JobId
, JobPayload
, JobRead
, JobWrite
, RegistryAdmissionPolicies
, claimSeq
, claimedBy
, kindsFor
, primaryKey
)
import Arbiter.Core.Job.Types qualified as Job
import Arbiter.Core.JobResult (EncodeJobResult, encodeJobResult)
import Arbiter.Core.JobTree qualified as JT
import Arbiter.Core.MonadArbiter (MonadArbiter (..), ResultOf)
import Arbiter.Core.Operations qualified as Ops
import Arbiter.Core.QueueRegistry (RegistryTables (..), TableForPayload)
import Arbiter.Core.Queues (QueueRow (..))
import Arbiter.Core.RateLimit.Spec (Policy (..), RateLimitKey (..))
import Arbiter.Core.RateLimit.Stats (RateLimitBucketView, RateLimitPolicyUpdate (..), RateLimitPolicyView)
import Arbiter.Core.Trace (withPublishSpan)
import Arbiter.Core.Worker (WorkerRow (..))
type QueueOperation m payload =
( JobPayload payload
, KnownSymbol (TableForPayload payload (RegistryOf m))
, MonadArbiter m
)
type JobOperation m payload =
( JobPayload payload
, MonadArbiter m
)
queueTable :: forall payload m. (KnownSymbol (TableForPayload payload (RegistryOf m))) => Text
queueTable :: forall payload (m :: * -> *).
KnownSymbol (TableForPayload payload (RegistryOf m)) =>
Text
queueTable = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Proxy (SpecName (MatchIn payload '[] (RegistryOf m))) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(TableForPayload payload (RegistryOf m)))
onQueue
:: forall payload m a
. (KnownSymbol (TableForPayload payload (RegistryOf m)), MonadArbiter m)
=> (Text -> Text -> m a)
-> m a
onQueue :: forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue Text -> Text -> m a
operation = m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema m Text -> (Text -> m a) -> m a
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
schemaName -> Text -> Text -> m a
operation Text
schemaName (forall payload (m :: * -> *).
KnownSymbol (TableForPayload payload (RegistryOf m)) =>
Text
queueTable @payload @m)
publishSpan
:: forall payload m a
. (HasKind payload, KnownSymbol (TableForPayload payload (RegistryOf m)), MonadUnliftIO m)
=> [JobWrite payload]
-> m a
-> m a
publishSpan :: forall payload (m :: * -> *) a.
(HasKind payload,
KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadUnliftIO m) =>
[JobWrite payload] -> m a -> m a
publishSpan = Text -> [JobWrite payload] -> m a -> m a
forall payload (m :: * -> *) a.
(HasKind payload, MonadUnliftIO m) =>
Text -> [JobWrite payload] -> m a -> m a
withPublishSpan (forall payload (m :: * -> *).
KnownSymbol (TableForPayload payload (RegistryOf m)) =>
Text
queueTable @payload @m)
insertJob
:: forall payload m
. (QueueOperation m payload)
=> JobWrite payload
-> m (Maybe (JobRead payload))
insertJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
JobWrite payload -> m (Maybe (JobRead payload))
insertJob JobWrite payload
job = forall payload (m :: * -> *) a.
(HasKind payload,
KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadUnliftIO m) =>
[JobWrite payload] -> m a -> m a
publishSpan @payload [JobWrite payload
job] (m (Maybe (JobRead payload)) -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload)) -> m (Maybe (JobRead payload))
forall a b. (a -> b) -> a -> b
$ forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload)))
-> (Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> JobWrite payload -> m (Maybe (JobRead payload))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> JobWrite payload -> m (Maybe (JobRead payload))
Ops.insertJob Text
schemaName Text
tableName JobWrite payload
job
insertJobsBatch
:: forall payload m
. (QueueOperation m payload)
=> [JobWrite payload]
-> m [JobRead payload]
insertJobsBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobWrite payload] -> m [JobRead payload]
insertJobsBatch [] = [JobRead payload] -> m [JobRead payload]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
insertJobsBatch [JobWrite payload]
jobs = forall payload (m :: * -> *) a.
(HasKind payload,
KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadUnliftIO m) =>
[JobWrite payload] -> m a -> m a
publishSpan @payload [JobWrite payload]
jobs (m [JobRead payload] -> m [JobRead payload])
-> m [JobRead payload] -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobWrite payload] -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> [JobWrite payload] -> m [JobRead payload]
Ops.insertJobsBatch Text
schemaName Text
tableName [JobWrite payload]
jobs
insertJobsBatch_
:: forall payload m
. (QueueOperation m payload)
=> [JobWrite payload]
-> m Int64
insertJobsBatch_ :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobWrite payload] -> m Int64
insertJobsBatch_ [] = Int64 -> m Int64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int64
0
insertJobsBatch_ [JobWrite payload]
jobs = forall payload (m :: * -> *) a.
(HasKind payload,
KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadUnliftIO m) =>
[JobWrite payload] -> m a -> m a
publishSpan @payload [JobWrite payload]
jobs (m Int64 -> m Int64) -> m Int64 -> m Int64
forall a b. (a -> b) -> a -> b
$ forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobWrite payload] -> m Int64
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> [JobWrite payload] -> m Int64
Ops.insertJobsBatch_ Text
schemaName Text
tableName [JobWrite payload]
jobs
claimNextVisibleJobs
:: forall payload m
. (QueueOperation m payload)
=> Int
-> NominalDiffTime
-> m [JobRead payload]
claimNextVisibleJobs :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> NominalDiffTime -> m [JobRead payload]
claimNextVisibleJobs Int
limit NominalDiffTime
timeout = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int -> NominalDiffTime -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int -> NominalDiffTime -> m [JobRead payload]
Ops.claimNextVisibleJobs Text
schemaName Text
tableName Int
limit NominalDiffTime
timeout
addRateLimitTokens
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> RateLimitKey
-> Double
-> m ()
addRateLimitTokens :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
RateLimitKey -> Double -> m ()
addRateLimitTokens RateLimitKey
key Double
amount = m () -> m ()
forall a. m a -> m a
forall (m :: * -> *) a. MonadArbiter m => m a -> m a
withDbTransaction (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.addRateLimitTokens schemaName key amount
let queues = Proxy (RegistryOf m) -> [Text]
forall (registry :: JobPayloadRegistry).
RegistryTables registry =>
Proxy registry -> [Text]
registryTableNames (forall (t :: JobPayloadRegistry). Proxy t
forall {k} (t :: k). Proxy t
Proxy @(RegistryOf m))
void $ Ops.wakeThrottledJobsForKey schemaName queues key
setRateLimit :: (MonadArbiter m, RegistryTables (RegistryOf m)) => Policy -> m Int64
setRateLimit :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Policy -> m Int64
setRateLimit Policy
policy =
Text -> RateLimitPolicyUpdate -> m Int64
forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Text -> RateLimitPolicyUpdate -> m Int64
updateRateLimitPolicyOverrides (Policy -> Text
forall p. AdmissionPolicy p => p -> Text
policyPrefixOf Policy
policy) (RateLimitPolicyUpdate -> m Int64)
-> RateLimitPolicyUpdate -> m Int64
forall a b. (a -> b) -> a -> b
$
RateLimitPolicyUpdate
{ overrideMaxTokens :: Maybe (Maybe Double)
overrideMaxTokens = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just (Double -> Maybe Double
forall a. a -> Maybe a
Just (Policy -> Double
policyMax Policy
policy))
, overrideRefillAmount :: Maybe (Maybe Double)
overrideRefillAmount = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just (Double -> Maybe Double
forall a. a -> Maybe a
Just (Policy -> Double
policyRefill Policy
policy))
, overrideInterval :: Maybe (Maybe Double)
overrideInterval = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just (Double -> Maybe Double
forall a. a -> Maybe a
Just (NominalDiffTime -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Policy -> NominalDiffTime
policyInterval Policy
policy)))
}
clearRateLimit :: (MonadArbiter m, RegistryTables (RegistryOf m)) => Policy -> m Int64
clearRateLimit :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Policy -> m Int64
clearRateLimit Policy
policy =
Text -> RateLimitPolicyUpdate -> m Int64
forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Text -> RateLimitPolicyUpdate -> m Int64
updateRateLimitPolicyOverrides (Policy -> Text
forall p. AdmissionPolicy p => p -> Text
policyPrefixOf Policy
policy) (RateLimitPolicyUpdate -> m Int64)
-> RateLimitPolicyUpdate -> m Int64
forall a b. (a -> b) -> a -> b
$
RateLimitPolicyUpdate
{ overrideMaxTokens :: Maybe (Maybe Double)
overrideMaxTokens = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just Maybe Double
forall a. Maybe a
Nothing
, overrideRefillAmount :: Maybe (Maybe Double)
overrideRefillAmount = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just Maybe Double
forall a. Maybe a
Nothing
, overrideInterval :: Maybe (Maybe Double)
overrideInterval = Maybe Double -> Maybe (Maybe Double)
forall a. a -> Maybe a
Just Maybe Double
forall a. Maybe a
Nothing
}
pruneRateLimitBuckets
:: forall m
. (MonadArbiter m)
=> NominalDiffTime
-> m Int64
pruneRateLimitBuckets :: forall (m :: * -> *). MonadArbiter m => NominalDiffTime -> m Int64
pruneRateLimitBuckets NominalDiffTime
idle = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.pruneRateLimitBuckets schemaName idle
resetRateLimitBuckets
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> Text
-> m Int64
resetRateLimitBuckets :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Text -> m Int64
resetRateLimitBuckets Text
prefix = m Int64 -> m Int64
forall a. m a -> m a
forall (m :: * -> *) a. MonadArbiter m => m a -> m a
withDbTransaction (m Int64 -> m Int64) -> m Int64 -> m Int64
forall a b. (a -> b) -> a -> b
$ do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
resetCount <- Ops.resetRateLimitBuckets schemaName prefix
let queues = Proxy (RegistryOf m) -> [Text]
forall (registry :: JobPayloadRegistry).
RegistryTables registry =>
Proxy registry -> [Text]
registryTableNames (forall (t :: JobPayloadRegistry). Proxy t
forall {k} (t :: k). Proxy t
Proxy @(RegistryOf m))
_ <- Ops.wakeThrottledJobs schemaName queues prefix
pure resetCount
listRateLimitPolicies
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m [RateLimitPolicyView]
listRateLimitPolicies :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m [RateLimitPolicyView]
listRateLimitPolicies = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.listRateLimitPolicies schemaName (registryTableNames (Proxy @(RegistryOf m)))
getRateLimitPolicy
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> Text
-> m (Maybe RateLimitPolicyView)
getRateLimitPolicy :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Text -> m (Maybe RateLimitPolicyView)
getRateLimitPolicy Text
prefix = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.getRateLimitPolicy schemaName (registryTableNames (Proxy @(RegistryOf m))) prefix
rateLimitPolicyExists
:: forall m
. (MonadArbiter m)
=> Text
-> m Bool
rateLimitPolicyExists :: forall (m :: * -> *). MonadArbiter m => Text -> m Bool
rateLimitPolicyExists Text
prefix = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.rateLimitPolicyExists schemaName prefix
listRateLimitBuckets
:: forall m
. (MonadArbiter m)
=> Text
-> Int
-> Int
-> m [RateLimitBucketView]
listRateLimitBuckets :: forall (m :: * -> *).
MonadArbiter m =>
Text -> Int -> Int -> m [RateLimitBucketView]
listRateLimitBuckets Text
prefix Int
limit Int
offset = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.listRateLimitBuckets schemaName prefix limit offset
updateRateLimitPolicyOverrides
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> Text
-> RateLimitPolicyUpdate
-> m Int64
updateRateLimitPolicyOverrides :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
Text -> RateLimitPolicyUpdate -> m Int64
updateRateLimitPolicyOverrides Text
prefix RateLimitPolicyUpdate
upd = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
affected <- Ops.updateRateLimitPolicyOverrides schemaName prefix upd
when (affected > 0) $ do
let queues = Proxy (RegistryOf m) -> [Text]
forall (registry :: JobPayloadRegistry).
RegistryTables registry =>
Proxy registry -> [Text]
registryTableNames (forall (t :: JobPayloadRegistry). Proxy t
forall {k} (t :: k). Proxy t
Proxy @(RegistryOf m))
void $ Ops.wakeThrottledJobs schemaName queues prefix
pure affected
listConcurrencyPolicies
:: forall m
. (MonadArbiter m)
=> m [ConcurrencyPolicyView]
listConcurrencyPolicies :: forall (m :: * -> *). MonadArbiter m => m [ConcurrencyPolicyView]
listConcurrencyPolicies = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.listConcurrencyPolicies schemaName
getConcurrencyPolicy
:: forall m
. (MonadArbiter m)
=> Text
-> m (Maybe ConcurrencyPolicyView)
getConcurrencyPolicy :: forall (m :: * -> *).
MonadArbiter m =>
Text -> m (Maybe ConcurrencyPolicyView)
getConcurrencyPolicy Text
prefix = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.getConcurrencyPolicy schemaName prefix
listConcurrencyKeys
:: forall m
. (MonadArbiter m)
=> Text
-> Int
-> Int
-> m [ConcurrencyKeyView]
listConcurrencyKeys :: forall (m :: * -> *).
MonadArbiter m =>
Text -> Int -> Int -> m [ConcurrencyKeyView]
listConcurrencyKeys Text
prefix Int
limit Int
offset = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.listConcurrencyKeys schemaName prefix limit offset
updateConcurrencyPolicyOverrides
:: forall m
. (MonadArbiter m)
=> Text
-> ConcurrencyPolicyUpdate
-> m Int64
updateConcurrencyPolicyOverrides :: forall (m :: * -> *).
MonadArbiter m =>
Text -> ConcurrencyPolicyUpdate -> m Int64
updateConcurrencyPolicyOverrides Text
prefix ConcurrencyPolicyUpdate
upd = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.updateConcurrencyPolicyOverrides schemaName prefix upd
setConcurrencyLimit :: (MonadArbiter m) => ConcurrencyPolicy -> Int32 -> m Int64
setConcurrencyLimit :: forall (m :: * -> *).
MonadArbiter m =>
ConcurrencyPolicy -> Int32 -> m Int64
setConcurrencyLimit ConcurrencyPolicy
pool Int32
limit =
Text -> ConcurrencyPolicyUpdate -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> ConcurrencyPolicyUpdate -> m Int64
updateConcurrencyPolicyOverrides (ConcurrencyPolicy -> Text
forall p. AdmissionPolicy p => p -> Text
policyPrefixOf ConcurrencyPolicy
pool) (Maybe (Maybe Int32) -> ConcurrencyPolicyUpdate
ConcurrencyPolicyUpdate (Maybe Int32 -> Maybe (Maybe Int32)
forall a. a -> Maybe a
Just (Int32 -> Maybe Int32
forall a. a -> Maybe a
Just Int32
limit)))
clearConcurrencyLimit :: (MonadArbiter m) => ConcurrencyPolicy -> m Int64
clearConcurrencyLimit :: forall (m :: * -> *).
MonadArbiter m =>
ConcurrencyPolicy -> m Int64
clearConcurrencyLimit ConcurrencyPolicy
pool =
Text -> ConcurrencyPolicyUpdate -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> ConcurrencyPolicyUpdate -> m Int64
updateConcurrencyPolicyOverrides (ConcurrencyPolicy -> Text
forall p. AdmissionPolicy p => p -> Text
policyPrefixOf ConcurrencyPolicy
pool) (Maybe (Maybe Int32) -> ConcurrencyPolicyUpdate
ConcurrencyPolicyUpdate (Maybe Int32 -> Maybe (Maybe Int32)
forall a. a -> Maybe a
Just Maybe Int32
forall a. Maybe a
Nothing))
pruneConcurrencyKeys
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m Int64
pruneConcurrencyKeys :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m Int64
pruneConcurrencyKeys = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.pruneConcurrencyKeys schemaName (registryTableNames (Proxy @(RegistryOf m)))
reconcileConcurrencyCounts
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m Int64
reconcileConcurrencyCounts :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m Int64
reconcileConcurrencyCounts = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.reconcileConcurrencyCounts schemaName (registryTableNames (Proxy @(RegistryOf m)))
reconcileConcurrencyCountsIfStale
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m Int64
reconcileConcurrencyCountsIfStale :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m Int64
reconcileConcurrencyCountsIfStale = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.reconcileConcurrencyCountsIfStale schemaName (registryTableNames (Proxy @(RegistryOf m)))
reconcileAndPruneConcurrency
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m Int64
reconcileAndPruneConcurrency :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m Int64
reconcileAndPruneConcurrency = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.reconcileAndPruneConcurrency schemaName (registryTableNames (Proxy @(RegistryOf m)))
mkClaimSql
:: forall payload m
. (QueueOperation m payload)
=> Int
-> Int
-> NominalDiffTime
-> UUID
-> m Ops.ClaimSql
mkClaimSql :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> Int -> NominalDiffTime -> UUID -> m ClaimSql
mkClaimSql Int
batchSize Int
poolSize NominalDiffTime
timeout UUID
workerId =
forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m ClaimSql) -> m ClaimSql)
-> (Text -> Text -> m ClaimSql) -> m ClaimSql
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName ->
ClaimSql -> m ClaimSql
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClaimSql -> m ClaimSql) -> ClaimSql -> m ClaimSql
forall a b. (a -> b) -> a -> b
$ Proxy payload
-> Text
-> Text
-> Int
-> Int
-> NominalDiffTime
-> UUID
-> ClaimSql
forall payload (proxy :: * -> *).
JobPayload payload =>
proxy payload
-> Text
-> Text
-> Int
-> Int
-> NominalDiffTime
-> UUID
-> ClaimSql
Ops.mkClaimSql (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @payload) Text
schemaName Text
tableName Int
batchSize Int
poolSize NominalDiffTime
timeout UUID
workerId
claimNextVisibleJobsAs
:: forall payload m
. (QueueOperation m payload)
=> Int
-> NominalDiffTime
-> UUID
-> m [JobRead payload]
claimNextVisibleJobsAs :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> NominalDiffTime -> UUID -> m [JobRead payload]
claimNextVisibleJobsAs Int
limit NominalDiffTime
timeout UUID
workerId =
forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName ->
Text
-> Text -> Int -> NominalDiffTime -> UUID -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text
-> Text -> Int -> NominalDiffTime -> UUID -> m [JobRead payload]
Ops.claimNextVisibleJobsAs Text
schemaName Text
tableName Int
limit NominalDiffTime
timeout UUID
workerId
claimNextVisibleJobsBatched
:: forall payload m
. (QueueOperation m payload)
=> Int
-> Int
-> NominalDiffTime
-> m [NonEmpty (JobRead payload)]
claimNextVisibleJobsBatched :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> Int -> NominalDiffTime -> m [NonEmpty (JobRead payload)]
claimNextVisibleJobsBatched Int
batchSize Int
maxGroups NominalDiffTime
timeout =
forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [NonEmpty (JobRead payload)])
-> m [NonEmpty (JobRead payload)])
-> (Text -> Text -> m [NonEmpty (JobRead payload)])
-> m [NonEmpty (JobRead payload)]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName ->
Text
-> Text
-> Int
-> Int
-> NominalDiffTime
-> m [NonEmpty (JobRead payload)]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text
-> Text
-> Int
-> Int
-> NominalDiffTime
-> m [NonEmpty (JobRead payload)]
Ops.claimNextVisibleJobsBatched Text
schemaName Text
tableName Int
batchSize Int
maxGroups NominalDiffTime
timeout
ackJob
:: forall payload m
. (JobOperation m payload)
=> JobRead payload
-> m Int64
ackJob :: forall payload (m :: * -> *).
JobOperation m payload =>
JobRead payload -> m Int64
ackJob JobRead payload
job = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
job
Ops.ackJob schemaName tableName job
ackJobsBatch
:: forall payload m
. (JobOperation m payload)
=> [JobRead payload]
-> m [Int64]
ackJobsBatch :: forall payload (m :: * -> *).
JobOperation m payload =>
[JobRead payload] -> m [Int64]
ackJobsBatch [] = [Int64] -> m [Int64]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
ackJobsBatch jobs :: [JobRead payload]
jobs@(JobRead payload
firstJob : [JobRead payload]
_) = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
firstJob
Ops.ackJobsBatch schemaName tableName jobs
updateJobForRetry
:: forall payload m
. (JobOperation m payload)
=> NominalDiffTime
-> Text
-> JobRead payload
-> m Int64
updateJobForRetry :: forall payload (m :: * -> *).
JobOperation m payload =>
NominalDiffTime -> Text -> JobRead payload -> m Int64
updateJobForRetry NominalDiffTime
delay Text
errorMsg JobRead payload
job = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
job
Ops.updateJobForRetry schemaName tableName delay errorMsg job
nackJob
:: forall payload m
. (JobOperation m payload)
=> JobRead payload
-> m Int64
nackJob :: forall payload (m :: * -> *).
JobOperation m payload =>
JobRead payload -> m Int64
nackJob JobRead payload
job = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
job
Ops.nackJob schemaName tableName job
nackJobsBatch
:: forall payload m
. (JobOperation m payload)
=> [JobRead payload]
-> m [Int64]
nackJobsBatch :: forall payload (m :: * -> *).
JobOperation m payload =>
[JobRead payload] -> m [Int64]
nackJobsBatch [] = [Int64] -> m [Int64]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
nackJobsBatch jobs :: [JobRead payload]
jobs@(JobRead payload
firstJob : [JobRead payload]
_) = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.nackJobsBatch schemaName (Job.queueName firstJob) jobs
setVisibilityTimeout
:: forall payload m
. (JobOperation m payload)
=> NominalDiffTime
-> JobRead payload
-> m Int64
setVisibilityTimeout :: forall payload (m :: * -> *).
JobOperation m payload =>
NominalDiffTime -> JobRead payload -> m Int64
setVisibilityTimeout NominalDiffTime
timeout JobRead payload
job = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
job
Ops.setVisibilityTimeout schemaName tableName timeout job
data SetVisibilityResult
=
VisibilityExtended JobId
|
JobGone JobId
|
JobReclaimed JobId ClaimSeq ClaimSeq
|
JobCancelled JobId
|
JobSuspended JobId
|
VisibilityUnchanged JobId
deriving stock (SetVisibilityResult -> SetVisibilityResult -> Bool
(SetVisibilityResult -> SetVisibilityResult -> Bool)
-> (SetVisibilityResult -> SetVisibilityResult -> Bool)
-> Eq SetVisibilityResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetVisibilityResult -> SetVisibilityResult -> Bool
== :: SetVisibilityResult -> SetVisibilityResult -> Bool
$c/= :: SetVisibilityResult -> SetVisibilityResult -> Bool
/= :: SetVisibilityResult -> SetVisibilityResult -> Bool
Eq, Int -> SetVisibilityResult -> ShowS
[SetVisibilityResult] -> ShowS
SetVisibilityResult -> String
(Int -> SetVisibilityResult -> ShowS)
-> (SetVisibilityResult -> String)
-> ([SetVisibilityResult] -> ShowS)
-> Show SetVisibilityResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetVisibilityResult -> ShowS
showsPrec :: Int -> SetVisibilityResult -> ShowS
$cshow :: SetVisibilityResult -> String
show :: SetVisibilityResult -> String
$cshowList :: [SetVisibilityResult] -> ShowS
showList :: [SetVisibilityResult] -> ShowS
Show)
setVisibilityTimeoutBatch
:: forall payload m
. (JobOperation m payload)
=> NominalDiffTime
-> [JobRead payload]
-> m [SetVisibilityResult]
setVisibilityTimeoutBatch :: forall payload (m :: * -> *).
JobOperation m payload =>
NominalDiffTime -> [JobRead payload] -> m [SetVisibilityResult]
setVisibilityTimeoutBatch NominalDiffTime
_ [] = [SetVisibilityResult] -> m [SetVisibilityResult]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
setVisibilityTimeoutBatch NominalDiffTime
timeout jobs :: [JobRead payload]
jobs@(JobRead payload
firstJob : [JobRead payload]
_) = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
firstJob
infos <- Ops.setVisibilityTimeoutBatch schemaName tableName timeout jobs
let jobMap = [(Int64, JobRead payload)] -> Map Int64 (JobRead payload)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(JobRead payload -> Int64
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> key
primaryKey JobRead payload
job, JobRead payload
job) | JobRead payload
job <- [JobRead payload]
jobs]
toResult (Ops.VisibilityUpdateInfo Int64
jobId Bool
heartbeated Maybe Int64
mActual Bool
cancelled Bool
suspended Maybe UUID
holder) =
let mJob :: Maybe (JobRead payload)
mJob = Int64 -> Map Int64 (JobRead payload) -> Maybe (JobRead payload)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Int64
jobId Map Int64 (JobRead payload)
jobMap
expected :: Int64
expected = Int64
-> (JobRead payload -> Int64) -> Maybe (JobRead payload) -> Int64
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int64
0 JobRead payload -> Int64
forall payload q insertedAt adm.
JobRecord payload Int64 q insertedAt adm -> Int64
claimSeq Maybe (JobRead payload)
mJob
heldHere :: Bool
heldHere = Bool
-> (JobRead payload -> Bool) -> Maybe (JobRead payload) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (\JobRead payload
job -> JobRead payload -> Maybe UUID
forall payload q insertedAt adm.
JobRecord payload Int64 q insertedAt adm -> Maybe UUID
claimedBy JobRead payload
job Maybe UUID -> Maybe UUID -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe UUID
holder) Maybe (JobRead payload)
mJob
in case Maybe Int64
mActual of
Maybe Int64
Nothing -> Int64 -> SetVisibilityResult
JobGone Int64
jobId
Just Int64
actual
| Bool
cancelled, Bool
heldHere, Int64
actual Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
expected Int64 -> Int64 -> Int64
forall a. Num a => a -> a -> a
+ Int64
1 -> Int64 -> SetVisibilityResult
JobCancelled Int64
jobId
| Int64
actual Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Int64
expected -> Int64 -> Int64 -> Int64 -> SetVisibilityResult
JobReclaimed Int64
jobId Int64
expected Int64
actual
| Bool
suspended -> Int64 -> SetVisibilityResult
JobSuspended Int64
jobId
| Bool
heartbeated -> Int64 -> SetVisibilityResult
VisibilityExtended Int64
jobId
| Bool
otherwise -> Int64 -> SetVisibilityResult
VisibilityUnchanged Int64
jobId
pure $ map toResult infos
moveToDLQ
:: forall payload m
. (JobOperation m payload)
=> Text
-> JobRead payload
-> m Int64
moveToDLQ :: forall payload (m :: * -> *).
JobOperation m payload =>
Text -> JobRead payload -> m Int64
moveToDLQ Text
errorMsg JobRead payload
job = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
job
Ops.moveToDLQ Ops.TakeLocks schemaName tableName errorMsg job
listDLQJobs
:: forall payload m
. (QueueOperation m payload)
=> Int
-> Int
-> m [DLQ.DLQJob payload]
listDLQJobs :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> Int -> m [DLQJob payload]
listDLQJobs Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [DLQJob payload]) -> m [DLQJob payload])
-> (Text -> Text -> m [DLQJob payload]) -> m [DLQJob payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int -> Int -> m [DLQJob payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int -> Int -> m [DLQJob payload]
Ops.listDLQJobs Text
schemaName Text
tableName Int
limit Int
offset
listArchiveJobs
:: forall payload m
. (QueueOperation m payload)
=> Int
-> Int
-> m [Archive.ArchiveJob payload]
listArchiveJobs :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> Int -> m [ArchiveJob payload]
listArchiveJobs Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [ArchiveJob payload])
-> m [ArchiveJob payload])
-> (Text -> Text -> m [ArchiveJob payload])
-> m [ArchiveJob payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int -> Int -> m [ArchiveJob payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int -> Int -> m [ArchiveJob payload]
Ops.listArchiveJobs Text
schemaName Text
tableName Int
limit Int
offset
getArchivedJobById
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Maybe (Archive.ArchiveJob payload))
getArchivedJobById :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Maybe (ArchiveJob payload))
getArchivedJobById Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe (ArchiveJob payload)))
-> m (Maybe (ArchiveJob payload)))
-> (Text -> Text -> m (Maybe (ArchiveJob payload)))
-> m (Maybe (ArchiveJob payload))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Maybe (ArchiveJob payload))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int64 -> m (Maybe (ArchiveJob payload))
Ops.getArchivedJobById Text
schemaName Text
tableName Int64
jobId
listArchivedJobsByGroupKey
:: forall payload m
. (QueueOperation m payload)
=> Text
-> Int
-> Int
-> m [Archive.ArchiveJob payload]
listArchivedJobsByGroupKey :: forall payload (m :: * -> *).
QueueOperation m payload =>
Text -> Int -> Int -> m [ArchiveJob payload]
listArchivedJobsByGroupKey Text
groupKey Int
limit Int
offset =
forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [ArchiveJob payload])
-> m [ArchiveJob payload])
-> (Text -> Text -> m [ArchiveJob payload])
-> m [ArchiveJob payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName ->
Text -> Text -> Text -> Int -> Int -> m [ArchiveJob payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Text -> Int -> Int -> m [ArchiveJob payload]
Ops.listArchivedJobsByGroupKey Text
schemaName Text
tableName Text
groupKey Int
limit Int
offset
deleteArchiveJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
deleteArchiveJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
deleteArchiveJob Int64
archiveId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.deleteArchiveJob Text
schemaName Text
tableName Int64
archiveId
deleteArchiveJobsBatch
:: forall payload m
. (QueueOperation m payload)
=> [Int64]
-> m Int64
deleteArchiveJobsBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m Int64
deleteArchiveJobsBatch [Int64]
archiveIds = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Int64] -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Int64] -> m Int64
Ops.deleteArchiveJobsBatch Text
schemaName Text
tableName [Int64]
archiveIds
reEnqueueFromArchive
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Maybe (JobRead payload))
reEnqueueFromArchive :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Maybe (JobRead payload))
reEnqueueFromArchive Int64
archiveId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload)))
-> (Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Maybe (JobRead payload))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int64 -> m (Maybe (JobRead payload))
Ops.reEnqueueFromArchive Text
schemaName Text
tableName Int64
archiveId
retryFromDLQ
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Maybe (JobRead payload))
retryFromDLQ :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Maybe (JobRead payload))
retryFromDLQ Int64
dlqId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload)))
-> (Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Maybe (JobRead payload))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int64 -> m (Maybe (JobRead payload))
Ops.retryFromDLQ Text
schemaName Text
tableName Int64
dlqId
dlqJobExists
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Bool
dlqJobExists :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Bool
dlqJobExists Int64
dlqId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Bool) -> m Bool)
-> (Text -> Text -> m Bool) -> m Bool
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Bool
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Bool
Ops.dlqJobExists Text
schemaName Text
tableName Int64
dlqId
deleteDLQJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
deleteDLQJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
deleteDLQJob Int64
dlqId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.deleteDLQJob Text
schemaName Text
tableName Int64
dlqId
moveToDLQBatch
:: forall payload m
. (JobOperation m payload)
=> [(JobRead payload, Text)]
-> m Int64
moveToDLQBatch :: forall payload (m :: * -> *).
JobOperation m payload =>
[(JobRead payload, Text)] -> m Int64
moveToDLQBatch [] = Int64 -> m Int64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int64
0
moveToDLQBatch jobsWithErrors :: [(JobRead payload, Text)]
jobsWithErrors@((JobRead payload
firstJob, Text
_) : [(JobRead payload, Text)]
_) = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
let tableName = JobRead payload -> Text
forall payload key q insertedAt adm.
JobRecord payload key q insertedAt adm -> q
Job.queueName JobRead payload
firstJob
Ops.moveToDLQBatch schemaName tableName jobsWithErrors
deleteDLQJobsBatch
:: forall payload m
. (QueueOperation m payload)
=> [Int64]
-> m Int64
deleteDLQJobsBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m Int64
deleteDLQJobsBatch [Int64]
dlqIds = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Int64] -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Int64] -> m Int64
Ops.deleteDLQJobsBatch Text
schemaName Text
tableName [Int64]
dlqIds
listJobsFiltered
:: forall payload m
. (QueueOperation m payload)
=> [Ops.JobFilter]
-> Int
-> Int
-> m [JobRead payload]
listJobsFiltered :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobFilter] -> Int -> Int -> m [JobRead payload]
listJobsFiltered [JobFilter]
filters Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobFilter] -> Int -> Int -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> [JobFilter] -> Int -> Int -> m [JobRead payload]
Ops.listJobsFiltered Text
schemaName Text
tableName [JobFilter]
filters Int
limit Int
offset
countJobsFiltered
:: forall payload m
. (QueueOperation m payload)
=> [Ops.JobFilter]
-> m Int64
countJobsFiltered :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobFilter] -> m Int64
countJobsFiltered [JobFilter]
filters = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobFilter] -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [JobFilter] -> m Int64
Ops.countJobsFiltered Text
schemaName Text
tableName [JobFilter]
filters
listDLQFiltered
:: forall payload m
. (QueueOperation m payload)
=> [Ops.JobFilter]
-> Int
-> Int
-> m [DLQ.DLQJob payload]
listDLQFiltered :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobFilter] -> Int -> Int -> m [DLQJob payload]
listDLQFiltered [JobFilter]
filters Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [DLQJob payload]) -> m [DLQJob payload])
-> (Text -> Text -> m [DLQJob payload]) -> m [DLQJob payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobFilter] -> Int -> Int -> m [DLQJob payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> [JobFilter] -> Int -> Int -> m [DLQJob payload]
Ops.listDLQFiltered Text
schemaName Text
tableName [JobFilter]
filters Int
limit Int
offset
countDLQFiltered
:: forall payload m
. (QueueOperation m payload)
=> [Ops.JobFilter]
-> m Int64
countDLQFiltered :: forall payload (m :: * -> *).
QueueOperation m payload =>
[JobFilter] -> m Int64
countDLQFiltered [JobFilter]
filters = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [JobFilter] -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [JobFilter] -> m Int64
Ops.countDLQFiltered Text
schemaName Text
tableName [JobFilter]
filters
listJobs
:: forall payload m
. (QueueOperation m payload)
=> Int
-> Int
-> m [JobRead payload]
listJobs :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int -> Int -> m [JobRead payload]
listJobs Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int -> Int -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int -> Int -> m [JobRead payload]
Ops.listJobs Text
schemaName Text
tableName Int
limit Int
offset
getJobById
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Maybe (JobRead payload))
getJobById :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Maybe (JobRead payload))
getJobById Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload)))
-> (Text -> Text -> m (Maybe (JobRead payload)))
-> m (Maybe (JobRead payload))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Maybe (JobRead payload))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int64 -> m (Maybe (JobRead payload))
Ops.getJobById Text
schemaName Text
tableName Int64
jobId
jobExists
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Bool
jobExists :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Bool
jobExists Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Bool) -> m Bool)
-> (Text -> Text -> m Bool) -> m Bool
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Bool
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Bool
Ops.jobExists Text
schemaName Text
tableName Int64
jobId
getJobsByGroup
:: forall payload m
. (QueueOperation m payload)
=> Text
-> Int
-> Int
-> m [JobRead payload]
getJobsByGroup :: forall payload (m :: * -> *).
QueueOperation m payload =>
Text -> Int -> Int -> m [JobRead payload]
getJobsByGroup Text
groupKey Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Text -> Int -> Int -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Text -> Int -> Int -> m [JobRead payload]
Ops.getJobsByGroup Text
schemaName Text
tableName Text
groupKey Int
limit Int
offset
getJobsByParent
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> Int
-> Int
-> m [JobRead payload]
getJobsByParent :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> Int -> Int -> m [JobRead payload]
getJobsByParent Int64
pid Int
limit Int
offset = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m [JobRead payload]) -> m [JobRead payload])
-> (Text -> Text -> m [JobRead payload]) -> m [JobRead payload]
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> Int -> Int -> m [JobRead payload]
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text -> Text -> Int64 -> Int -> Int -> m [JobRead payload]
Ops.getJobsByParent Text
schemaName Text
tableName Int64
pid Int
limit Int
offset
cancelJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
cancelJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
cancelJob Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.cancelJob Text
schemaName Text
tableName Int64
jobId
forceCancelJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
forceCancelJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
forceCancelJob Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.forceCancelJob Text
schemaName Text
tableName Int64
jobId
cancelJobsBatch
:: forall payload m
. (QueueOperation m payload)
=> [Int64]
-> m Int64
cancelJobsBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m Int64
cancelJobsBatch [Int64]
jobIds = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Int64] -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Int64] -> m Int64
Ops.cancelJobsBatch Text
schemaName Text
tableName [Int64]
jobIds
promoteJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
promoteJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
promoteJob Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.promoteJob Text
schemaName Text
tableName Int64
jobId
getQueueStats
:: forall payload m
. (QueueOperation m payload)
=> m Ops.QueueStats
getQueueStats :: forall payload (m :: * -> *).
QueueOperation m payload =>
m QueueStats
getQueueStats = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m QueueStats) -> m QueueStats)
-> (Text -> Text -> m QueueStats) -> m QueueStats
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Text] -> m QueueStats
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Text] -> m QueueStats
Ops.getQueueStats Text
schemaName Text
tableName (forall payload. HasKind payload => [Text]
kindsFor @payload)
countJobs
:: forall payload m
. (QueueOperation m payload)
=> m Int64
countJobs :: forall payload (m :: * -> *). QueueOperation m payload => m Int64
countJobs = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> m Int64
forall (m :: * -> *). MonadArbiter m => Text -> Text -> m Int64
Ops.countJobs Text
schemaName Text
tableName
countJobsByGroup
:: forall payload m
. (QueueOperation m payload)
=> Text
-> m Int64
countJobsByGroup :: forall payload (m :: * -> *).
QueueOperation m payload =>
Text -> m Int64
countJobsByGroup Text
groupKey = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Text -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Text -> m Int64
Ops.countJobsByGroup Text
schemaName Text
tableName Text
groupKey
countJobsByParent
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
countJobsByParent :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
countJobsByParent Int64
pid = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.countJobsByParent Text
schemaName Text
tableName Int64
pid
countDLQJobs
:: forall payload m
. (QueueOperation m payload)
=> m Int64
countDLQJobs :: forall payload (m :: * -> *). QueueOperation m payload => m Int64
countDLQJobs = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> m Int64
forall (m :: * -> *). MonadArbiter m => Text -> Text -> m Int64
Ops.countDLQJobs Text
schemaName Text
tableName
countChildrenBatch
:: forall payload m
. (QueueOperation m payload)
=> [Int64]
-> m (Map Int64 (Int64, Int64))
countChildrenBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m (Map Int64 (Int64, Int64))
countChildrenBatch [Int64]
ids = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Map Int64 (Int64, Int64)))
-> m (Map Int64 (Int64, Int64)))
-> (Text -> Text -> m (Map Int64 (Int64, Int64)))
-> m (Map Int64 (Int64, Int64))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Int64] -> m (Map Int64 (Int64, Int64))
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Int64] -> m (Map Int64 (Int64, Int64))
Ops.countChildrenBatch Text
schemaName Text
tableName [Int64]
ids
countDLQChildren
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
countDLQChildren :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
countDLQChildren Int64
parentJobId = do
counts <- forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m (Map Int64 Int64)
countDLQChildrenBatch @payload [Int64
parentJobId]
pure $ fromMaybe 0 (Map.lookup parentJobId counts)
countDLQChildrenBatch
:: forall payload m
. (QueueOperation m payload)
=> [Int64]
-> m (Map Int64 Int64)
countDLQChildrenBatch :: forall payload (m :: * -> *).
QueueOperation m payload =>
[Int64] -> m (Map Int64 Int64)
countDLQChildrenBatch [Int64]
ids = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Map Int64 Int64)) -> m (Map Int64 Int64))
-> (Text -> Text -> m (Map Int64 Int64)) -> m (Map Int64 Int64)
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> [Int64] -> m (Map Int64 Int64)
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> [Int64] -> m (Map Int64 Int64)
Ops.countDLQChildrenBatch Text
schemaName Text
tableName [Int64]
ids
pauseChildren
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
pauseChildren :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
pauseChildren Int64
parentJobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.pauseChildren Text
schemaName Text
tableName Int64
parentJobId
resumeChildren
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
resumeChildren :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
resumeChildren Int64
parentJobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.resumeChildren Text
schemaName Text
tableName Int64
parentJobId
cancelJobCascade
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
cancelJobCascade :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
cancelJobCascade Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.cancelJobCascade Text
schemaName Text
tableName Int64
jobId
suspendJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
suspendJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
suspendJob Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.suspendJob Text
schemaName Text
tableName Int64
jobId
resumeJob
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m Int64
resumeJob :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m Int64
resumeJob Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m Int64
Ops.resumeJob Text
schemaName Text
tableName Int64
jobId
insertResult
:: forall payload m
. (EncodeJobResult (ResultOf m payload), QueueOperation m payload)
=> Int64
-> Int64
-> ResultOf m payload
-> m Int64
insertResult :: forall payload (m :: * -> *).
(EncodeJobResult (ResultOf m payload), QueueOperation m payload) =>
Int64 -> Int64 -> ResultOf m payload -> m Int64
insertResult Int64
parentJobId Int64
childId ResultOf m payload
result =
m Int64 -> (Value -> m Int64) -> Maybe Value -> m Int64
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Int64 -> m Int64
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int64
0) (forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> Int64 -> Value -> m Int64
insertResultUnsafe @payload Int64
parentJobId Int64
childId) (SpecResult (MatchIn payload '[] (RegistryOf m)) -> Maybe Value
forall a. EncodeJobResult a => a -> Maybe Value
encodeJobResult ResultOf m payload
SpecResult (MatchIn payload '[] (RegistryOf m))
result)
insertResultUnsafe
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> Int64
-> Value
-> m Int64
insertResultUnsafe :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> Int64 -> Value -> m Int64
insertResultUnsafe Int64
parentJobId Int64
childId Value
result =
forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName ->
Text -> Text -> Int64 -> Int64 -> Value -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> Int64 -> Value -> m Int64
Ops.insertResult Text
schemaName Text
tableName Int64
parentJobId Int64
childId Value
result
getResultsByParent
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Map Int64 Value)
getResultsByParent :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Map Int64 Value)
getResultsByParent Int64
parentJobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Map Int64 Value)) -> m (Map Int64 Value))
-> (Text -> Text -> m (Map Int64 Value)) -> m (Map Int64 Value)
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Map Int64 Value)
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m (Map Int64 Value)
Ops.getResultsByParent Text
schemaName Text
tableName Int64
parentJobId
getDLQChildErrorsByParent
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Map Int64 Text)
getDLQChildErrorsByParent :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Map Int64 Text)
getDLQChildErrorsByParent Int64
parentJobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Map Int64 Text)) -> m (Map Int64 Text))
-> (Text -> Text -> m (Map Int64 Text)) -> m (Map Int64 Text)
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Map Int64 Text)
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m (Map Int64 Text)
Ops.getDLQChildErrorsByParent Text
schemaName Text
tableName Int64
parentJobId
readChildResultsRaw
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)
readChildResultsRaw :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64
-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)
readChildResultsRaw Int64
parentJobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text
-> Text
-> m (Map Int64 Value, Map Int64 Text, Maybe Value,
Map Int64 Text))
-> m (Map Int64 Value, Map Int64 Text, Maybe Value,
Map Int64 Text))
-> (Text
-> Text
-> m (Map Int64 Value, Map Int64 Text, Maybe Value,
Map Int64 Text))
-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text
-> Text
-> Int64
-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)
forall (m :: * -> *).
MonadArbiter m =>
Text
-> Text
-> Int64
-> m (Map Int64 Value, Map Int64 Text, Maybe Value, Map Int64 Text)
Ops.readChildResultsRaw Text
schemaName Text
tableName Int64
parentJobId
persistParentState
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> Value
-> m Int64
persistParentState :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> Value -> m Int64
persistParentState Int64
jobId Value
state = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m Int64) -> m Int64)
-> (Text -> Text -> m Int64) -> m Int64
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> Value -> m Int64
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> Value -> m Int64
Ops.persistParentState Text
schemaName Text
tableName Int64
jobId Value
state
getParentStateSnapshot
:: forall payload m
. (QueueOperation m payload)
=> Int64
-> m (Maybe Value)
getParentStateSnapshot :: forall payload (m :: * -> *).
QueueOperation m payload =>
Int64 -> m (Maybe Value)
getParentStateSnapshot Int64
jobId = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Maybe Value)) -> m (Maybe Value))
-> (Text -> Text -> m (Maybe Value)) -> m (Maybe Value)
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text -> Text -> Int64 -> m (Maybe Value)
forall (m :: * -> *).
MonadArbiter m =>
Text -> Text -> Int64 -> m (Maybe Value)
Ops.getParentStateSnapshot Text
schemaName Text
tableName Int64
jobId
refreshAllGroupsFully
:: forall m
. (MonadArbiter m, RegistryTables (RegistryOf m))
=> m (Int64, [Text])
refreshAllGroupsFully :: forall (m :: * -> *).
(MonadArbiter m, RegistryTables (RegistryOf m)) =>
m (Int64, [Text])
refreshAllGroupsFully = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.refreshAllGroupsFully schemaName (registryTableNames (Proxy @(RegistryOf m)))
listCronSchedules
:: forall m
. (MonadArbiter m)
=> Maybe Text
-> m [CronScheduleRow]
listCronSchedules :: forall (m :: * -> *).
MonadArbiter m =>
Maybe Text -> m [CronScheduleRow]
listCronSchedules Maybe Text
mQueue = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.listCronSchedules schemaName mQueue
getCronScheduleByName
:: forall m
. (MonadArbiter m)
=> Text
-> m (Maybe CronScheduleRow)
getCronScheduleByName :: forall (m :: * -> *).
MonadArbiter m =>
Text -> m (Maybe CronScheduleRow)
getCronScheduleByName Text
scheduleName = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.getCronScheduleByName schemaName scheduleName
updateCronScheduleUnchecked
:: forall m
. (MonadArbiter m)
=> Text
-> CronScheduleUpdate
-> m Int64
updateCronScheduleUnchecked :: forall (m :: * -> *).
MonadArbiter m =>
Text -> CronScheduleUpdate -> m Int64
updateCronScheduleUnchecked Text
scheduleName CronScheduleUpdate
upd = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.updateCronSchedule schemaName scheduleName upd
runGated
:: forall m a
. (MonadArbiter m)
=> Text
-> NominalDiffTime
-> m a
-> m (Maybe a)
runGated :: forall (m :: * -> *) a.
MonadArbiter m =>
Text -> NominalDiffTime -> m a -> m (Maybe a)
runGated Text
task NominalDiffTime
interval m a
work = do
schemaName <- m Text
forall (m :: * -> *). MonadArbiter m => m Text
getSchema
Ops.runGated schemaName task interval work
insertJobTree
:: forall payload m
. (QueueOperation m payload)
=> JT.JobTree payload
-> m (Either Text (NonEmpty (JobRead payload)))
insertJobTree :: forall payload (m :: * -> *).
QueueOperation m payload =>
JobTree payload -> m (Either Text (NonEmpty (JobRead payload)))
insertJobTree JobTree payload
tree = forall payload (m :: * -> *) a.
(KnownSymbol (TableForPayload payload (RegistryOf m)),
MonadArbiter m) =>
(Text -> Text -> m a) -> m a
onQueue @payload ((Text -> Text -> m (Either Text (NonEmpty (JobRead payload))))
-> m (Either Text (NonEmpty (JobRead payload))))
-> (Text -> Text -> m (Either Text (NonEmpty (JobRead payload))))
-> m (Either Text (NonEmpty (JobRead payload)))
forall a b. (a -> b) -> a -> b
$ \Text
schemaName Text
tableName -> Text
-> Text
-> JobTree payload
-> m (Either Text (NonEmpty (JobRead payload)))
forall (m :: * -> *) payload.
(JobPayload payload, MonadArbiter m) =>
Text
-> Text
-> JobTree payload
-> m (Either Text (NonEmpty (JobRead payload)))
JT.insertJobTree Text
schemaName Text
tableName JobTree payload
tree