yesod-job-queue: Background jobs library for Yesod.

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

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


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
example

Build the example application

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.2.0.0, 0.2.0.1, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.0.3, 0.3.0.4
Dependencies aeson (>=1.1), api-field-json-th (>=0.1), base (>=4.7 && <5), bytestring, classy-prelude-yesod, cron (>=0.5.0 && <0.6), file-embed, hedis, lens, monad-control, monad-logger, persistent-sqlite, resourcet, stm, text, time, transformers, uuid, yesod (>=1.4 && <1.5), yesod-core, yesod-job-queue, yesod-persistent (>=1.4 && <1.5) [details]
License BSD-3-Clause
Copyright 2016 Daishi Nakajima
Author Daishi Nakajima
Maintainer nakaji.dayo@gmail.com
Category Web
Home page https://github.com/nakaji-dayo/yesod-job-queue#readme
Source repo head: git clone https://github.com/nakaji-dayo/yesod-job-queue
Uploaded by nakaji_dayo at 2017-05-17T04:58:11Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables yesod-job-queue-example
Downloads 7373 total (2 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-05-17 [all 1 reports]

Readme for yesod-job-queue-0.3.0.4

[back to package description]

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