Repository: hasura/graphql-engine
File: server/src-lib/Hasura/Eventing/ScheduledTrigger.hs (Haskell)

Code before:
  , saseRetryConf     :: !STRetryConf
  , saseHeaderConf    :: ![HeaderConf]
  , saseComment       :: !(Maybe Text)
  } deriving (Show, Eq)

$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''StandAloneScheduledEvent)

-- | The 'ScheduledEventType' data type is needed to differentiate
--   between a 'CronScheduledEvent' and 'StandAloneEvent' scheduled
--   event because they both have different configurations
--   and they live in different tables.
data ScheduledEventType =
    CronScheduledEvent
  -- ^ A Cron scheduled event has a template defined which will
  -- contain the webhook, header configuration, retry
  -- configuration and a payload. Every cron event created
  -- uses the above mentioned configurations defined in the template.
  -- The configuration defined with the cron trigger is cached
  -- and hence it's not fetched along the cron scheduled events.
  | StandAloneEvent
  -- ^ A standalone scheduled event doesn't have any template defined
  -- so all the configuration is fetched along the scheduled events.
    deriving (Eq, Show)

data ScheduledEventWebhookBody
  = ScheduledEventWebhookBody
  { sewbId            :: !Text
  , sewbName          :: !(Maybe TriggerName)
  , sewbScheduledTime :: !UTCTime
  , sewbPayload       :: !J.Value
  , sewbComment       :: !(Maybe Text)
  , sewbCreatedAt     :: !UTCTime
  } deriving (Show, Eq)

$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''ScheduledEventWebhookBody)

-- | runCronEventsGenerator makes sure that all the cron triggers
--   have an adequate buffer of cron events.
runCronEventsGenerator ::
     L.Logger L.Hasura
  -> Q.PGPool
  -> IO SchemaCache
  -> IO void
runCronEventsGenerator logger pgpool getSC = do
  forever $ do
    sc <- getSC
    -- get cron triggers from cache
    let cronTriggersCache = scCronTriggers sc

    -- get cron trigger stats from db
    runExceptT

Review comment (suggestion):
I’m a little bit curious: the original issue shows a request payload with these fields in the console. So these fields must come from somewhere in the code already, right? It seems like it would be useful to share the definition of those types in some way. But maybe I’m misunderstanding something.

Code after:
  , sefHeaders       :: ![EventHeaderInfo]
  , sefComment       :: !(Maybe Text)
  } deriving (Show, Eq)

$(J.deriveToJSON (J.aesonDrop 3 J.snakeCase) {J.omitNothingFields = True} ''ScheduledEventFull)

data StandAloneScheduledEvent
  = StandAloneScheduledEvent
  { saseId            :: !StandAloneScheduledEventId
  , saseScheduledTime :: !UTCTime
  , saseTries         :: !Int
  , saseWebhook       :: !InputWebhook
  , sasePayload       :: !(Maybe J.Value)
  , saseRetryConf     :: !STRetryConf
  , saseHeaderConf    :: ![HeaderConf]
  , saseComment       :: !(Maybe Text)
  } deriving (Show, Eq)

$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''StandAloneScheduledEvent)

-- | The 'ScheduledEventType' data type is needed to differentiate
--   between a 'CronScheduledEvent' and 'StandAloneEvent' scheduled
--   event because they both have different configurations
--   and they live in different tables.
data ScheduledEventType =
    CronScheduledEvent
  -- ^ A Cron scheduled event has a template defined which will
  -- contain the webhook, header configuration, retry
  -- configuration and a payload. Every cron event created
  -- uses the above mentioned configurations defined in the template.
  -- The configuration defined with the cron trigger is cached
  -- and hence it's not fetched along the cron scheduled events.
  | StandAloneEvent
  -- ^ A standalone scheduled event doesn't have any template defined
  -- so all the configuration is fetched along the scheduled events.
    deriving (Eq, Show)

data ScheduledEventWebhookPayload
  = ScheduledEventWebhookPayload
  { sewpId            :: !Text
  , sewpName          :: !(Maybe TriggerName)
  , sewpScheduledTime :: !UTCTime
  , sewpPayload       :: !J.Value
  , sewpComment       :: !(Maybe Text)
  , sewpCreatedAt     :: !UTCTime
  } deriving (Show, Eq)

$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''ScheduledEventWebhookPayload)

-- | runCronEventsGenerator makes sure that all the cron triggers
--   have an adequate buffer of cron events.