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

Code before:
data CronEventPartial
  = CronEventPartial
  { cepId            :: !CronEventId
  , cepName          :: !TriggerName
  , cepScheduledTime :: !UTCTime
  , cepTries         :: !Int
  , cepCreatedAt     :: !UTCTime
  } deriving (Show, Eq)

data ScheduledEventFull
  = ScheduledEventFull
  { sefId            :: !ScheduledEventId
  , sefName          :: !(Maybe TriggerName)
  -- ^ sefName is the name of the cron trigger.
  -- A one-off scheduled event is not associated with a name, so in that
  -- case, 'sefName' will be @Nothing@
  , sefScheduledTime :: !UTCTime
  , sefTries         :: !Int
  , sefWebhook       :: !Text
  , sefPayload       :: !J.Value
  , sefRetryConf     :: !STRetryConf
  , sefHeaders       :: ![EventHeaderInfo]
  , sefComment       :: !(Maybe Text)
  , sefCreatedAt     :: !UTCTime
  } deriving (Show, Eq)
$(J.deriveToJSON (J.aesonDrop 3 J.snakeCase) {J.omitNothingFields = True} ''ScheduledEventFull)

data OneOffScheduledEvent
  = OneOffScheduledEvent
  { ooseId            :: !OneOffScheduledEventId
  , ooseScheduledTime :: !UTCTime
  , ooseTries         :: !Int
  , ooseWebhook       :: !InputWebhook
  , oosePayload       :: !(Maybe J.Value)
  , ooseRetryConf     :: !STRetryConf
  , ooseHeaderConf    :: ![HeaderConf]
  , ooseComment       :: !(Maybe Text)
  , ooseCreatedAt     :: !UTCTime
  } deriving (Show, Eq)
$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''OneOffScheduledEvent)

-- | The 'ScheduledEventType' data type is needed to differentiate
--   between a 'CronScheduledEvent' and 'OneOffScheduledEvent' 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.

Review comment (suggestion):
Let's not send `createdAt` for cron events as it is an implementation detail and can be confusing to consumers.

Code after:
data CronEventPartial
  = CronEventPartial
  { cepId            :: !CronEventId
  , cepName          :: !TriggerName
  , cepScheduledTime :: !UTCTime
  , cepTries         :: !Int
  , cepCreatedAt     :: !UTCTime
  -- ^ cepCreatedAt is the time at which the cron event generator
  -- created the cron event
  } deriving (Show, Eq)

data ScheduledEventFull
  = ScheduledEventFull
  { sefId            :: !ScheduledEventId
  , sefName          :: !(Maybe TriggerName)
  -- ^ sefName is the name of the cron trigger.
  -- A one-off scheduled event is not associated with a name, so in that
  -- case, 'sefName' will be @Nothing@
  , sefScheduledTime :: !UTCTime
  , sefTries         :: !Int
  , sefWebhook       :: !Text
  , sefPayload       :: !J.Value
  , sefRetryConf     :: !STRetryConf
  , sefHeaders       :: ![EventHeaderInfo]
  , sefComment       :: !(Maybe Text)
  , sefCreatedAt     :: !UTCTime
  } deriving (Show, Eq)
$(J.deriveToJSON (J.aesonDrop 3 J.snakeCase) {J.omitNothingFields = True} ''ScheduledEventFull)

data OneOffScheduledEvent
  = OneOffScheduledEvent
  { ooseId            :: !OneOffScheduledEventId
  , ooseScheduledTime :: !UTCTime
  , ooseTries         :: !Int
  , ooseWebhook       :: !InputWebhook
  , oosePayload       :: !(Maybe J.Value)
  , ooseRetryConf     :: !STRetryConf
  , ooseHeaderConf    :: ![HeaderConf]
  , ooseComment       :: !(Maybe Text)
  , ooseCreatedAt     :: !UTCTime
  } deriving (Show, Eq)
$(J.deriveToJSON (J.aesonDrop 4 J.snakeCase) {J.omitNothingFields = True} ''OneOffScheduledEvent)

-- | The 'ScheduledEventType' data type is needed to differentiate
--   between a 'CronScheduledEvent' and 'OneOffScheduledEvent' scheduled
--   event because they both have different configurations
--   and they live in different tables.
data ScheduledEventType =
    Cron
  -- ^ A Cron scheduled event has a template defined which will
  -- contain the webhook, header configuration, retry