2020-11-25 13:56:44 +03:00
|
|
|
-- | This module has type class and types which implements the Metadata Storage Abstraction
|
|
|
|
module Hasura.Metadata.Class
|
2020-12-14 07:30:19 +03:00
|
|
|
( SchemaSyncEventProcessResult (..),
|
2020-11-25 13:56:44 +03:00
|
|
|
MonadMetadataStorage (..),
|
2020-12-28 15:56:00 +03:00
|
|
|
MonadMetadataStorageQueryAPI (..),
|
2020-11-25 13:56:44 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
import Control.Monad.Trans.Managed
|
2020-12-14 07:30:19 +03:00
|
|
|
import Data.Aeson
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
import Database.PG.Query qualified as PG
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Base.Error
|
2020-11-25 13:56:44 +03:00
|
|
|
import Hasura.Eventing.ScheduledTrigger.Types
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Action
|
|
|
|
import Hasura.RQL.Types.EventTrigger
|
|
|
|
import Hasura.RQL.Types.Eventing
|
|
|
|
import Hasura.RQL.Types.Metadata
|
|
|
|
import Hasura.RQL.Types.ScheduledTrigger
|
|
|
|
import Hasura.RQL.Types.SchemaCache
|
|
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
2020-12-14 07:30:19 +03:00
|
|
|
import Hasura.Server.Types
|
|
|
|
import Hasura.Session
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
import Network.HTTP.Types qualified as HTTP
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2020-12-14 07:30:19 +03:00
|
|
|
data SchemaSyncEventProcessResult = SchemaSyncEventProcessResult
|
|
|
|
{ _sseprShouldReload :: !Bool,
|
|
|
|
_sseprCacheInvalidations :: !CacheInvalidations
|
|
|
|
}
|
|
|
|
|
2020-11-25 13:56:44 +03:00
|
|
|
{- Note [Todo: Common interface for eventing sub-system]
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Postgres tables' event triggers and scheduled event triggers are similar in the
|
|
|
|
core logic. But currently, their implementation is completely isolated and do not
|
|
|
|
share a common schema in Postgres. We're having a plan to simplify them via a
|
|
|
|
common 'event storage and retrieval' interface (maybe via a Postgres extension?).
|
|
|
|
This will potentially reduce number of interactions made to database and schema foot print.
|
|
|
|
|
|
|
|
TODO: Reference to open issue or rfc?
|
|
|
|
-}
|
|
|
|
|
|
|
|
-- | Metadata storage abstraction via a type class.
|
|
|
|
--
|
|
|
|
-- This type class enables storing and managing Hasura metadata in an isolated
|
|
|
|
-- database which will not interfere with user's database where tables/functions
|
|
|
|
-- are defined. Hence, it'll enable support for databases of multiple backends
|
|
|
|
-- like MySQL, MSSQL etc.
|
|
|
|
--
|
2023-02-03 04:03:23 +03:00
|
|
|
-- Error-handling is handled explicitly, with every function returning an
|
|
|
|
-- `Either QErr`. This is inelegant, but is required: we want the caller to
|
|
|
|
-- explictly deal with errors, rather than letting them surface to a "lower"
|
|
|
|
-- monad, because we want to implement this as a "Service", on the base monad,
|
|
|
|
-- so that different implementations of the engine can choose how to implement
|
|
|
|
-- it; and those base monads do not include error handling, all error handling
|
|
|
|
-- must be done at the endpoint level. As a result, we choose to make the errors
|
|
|
|
-- explicit in the return type rather than making assumptions about the stack.
|
|
|
|
--
|
2020-11-25 13:56:44 +03:00
|
|
|
-- This class has functions broadly related to:
|
|
|
|
--
|
2020-12-14 07:30:19 +03:00
|
|
|
-- 1. Metadata Management
|
2020-11-25 13:56:44 +03:00
|
|
|
-- ----------------------
|
|
|
|
-- Basic metadata management functions such as retrieving metadata from storage
|
|
|
|
-- database and replacing the given metadata.
|
2020-12-14 07:30:19 +03:00
|
|
|
-- TODO: Console specific operations
|
2020-11-25 13:56:44 +03:00
|
|
|
--
|
|
|
|
-- 2. Scheduled Triggers
|
|
|
|
-- ---------------------
|
|
|
|
-- Eventing sub-system for scheduled triggers is implemented via metadata storage.
|
|
|
|
-- For more details, refer description in 'Hasura.Eventing.ScheduledTrigger' module.
|
|
|
|
--
|
|
|
|
-- TODO: Functions need to be added to the type class
|
|
|
|
-- - Retrieving invocation logs from storage (console requirement)
|
|
|
|
-- - Deleting an scheduled event
|
|
|
|
-- - Creating an one-off scheduled event
|
|
|
|
--
|
2020-12-14 07:30:19 +03:00
|
|
|
-- 3. Async Actions
|
2020-11-25 13:56:44 +03:00
|
|
|
-- ----------------
|
|
|
|
-- Operations to implement async actions sub-system. This includes recording an
|
|
|
|
-- async action event and retreiving the details of action delivery to the webhook.
|
|
|
|
-- For more details see Note [Async action architecture] in 'Hasura.GraphQL.Execute.Action' module.
|
|
|
|
--
|
|
|
|
-- It is believed that all the above three are implemented in a single storage
|
|
|
|
-- system (ex: a Postgres database). We can split the functions into appropriate and
|
|
|
|
-- specific type classes in future iterations if required.
|
2023-02-03 04:03:23 +03:00
|
|
|
class Monad m => MonadMetadataStorage m where
|
2020-12-14 07:30:19 +03:00
|
|
|
-- Metadata
|
2023-02-03 04:03:23 +03:00
|
|
|
fetchMetadataResourceVersion :: m (Either QErr MetadataResourceVersion)
|
2023-03-28 16:26:08 +03:00
|
|
|
fetchMetadata :: m (Either QErr MetadataWithResourceVersion)
|
2023-02-03 04:03:23 +03:00
|
|
|
fetchMetadataNotifications :: MetadataResourceVersion -> InstanceId -> m (Either QErr [(MetadataResourceVersion, CacheInvalidations)])
|
|
|
|
setMetadata :: MetadataResourceVersion -> Metadata -> m (Either QErr MetadataResourceVersion)
|
|
|
|
notifySchemaCacheSync :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> m (Either QErr ())
|
|
|
|
getCatalogState :: m (Either QErr CatalogState)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
-- the `setCatalogState` function is used by the console and CLI to store its state
|
|
|
|
-- it is disabled when maintenance mode is on
|
2023-02-03 04:03:23 +03:00
|
|
|
setCatalogState :: CatalogStateType -> Value -> m (Either QErr ())
|
2020-12-14 07:30:19 +03:00
|
|
|
|
2021-01-07 12:04:22 +03:00
|
|
|
-- get the @db_uuid@ that we store in the database.
|
2023-02-03 04:03:23 +03:00
|
|
|
getMetadataDbUid :: m (Either QErr MetadataDbId)
|
|
|
|
checkMetadataStorageHealth :: m (Either QErr ())
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2020-11-25 13:56:44 +03:00
|
|
|
-- Scheduled triggers
|
|
|
|
-- TODO:-
|
|
|
|
-- Ideally we would've liked to avoid having functions that are specific to
|
|
|
|
-- scheduled/cron triggers and instead have functions that provide a generic
|
|
|
|
-- 'event storage and retrieval' interface but we'll have to change a lot of
|
|
|
|
-- existing code for scheduled and cron triggers. We can get to this after the
|
|
|
|
-- multi-source work is done. See Note [Todo: Common interface for eventing sub-system]
|
2023-02-03 04:03:23 +03:00
|
|
|
getDeprivedCronTriggerStats :: [TriggerName] -> m (Either QErr [CronTriggerStats])
|
|
|
|
getScheduledEventsForDelivery :: m (Either QErr ([CronEvent], [OneOffScheduledEvent]))
|
|
|
|
insertCronEvents :: [CronEventSeed] -> m (Either QErr ())
|
|
|
|
insertOneOffScheduledEvent :: OneOffEvent -> m (Either QErr EventId)
|
|
|
|
insertScheduledEventInvocation :: Invocation 'ScheduledType -> ScheduledEventType -> m (Either QErr ())
|
|
|
|
setScheduledEventOp :: ScheduledEventId -> ScheduledEventOp -> ScheduledEventType -> m (Either QErr ())
|
|
|
|
unlockScheduledEvents :: ScheduledEventType -> [ScheduledEventId] -> m (Either QErr Int)
|
|
|
|
unlockAllLockedScheduledEvents :: m (Either QErr ())
|
|
|
|
clearFutureCronEvents :: ClearCronEvents -> m (Either QErr ())
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
-- Console API requirements
|
2023-02-03 04:03:23 +03:00
|
|
|
getOneOffScheduledEvents :: ScheduledEventPagination -> [ScheduledEventStatus] -> RowsCountOption -> m (Either QErr (WithOptionalTotalCount [OneOffScheduledEvent]))
|
|
|
|
getCronEvents :: TriggerName -> ScheduledEventPagination -> [ScheduledEventStatus] -> RowsCountOption -> m (Either QErr (WithOptionalTotalCount [CronEvent]))
|
|
|
|
getScheduledEventInvocations :: GetScheduledEventInvocations -> m (Either QErr (WithOptionalTotalCount [ScheduledEventInvocation]))
|
|
|
|
deleteScheduledEvent :: ScheduledEventId -> ScheduledEventType -> m (Either QErr ())
|
2020-12-14 07:30:19 +03:00
|
|
|
|
|
|
|
-- Async actions
|
|
|
|
insertAction ::
|
|
|
|
ActionName ->
|
|
|
|
SessionVariables ->
|
|
|
|
[HTTP.Header] ->
|
|
|
|
Value ->
|
2023-02-03 04:03:23 +03:00
|
|
|
m (Either QErr ActionId)
|
|
|
|
fetchUndeliveredActionEvents :: m (Either QErr [ActionLogItem])
|
|
|
|
setActionStatus :: ActionId -> AsyncActionStatus -> m (Either QErr ())
|
|
|
|
fetchActionResponse :: ActionId -> m (Either QErr ActionLogResponse)
|
|
|
|
clearActionData :: ActionName -> m (Either QErr ())
|
|
|
|
setProcessingActionLogsToPending :: LockedActionIdArray -> m (Either QErr ())
|
2020-11-25 13:56:44 +03:00
|
|
|
|
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (ReaderT r m) where
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
2021-02-18 19:46:14 +03:00
|
|
|
fetchMetadata = lift fetchMetadata
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
2021-02-19 05:39:30 +03:00
|
|
|
setMetadata r = lift . setMetadata r
|
2021-04-06 06:25:02 +03:00
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
2021-02-18 19:46:14 +03:00
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-02-18 19:46:14 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
2021-02-18 19:46:14 +03:00
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-02-18 19:46:14 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-02-18 19:46:14 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
2021-05-14 12:38:37 +03:00
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-12-14 07:30:19 +03:00
|
|
|
|
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (StateT s m) where
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
2021-02-18 19:46:14 +03:00
|
|
|
fetchMetadata = lift fetchMetadata
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
2021-02-19 05:39:30 +03:00
|
|
|
setMetadata r = lift . setMetadata r
|
2021-04-06 06:25:02 +03:00
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
2021-02-18 19:46:14 +03:00
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-02-18 19:46:14 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
2021-02-18 19:46:14 +03:00
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-02-18 19:46:14 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-02-18 19:46:14 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
2021-05-14 12:38:37 +03:00
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-11-25 13:56:44 +03:00
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (ExceptT e m) where
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
2021-02-18 19:46:14 +03:00
|
|
|
fetchMetadata = lift fetchMetadata
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
2021-02-19 05:39:30 +03:00
|
|
|
setMetadata r = lift . setMetadata r
|
2021-04-06 06:25:02 +03:00
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
2021-02-18 19:46:14 +03:00
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-02-18 19:46:14 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
2021-02-18 19:46:14 +03:00
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-02-18 19:46:14 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-02-18 19:46:14 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
2021-05-14 12:38:37 +03:00
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-12-14 07:30:19 +03:00
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (Tracing.TraceT m) where
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
2021-02-18 19:46:14 +03:00
|
|
|
fetchMetadata = lift fetchMetadata
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
2021-02-19 05:39:30 +03:00
|
|
|
setMetadata r = lift . setMetadata r
|
2021-04-06 06:25:02 +03:00
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
2021-02-18 19:46:14 +03:00
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-02-18 19:46:14 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
2021-02-18 19:46:14 +03:00
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-02-18 19:46:14 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-02-18 19:46:14 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
2021-05-14 12:38:37 +03:00
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-12-14 07:30:19 +03:00
|
|
|
|
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (MetadataT m) where
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
2021-02-18 19:46:14 +03:00
|
|
|
fetchMetadata = lift fetchMetadata
|
2021-04-06 06:25:02 +03:00
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
2021-02-19 05:39:30 +03:00
|
|
|
setMetadata r = lift . setMetadata r
|
2021-04-06 06:25:02 +03:00
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
2021-02-18 19:46:14 +03:00
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-02-18 19:46:14 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-05-26 19:19:26 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-05-26 19:19:26 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (PG.TxET e m) where
|
2021-05-26 19:19:26 +03:00
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
|
|
|
fetchMetadata = lift fetchMetadata
|
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
|
|
|
setMetadata r = lift . setMetadata r
|
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-06-15 11:02:29 +03:00
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
2021-05-26 19:19:26 +03:00
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
2021-02-18 19:46:14 +03:00
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
2021-09-13 21:00:53 +03:00
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
2021-02-18 19:46:14 +03:00
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
2022-09-15 22:10:53 +03:00
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
2022-11-03 13:21:56 +03:00
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
2021-02-18 19:46:14 +03:00
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-02-18 19:46:14 +03:00
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
2021-05-14 12:38:37 +03:00
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-11-25 13:56:44 +03:00
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance (MonadMetadataStorage m) => MonadMetadataStorage (ManagedT m) where
|
|
|
|
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
|
|
|
fetchMetadata = lift fetchMetadata
|
|
|
|
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
|
|
|
setMetadata r = lift . setMetadata r
|
|
|
|
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
|
|
|
getCatalogState = lift getCatalogState
|
|
|
|
setCatalogState a b = lift $ setCatalogState a b
|
|
|
|
|
|
|
|
getMetadataDbUid = lift getMetadataDbUid
|
|
|
|
checkMetadataStorageHealth = lift checkMetadataStorageHealth
|
|
|
|
|
|
|
|
getDeprivedCronTriggerStats = lift . getDeprivedCronTriggerStats
|
|
|
|
getScheduledEventsForDelivery = lift getScheduledEventsForDelivery
|
|
|
|
insertCronEvents = lift . insertCronEvents
|
|
|
|
insertOneOffScheduledEvent = lift . insertOneOffScheduledEvent
|
|
|
|
insertScheduledEventInvocation a b = lift $ insertScheduledEventInvocation a b
|
|
|
|
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
|
|
|
|
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
|
|
|
|
unlockAllLockedScheduledEvents = lift $ unlockAllLockedScheduledEvents
|
|
|
|
clearFutureCronEvents = lift . clearFutureCronEvents
|
|
|
|
getOneOffScheduledEvents a b c = lift $ getOneOffScheduledEvents a b c
|
|
|
|
getCronEvents a b c d = lift $ getCronEvents a b c d
|
|
|
|
getScheduledEventInvocations a = lift $ getScheduledEventInvocations a
|
|
|
|
deleteScheduledEvent a b = lift $ deleteScheduledEvent a b
|
|
|
|
|
|
|
|
insertAction a b c d = lift $ insertAction a b c d
|
|
|
|
fetchUndeliveredActionEvents = lift fetchUndeliveredActionEvents
|
|
|
|
setActionStatus a b = lift $ setActionStatus a b
|
|
|
|
fetchActionResponse = lift . fetchActionResponse
|
|
|
|
clearActionData = lift . clearActionData
|
|
|
|
setProcessingActionLogsToPending = lift . setProcessingActionLogsToPending
|
2020-12-14 07:30:19 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
-- | Operations from @'MonadMetadataStorage' used in '/v1/query' and '/v1/metadata' APIs
|
|
|
|
class (MonadMetadataStorage m) => MonadMetadataStorageQueryAPI m where
|
2021-09-13 21:00:53 +03:00
|
|
|
-- | Record a one-off event
|
2023-02-03 04:03:23 +03:00
|
|
|
createOneOffScheduledEvent :: OneOffEvent -> m (Either QErr EventId)
|
2021-09-13 21:00:53 +03:00
|
|
|
createOneOffScheduledEvent = insertOneOffScheduledEvent
|
|
|
|
|
|
|
|
-- | Record a cron event
|
2023-02-03 04:03:23 +03:00
|
|
|
createCronEvents :: [CronEventSeed] -> m (Either QErr ())
|
2021-09-13 21:00:53 +03:00
|
|
|
createCronEvents = insertCronEvents
|
2020-12-14 07:30:19 +03:00
|
|
|
|
|
|
|
-- | Clear cron events
|
2023-02-03 04:03:23 +03:00
|
|
|
dropFutureCronEvents :: ClearCronEvents -> m (Either QErr ())
|
2020-12-14 07:30:19 +03:00
|
|
|
dropFutureCronEvents = clearFutureCronEvents
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
-- | Delete async action logs
|
2023-02-03 04:03:23 +03:00
|
|
|
deleteActionData :: ActionName -> m (Either QErr ())
|
2020-12-28 15:56:00 +03:00
|
|
|
deleteActionData = clearActionData
|
|
|
|
|
2021-01-07 12:04:22 +03:00
|
|
|
-- | Fetch cron/oneoff scheduled event invocations
|
2022-11-03 13:21:56 +03:00
|
|
|
fetchScheduledEventInvocations ::
|
|
|
|
GetScheduledEventInvocations ->
|
2023-02-03 04:03:23 +03:00
|
|
|
m (Either QErr (WithOptionalTotalCount [ScheduledEventInvocation]))
|
2022-11-03 13:21:56 +03:00
|
|
|
fetchScheduledEventInvocations = getScheduledEventInvocations
|
2021-01-07 12:04:22 +03:00
|
|
|
|
|
|
|
-- | Fetch cron/oneoff scheduled events
|
2023-02-03 04:03:23 +03:00
|
|
|
fetchScheduledEvents :: GetScheduledEvents -> m (Either QErr Value)
|
2021-01-07 12:04:22 +03:00
|
|
|
fetchScheduledEvents GetScheduledEvents {..} = do
|
2022-09-15 22:10:53 +03:00
|
|
|
let totalCountToJSON WithOptionalTotalCount {..} =
|
|
|
|
object $
|
|
|
|
("events" .= _wtcData) : (maybe mempty (\count -> ["count" .= count]) _wtcCount)
|
2021-01-07 12:04:22 +03:00
|
|
|
case _gseScheduledEvent of
|
2023-02-03 04:03:23 +03:00
|
|
|
SEOneOff -> (fmap . fmap) totalCountToJSON $ getOneOffScheduledEvents _gsePagination _gseStatus _gseGetRowsCount
|
|
|
|
SECron name -> (fmap . fmap) totalCountToJSON $ getCronEvents name _gsePagination _gseStatus _gseGetRowsCount
|
2021-01-07 12:04:22 +03:00
|
|
|
|
|
|
|
-- | Drop a cron/oneoff scheduled event
|
2023-02-03 04:03:23 +03:00
|
|
|
dropEvent :: ScheduledEventId -> ScheduledEventType -> m (Either QErr ())
|
2021-01-07 12:04:22 +03:00
|
|
|
dropEvent = deleteScheduledEvent
|
|
|
|
|
|
|
|
-- | Retrieve the state from metadata storage catalog
|
2023-02-03 04:03:23 +03:00
|
|
|
fetchCatalogState :: m (Either QErr CatalogState)
|
2021-01-07 12:04:22 +03:00
|
|
|
fetchCatalogState = getCatalogState
|
|
|
|
|
|
|
|
-- | Update the state from metadata storage catalog
|
2023-02-03 04:03:23 +03:00
|
|
|
updateCatalogState :: CatalogStateType -> Value -> m (Either QErr ())
|
2021-01-07 12:04:22 +03:00
|
|
|
updateCatalogState = setCatalogState
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (ReaderT r m)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (StateT s m)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (ExceptT s m)
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (Tracing.TraceT m)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (MetadataT m)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Import `pg-client-hs` as `PG`
Result of executing the following commands:
```shell
# replace "as Q" imports with "as PG" (in retrospect this didn't need a regex)
git grep -lE 'as Q($|[^a-zA-Z])' -- '*.hs' | xargs sed -i -E 's/as Q($|[^a-zA-Z])/as PG\1/'
# replace " Q." with " PG."
git grep -lE ' Q\.' -- '*.hs' | xargs sed -i 's/ Q\./ PG./g'
# replace "(Q." with "(PG."
git grep -lE '\(Q\.' -- '*.hs' | xargs sed -i 's/(Q\./(PG./g'
# ditto, but for [, |, { and !
git grep -lE '\[Q\.' -- '*.hs' | xargs sed -i 's/\[Q\./\[PG./g'
git grep -l '|Q\.' -- '*.hs' | xargs sed -i 's/|Q\./|PG./g'
git grep -l '{Q\.' -- '*.hs' | xargs sed -i 's/{Q\./{PG./g'
git grep -l '!Q\.' -- '*.hs' | xargs sed -i 's/!Q\./!PG./g'
```
(Doing the `grep -l` before the `sed`, instead of `sed` on the entire codebase, reduces the number of `mtime` updates, and so reduces how many times a file gets recompiled while checking intermediate results.)
Finally, I manually removed a broken and unused `Arbitrary` instance in `Hasura.RQL.Network`. (It used an `import Test.QuickCheck.Arbitrary as Q` statement, which was erroneously caught by the first find-replace command.)
After this PR, `Q` is no longer used as an import qualifier. That was not the goal of this PR, but perhaps it's a useful fact for future efforts.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5933
GitOrigin-RevId: 8c84c59d57789111d40f5d3322c5a885dcfbf40e
2022-09-20 22:54:43 +03:00
|
|
|
instance (MonadMetadataStorageQueryAPI m) => MonadMetadataStorageQueryAPI (PG.TxET QErr m)
|