nextScheduledJob :: Connection -> IO (Maybe Task)
nextScheduledJob con = do
  jobs <- query_ con
    "SELECT id, next_push_at, q_name, method, args FROM scheduled_jobs \
    \ORDER BY next_push_at ASC LIMIT 1"
  case jobs of
    [] -> return Nothing
    -- Use Data.Time.Clock ...
    (i, r::C.UTCTime, q, m, a):_ -> do
      -- ... then convert from epoch to Thyme's UTCTime.
      let secondsSinceEpoch = (floor $ C.utcTimeToPOSIXSeconds r) :: Int
          t = mkUTCTime (fromGregorian 1970 0 0) (fromSeconds secondsSinceEpoch)
      return . Just $ Task i t q m a Nothing
      -- TODO Task repetition.

----------------------------------------------------------------------
-- Scheduled jobs
----------------------------------------------------------------------

-- | A `NOTIFY` is automatically sent by a trigger.
nextScheduledJob :: Connection -> IO (Maybe Task)
nextScheduledJob con = do
  jobs <- query_ con
    "SELECT id, next_push_at, q_name, method, args FROM scheduled_jobs \
    \ORDER BY next_push_at ASC LIMIT 1"
  case jobs of
    [] -> return Nothing
    -- Use Data.Time.Clock ...
    (i, r::C.UTCTime, q, m, a):_ -> do
      -- ... then convert from epoch to Thyme's UTCTime.
      let secondsSinceEpoch = (floor $ C.utcTimeToPOSIXSeconds r) :: Int
          t = mkUTCTime (fromGregorian 1970 0 0) (fromSeconds secondsSinceEpoch)
      return . Just $ Task i t q m a Nothing
      -- TODO Task repetition.

----------------------------------------------------------------------
-- Scheduled jobs
----------------------------------------------------------------------

-- | A `NOTIFY` is automatically sent by a trigger.
nextScheduledJob con = do
  jobs <- query_ con
    "SELECT id, next_push_at, q_name, method, args FROM scheduled_jobs \
    \ORDER BY next_push_at ASC LIMIT 1"
  case jobs of
    [] -> return Nothing
    -- Use Data.Time.Clock ...
    (i, r::C.UTCTime, q, m, a):_ -> do
      -- ... then convert from epoch to Thyme's UTCTime.
      let secondsSinceEpoch = (floor $ C.utcTimeToPOSIXSeconds r) :: Int
          t = mkUTCTime (fromGregorian 1970 0 0) (fromSeconds secondsSinceEpoch)
      return . Just $ Task i t q m a Nothing
      -- TODO Task repetition.

----------------------------------------------------------------------
-- Scheduled jobs
----------------------------------------------------------------------

-- | A `NOTIFY` is automatically sent by a trigger.