Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data JobEnv t w a = JobEnv {
- jeSettings :: JobSettings
- jeState :: JobsState t w a
- jeManager :: Manager
- type NumRunners = Int
- data JobError
- class MonadIO m => MonadJob m t w a | m -> t w a where
- class ToHumanFriendlyError e where
- mkHumanFriendly :: e -> Text
- class MonadJobStatus m where
- type JobHandle m :: Type
- type JobType m :: Type
- type JobOutputType m :: Type
- type JobEventType m :: Type
- noJobHandle :: Proxy m -> JobHandle m
- getLatestJobStatus :: JobHandle m -> m (JobEventType m)
- withTracer :: Logger (JobEventType m) -> JobHandle m -> (JobHandle m -> m a) -> m a
- markStarted :: Int -> JobHandle m -> m ()
- markProgress :: Int -> JobHandle m -> m ()
- markFailure :: forall e. ToHumanFriendlyError e => Int -> Maybe e -> JobHandle m -> m ()
- markComplete :: JobHandle m -> m ()
- markFailed :: forall e. ToHumanFriendlyError e => Maybe e -> JobHandle m -> m ()
- addMoreSteps :: MonadJobStatus m => Int -> JobHandle m -> m ()
- newJobEnv :: (EnumBounded t, Monoid w) => JobSettings -> Map t Prio -> Manager -> IO (JobEnv t w a)
- defaultJobSettings :: NumRunners -> SecretKey -> JobSettings
- genSecret :: IO SecretKey
- getJobsSettings :: MonadJob m t w a => m JobSettings
- getJobsState :: MonadJob m t w a => m (JobsState t w a)
- getJobsMap :: MonadJob m t w a => m (JobMap (JobID 'Safe) w a)
- getJobsQueue :: MonadJob m t w a => m (Queue t (JobID 'Safe))
- queueJob :: (MonadJob m t w a, Ord t) => t -> i -> (JobID 'Safe -> i -> Logger w -> IO a) -> m (JobID 'Safe)
- findJob :: MonadJob m t w a => JobID 'Safe -> m (Maybe (JobEntry (JobID 'Safe) w a))
- checkJID :: MonadJob m t w a => JobID 'Unsafe -> m (Either JobError (JobID 'Safe))
- withJob :: MonadJob m t w a => JobID 'Unsafe -> (JobID 'Safe -> JobEntry (JobID 'Safe) w a -> m r) -> m (Either JobError (Maybe r))
- handleIDError :: MonadError e m => (JobError -> e) -> m (Either JobError a) -> m a
- removeJob :: (Ord t, MonadJob m t w a) => Bool -> t -> JobID 'Safe -> m ()
- markFailedNoErr :: MonadJobStatus m => JobHandle m -> m ()
- markFailureNoErr :: MonadJobStatus m => Int -> JobHandle m -> m ()
Types and classes
JobEnv | |
|
type NumRunners = Int #
InvalidIDType Text | We expected to find a job tagged internall as "job", but we found the input |
IDExpired Int | The given ID expired. |
InvalidMacID Text | |
UnknownJob Int | |
JobException SomeException |
Reporting errors to users in a friendly way
class ToHumanFriendlyError e where #
This class represents the concept of "human friendly strings", by which we mean error messages and/or diagnostics which needs to be displayed to the end users, and, as such:
- They should be easy to understand for end users, not developers (developers would access the full debug logs on the server machine). As such, they don't have to include implementation details and/or technicalities;
- They MUST NOT include any sensitive data. Please be very careful when writing these instances
because just calling "T.pack . show" on the input data is immediately wrong; things like Servant's
ClientError
or any HTTP exception might include api keys in the form of HTTP headers, so leaking that is BAD.
mkHumanFriendly :: e -> Text #
Instances
ToHumanFriendlyError Void # | |
Defined in Gargantext.Utils.Jobs.Error mkHumanFriendly :: Void -> Text # | |
ToHumanFriendlyError GetCorpusError # | |
Defined in Gargantext.Core.Text.Corpus.API mkHumanFriendly :: GetCorpusError -> Text # | |
ToHumanFriendlyError ParseFormatError # | |
Defined in Gargantext.Core.Text.Corpus.Parsers mkHumanFriendly :: ParseFormatError -> Text # | |
ToHumanFriendlyError HumanFriendlyErrorText # | |
Defined in Gargantext.Utils.Jobs.Error |
Tracking jobs status
class MonadJobStatus m where #
A monad to query for the status of a particular job and submit updates for in-progress jobs.
This is type family for the concrete JobHandle
that is associated to
a job when it starts and it can be used to query for its completion status. Different environment
can decide how this will look like.
type JobOutputType m :: Type #
type JobEventType m :: Type #
noJobHandle :: Proxy m -> JobHandle m #
A job handle that doesn't do anything. Sometimes useful in all those circumstances
where we need to test a function taking a JobHandle
as input but we are not interested
in the progress tracking.
getLatestJobStatus :: JobHandle m -> m (JobEventType m) #
Retrevies the latest JobEventType
from the underlying monad. It can be
used to query the latest status for a particular job, given its JobHandle
as input.
withTracer :: Logger (JobEventType m) -> JobHandle m -> (JobHandle m -> m a) -> m a #
Adds an extra "tracer" that logs events to the passed action. Produces
a new JobHandle
.
markStarted :: Int -> JobHandle m -> m () #
Start tracking a new JobEventType
with n
remaining steps.
markProgress :: Int -> JobHandle m -> m () #
Mark n
steps of the job as succeeded, while simultaneously substracting this number
from the remaining steps.
markFailure :: forall e. ToHumanFriendlyError e => Int -> Maybe e -> JobHandle m -> m () #
Mark n
step of the job as failed, while simultaneously substracting this number
from the remaining steps. Attach an optional error message to the failure.
markComplete :: JobHandle m -> m () #
Finish tracking a job by marking all the remaining steps as succeeded.
markFailed :: forall e. ToHumanFriendlyError e => Maybe e -> JobHandle m -> m () #
Finish tracking a job by marking all the remaining steps as failed. Attach an optional message to the failure.
addMoreSteps :: MonadJobStatus m => Int -> JobHandle m -> m () #
Add n
more steps to the running computation, they will be marked as remaining.
Instances
Functions
newJobEnv :: (EnumBounded t, Monoid w) => JobSettings -> Map t Prio -> Manager -> IO (JobEnv t w a) #
defaultJobSettings :: NumRunners -> SecretKey -> JobSettings #
getJobsSettings :: MonadJob m t w a => m JobSettings #
getJobsState :: MonadJob m t w a => m (JobsState t w a) #
queueJob :: (MonadJob m t w a, Ord t) => t -> i -> (JobID 'Safe -> i -> Logger w -> IO a) -> m (JobID 'Safe) #
withJob :: MonadJob m t w a => JobID 'Unsafe -> (JobID 'Safe -> JobEntry (JobID 'Safe) w a -> m r) -> m (Either JobError (Maybe r)) #
handleIDError :: MonadError e m => (JobError -> e) -> m (Either JobError a) -> m a #
markFailedNoErr :: MonadJobStatus m => JobHandle m -> m () #
Helper on top of markFailed
for when we don't have a diagnostic to log.
markFailureNoErr :: MonadJobStatus m => Int -> JobHandle m -> m () #