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

[ bsd3, library, program, web ] [ Propose Tags ]

[Skip to Readme]
Versions [faq] 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 NixOS:0.2.1
Executables devel
Downloads 197 total (18 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-04-28 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


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!