odd-jobs-0.2.2: A full-featured PostgreSQL-backed job queue (with an admin UI)

Safe HaskellNone
LanguageHaskell2010

OddJobs.ConfigBuilder

Synopsis

Documentation

mkConfig Source #

Arguments

:: (LogLevel -> LogEvent -> IO ())

"Structured logging" function. Ref: cfgLogger

-> TableName

DB table which holds your jobs. Ref: cfgTableName

-> Pool Connection

DB connection-pool to be used by job-runner. Ref: cfgDbPool

-> ConcurrencyControl

Concurrency configuration. Ref: cfgConcurrencyControl

-> (Job -> IO ())

The actual "job runner" which contains your application code. Ref: cfgJobRunner

-> (Config -> Config)

A function that allows you to modify the "interim config". The "interim config" will cotain a bunch of in-built default config params, along with the config params that you've just provided (i.e. logging function, table name, DB pool, etc). You can use this function to override values in the "interim config". If you do not wish to modify the "interim config" just pass id as an argument to this parameter. Note: it is strongly recommended that you do not modify the generated Config outside of this function, unless you know what you're doing.

-> Config

The final Config that can be used to start various job-runners

This function gives you a Config with a bunch of sensible defaults already applied. It requires the bare minimum configuration parameters that this library cannot assume on your behalf.

It makes a few important assumptions about your 'jobPayload 'JSON, which are documented in defaultJobType.

defaultLogStr :: (Job -> Text) -> LogLevel -> LogEvent -> LogStr Source #

If you aren't interested in structured logging, you can use this function to emit plain-text logs (or define your own).

defaultJobToHtml :: (Job -> Text) -> [Job] -> IO [Html ()] Source #

defaultJobType :: Job -> Text Source #

This makes two important assumptions. First, this assumes that jobs in your app are represented by a sum-type. For example:

data MyJob = SendWelcomeEmail Int
           | SendPasswordResetEmail Text
           | SetupSampleData Int

Second, it assumes that the JSON representatin of this sum-type is "tagged". For example, the following...

let pload = SendWelcomeEmail 10

...when converted to JSON, would look like...

{"tag":"SendWelcomeEmail", "contents":10}

It uses this assumption to extract the "job type" from a Value (which would be SendWelcomeEmail in the example given above). This is used in logging and the admin UI.

Even if tihs assumption is violated, the job-runner should continue to function. It's just that you won't get very useful log messages.

Note: If your job payload does not conform to the structure described above, please read the section on customising the job payload's structure in the implementation guide.

withConnectionPool :: MonadUnliftIO m => Either ByteString ConnectInfo -> (Pool Connection -> m a) -> m a Source #

Convenience function to create a DB connection-pool with some sensible defaults. Please see the source-code of this function to understand what it's doing.

defaultTimedLogger :: TimedFastLogger -> (LogLevel -> LogEvent -> LogStr) -> LogLevel -> LogEvent -> IO () Source #

A convenience function to help you define a timed-logger with some sensible defaults.