MyNixOS website logo
Description

Background jobs library for Yesod.

Background jobs library for Yesod

  • It contains management API and web interface.

  • Queue backend is Redis.

  • Support cron scheduler

Usage and screen shot are available in README.md

yesod-job-queue Hackage Stackage LTS Stackage Nightly Build Status

Background jobs library for Yesod.

  • There are API and Web UI for managing the job.
  • Queue backend is Redis.
  • Multithreaded.

Web interface

web interface screenshot

Usage

Prepare the JobState to manage the running jobs

import Yesod.JobQueue

data App = App {
    appConnPool :: ConnectionPool
    , appDBConf :: SqliteConf
    , appJobState :: JobState
    }

-- e.g. In makeFoundation
main = do
    jobState <- newJobState -- create JobState
    let app = App pool dbConf jobState

Make the routes for API & Manager UI

mkYesod "App" [parseRoutes|
/ HomeR GET
/job JobQueueR JobQueue getJobQueue -- ^ JobQueue API and Manager
|]

Define the job. And, to the setting of JobQueue

-- Your job type
data MyJobType = AggregationUser
               | PushNotification
               | HelloJob String
               deriving (Show, Read, Generic)

-- JobQueue settings
instance YesodJobQueue App where
    type JobType App = MyJobType
    getJobState = appJobState
    threadNumber _ = 2
    runDBJob action = do -- Required if you use the DB in the job
        app <- ask
        runSqlPool action $ appConnPool app
    -- Your Job code
    runJob _ AggregationUser = do
        us <- runDBJob $ selectList ([] :: [Filter Person]) []
        liftIO $ threadDelay $ 10 * 1000 * 1000
        print us
        putStrLn "complate job!"
    runJob _ PushNotification = do
        putStrLn "sent norification!"
    runJob _ (HelloJob name) = do
        putStrLn . pack $ "Hello " ++ name

Please see example

Configration queue backend (Redis)

The default is to connect to redis localhost:6379.

And, you can change connect info by queueConnectInfo

Build package

stack build

build javascripts (required when app/* was editted)

cd app
npm install
npm run build-js
# need again `stack build`

developping app/*

You can edit app/app.js without re-build package

npm run watch-js ## watch app/*.js for changes, automatically build.
npm run bs ## serving app.bundle.js at `http://localhost:3001/dist/app.bundle.js` for test

in example/Main.hs. to use test version of app.bundle.js.

jobManagerJSUrl _ = "http://localhost:3001/dist/app.bundle.js"

Run example

stack build --flag yesod-job-queue:example && stack exec yesod-job-queue-example

You can access Web UI: http://localhost:3000/job/manager.

Metadata

Version

0.3.0.4

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows