Skip to content

Commit 2b25700

Browse files
committed
improve comment description
1 parent 664c43b commit 2b25700

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

server/src-lib/Hasura/Eventing/ScheduledTrigger.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ other. They can be split into different threads for a better performance.
3232
3333
== Implementation
3434
35+
The scheduled triggers eventing is being implemented in the metadata storage.
36+
All functions that make interaction to storage system are abstracted in
37+
the @'MonadMetadataStorage' class.
38+
3539
During the startup, two threads are started:
3640
3741
1. Generator: Fetches the list of scheduled triggers from cache and generates

server/src-lib/Hasura/Metadata/Class.hs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,13 @@ import Hasura.RQL.Types
1616

1717
import qualified Hasura.Tracing as Tracing
1818

19-
-- | Metadata storage transformer that enables raising @'QErr' exceptions.
20-
newtype MetadataStorageT m a
21-
= MetadataStorageT {unMetadataStorageT :: ExceptT QErr m a}
22-
deriving ( Functor, Applicative, Monad
23-
, MonadError QErr
24-
, MonadTrans
25-
, MonadIO
26-
, MFunctor
27-
, Tracing.HasReporter
28-
)
29-
30-
runMetadataStorageT
31-
:: MetadataStorageT m a -> m (Either QErr a)
32-
runMetadataStorageT =
33-
runExceptT . unMetadataStorageT
34-
3519
{- Note [Todo: Common interface for eventing sub-system]
3620
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3721
Postgres tables' event triggers and scheduled event triggers are similar in the
38-
core logic. But currently, their implementation is completely isolated and do not share
39-
a common schema in Postgres. We're having a plan to simplify them via a common interface
40-
(maybe via a Postgres extension). This will potentially reduce number of interactions made
41-
to database and schema foot print.
22+
core logic. But currently, their implementation is completely isolated and do not
23+
share a common schema in Postgres. We're having a plan to simplify them via a
24+
common 'event storage and retrieval' interface (maybe via a Postgres extension?).
25+
This will potentially reduce number of interactions made to database and schema foot print.
4226
4327
TODO: Reference to open issue or rfc?
4428
-}
@@ -52,24 +36,23 @@ TODO: Reference to open issue or rfc?
5236
--
5337
-- This class has functions broadly related to:
5438
--
55-
-- 1. Metadata Management
39+
-- 1. Metadata Management (TODO: Need to be added to the type class)
5640
-- ----------------------
57-
-- TODO
5841
-- Basic metadata management functions such as retrieving metadata from storage
5942
-- database and replacing the given metadata.
6043
--
6144
-- 2. Scheduled Triggers
6245
-- ---------------------
6346
-- Eventing sub-system for scheduled triggers is implemented via metadata storage.
64-
-- All necessary functions are included in the type class.
65-
-- TODO
66-
-- This also includes functions to fetch events and their invocations so that the
67-
-- console can show them in the UI.
6847
-- For more details, refer description in 'Hasura.Eventing.ScheduledTrigger' module.
6948
--
70-
-- 3. Async Actions
49+
-- TODO: Functions need to be added to the type class
50+
-- - Retrieving invocation logs from storage (console requirement)
51+
-- - Deleting an scheduled event
52+
-- - Creating an one-off scheduled event
53+
--
54+
-- 3. Async Actions (TODO: Need to be added to the type class)
7155
-- ----------------
72-
-- TODO
7356
-- Operations to implement async actions sub-system. This includes recording an
7457
-- async action event and retreiving the details of action delivery to the webhook.
7558
-- For more details see Note [Async action architecture] in 'Hasura.GraphQL.Execute.Action' module.
@@ -81,9 +64,12 @@ TODO: Reference to open issue or rfc?
8164
class (MonadError QErr m) => MonadMetadataStorage m where
8265

8366
-- Scheduled triggers
84-
-- By design, scheduled trigger eventing has many database interactions.
85-
-- Hence we have many functions. We can reduce the functions by having
86-
-- a common interface for eventing. See Note [Todo: Common interface for eventing sub-system]
67+
-- TODO:-
68+
-- Ideally we would've liked to avoid having functions that are specific to
69+
-- scheduled/cron triggers and instead have functions that provide a generic
70+
-- 'event storage and retrieval' interface but we'll have to change a lot of
71+
-- existing code for scheduled and cron triggers. We can get to this after the
72+
-- multi-source work is done. See Note [Todo: Common interface for eventing sub-system]
8773
getDeprivedCronTriggerStats :: m [CronTriggerStats]
8874
getScheduledEventsForDelivery :: m ([CronEvent], [OneOffScheduledEvent])
8975
insertScheduledEvent :: ScheduledEventSeed -> m ()
@@ -109,3 +95,20 @@ instance (MonadMetadataStorage m) => MonadMetadataStorage (Tracing.TraceT m) whe
10995
setScheduledEventOp a b c = lift $ setScheduledEventOp a b c
11096
unlockScheduledEvents a b = lift $ unlockScheduledEvents a b
11197
unlockAllLockedScheduledEvents = lift unlockAllLockedScheduledEvents
98+
99+
-- | The 'MetadataStorageT' transformer adds ability to throw exceptions
100+
-- for monads deriving @'MonadMetadataStorage' instance.
101+
newtype MetadataStorageT m a
102+
= MetadataStorageT {unMetadataStorageT :: ExceptT QErr m a}
103+
deriving ( Functor, Applicative, Monad
104+
, MonadError QErr
105+
, MonadTrans
106+
, MonadIO
107+
, MFunctor
108+
, Tracing.HasReporter
109+
)
110+
111+
runMetadataStorageT
112+
:: MetadataStorageT m a -> m (Either QErr a)
113+
runMetadataStorageT =
114+
runExceptT . unMetadataStorageT

0 commit comments

Comments
 (0)