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

[ bsd3, library, program, web ] [ Propose Tags ]
  • Background jobs library for Haskell.

  • Extracted from production code at Vacation Labs.

  • Inspired by the Delayed Jobs library in Rails.

  • Queue backend is a Postgres table.

  • Queue is monitored using, both, LISTEN/NOTIFY and polling the DB.

  • Comes with an in-built admin UI (WIP).

  • Comes with utilities to help you built a CLI for your job-queue.

  • Highly configurable and monitorable


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0, 0.2.1, 0.2.2
Change log CHANGELOG.md
Dependencies aeson, base (>=4.7 && <5), bytestring, direct-daemonize, directory, either, fast-logger, filepath, foreign-store, friendly-time, hostname, lucid, monad-control, monad-logger, mtl, odd-jobs, optparse-applicative, postgresql-simple, resource-pool, safe, servant, servant-lucid, servant-server, string-conv, text, text-conversions, time, timing-convenience, unix, unliftio, unliftio-core, unordered-containers, warp [details]
License BSD-3-Clause
Copyright 2016-2020 Saurabh Nanda
Author Saurabh Nanda
Maintainer saurabhnanda@gmail.com
Category Web
Home page https://www.haskelltutorials.com/odd-jobs
Bug tracker https://github.com/saurabhnanda/odd-jobs/issues
Uploaded by saurabhnanda at 2020-04-28T09:24:46Z
Distributions
Executables devel
Downloads 998 total (14 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-04-28 [all 1 reports]

Readme for odd-jobs-0.1.0

[back to package description]

Introduction

Please read the detailed tutorial available at Odd Jobs Tutorial. Broadly, here is the most common way to get started with this library:

  • (For a working version of the steps described below, please check the simple-example directory in the project repo).

  • Create a DB table to hold your jobs using the OddJobs.Migrations.createJobTable function.

  • Create a sum-type to represent your job payloads, for example:

    data MyJob = SendWelcomeEmail Int
               | SendPasswordResetEmail Text
               | SetupSampleData Int
               deriving (Eq, Show, Generic, ToJSON, FromJSON)
    
  • Ensure that you use a "tagged" JSON encoding for this data-type for best results (this is the default behaviour in Aeson). For example:

    Aeson.encode (SendWelcomeEmail 10) == "{\"tag\":\"SendWelcomeEmail\", \"contents\":10}"
    
  • Create you "core" job-runner function:

    myJobRunner :: Job -> IO ()
    myJobRunner Job{jobPayload} = 
      case jobPayload of
        SendWelcomeEmail userId -> sendWelcomeEmail userId
        SendPasswordResetEmail tkn -> sendPasswordResetEmail tkn
        SetupSampleData userId -> sendPasswordResetEmail userId
    
  • Use OddJobs.Job.createJob and OddJobs.Job.scheduleJob within your app whenever you want to enqueue a job.

  • Use OddJobs.Cli to wrap all of this together into a nice CLI that can fork itself as a background daemon.

  • Hook this up to your deployment scripts and you're good to go!