All Projects → sheharyarn → Que

sheharyarn / Que

Licence: mit
Simple Job Processing in Elixir with Mnesia ⚡️

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Que

celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-73.2%)
Mutual labels:  background-jobs, job-queue
Gen queue
Generic queues with adapter support for Elixir
Stars: ✭ 41 (-93.3%)
Mutual labels:  background-jobs, job-queue
Resque
Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later.
Stars: ✭ 9,031 (+1375.65%)
Mutual labels:  background-jobs, job-queue
Qutee
PHP Background Jobs (Tasks) Manager
Stars: ✭ 63 (-89.71%)
Mutual labels:  background-jobs, job-queue
Coravel
Near-zero config .NET Core micro-framework that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
Stars: ✭ 1,989 (+225%)
Mutual labels:  hacktoberfest, background-jobs
Django Rq
A simple app that provides django integration for RQ (Redis Queue)
Stars: ✭ 1,361 (+122.39%)
Mutual labels:  background-jobs, job-queue
Rq
Simple job queues for Python
Stars: ✭ 8,065 (+1217.81%)
Mutual labels:  background-jobs, job-queue
Enqueue Dev
Message Queue, Job Queue, Broadcasting, WebSockets packages for PHP, Symfony, Laravel, Magento. DEVELOPMENT REPOSITORY - provided by Forma-Pro
Stars: ✭ 1,977 (+223.04%)
Mutual labels:  hacktoberfest, job-queue
Hazelcast
Open-source distributed computation and storage platform
Stars: ✭ 4,662 (+661.76%)
Mutual labels:  hacktoberfest, in-memory
Challenges
PyBites Code Challenges
Stars: ✭ 604 (-1.31%)
Mutual labels:  hacktoberfest
Octodash
OctoDash is a simple, but beautiful dashboard for OctoPrint.
Stars: ✭ 606 (-0.98%)
Mutual labels:  hacktoberfest
Materialdialog Android
📱Android Library to implement animated, 😍beautiful, 🎨stylish Material Dialog in android apps easily.
Stars: ✭ 602 (-1.63%)
Mutual labels:  hacktoberfest
Images To Pdf
An app to convert images to PDF file!
Stars: ✭ 602 (-1.63%)
Mutual labels:  hacktoberfest
Kiwi
the leading open source test management system
Stars: ✭ 607 (-0.82%)
Mutual labels:  hacktoberfest
Earthdata Search
Earthdata Search is a web application developed by NASA EOSDIS to enable data discovery, search, comparison, visualization, and access across EOSDIS' Earth Science data holdings.
Stars: ✭ 602 (-1.63%)
Mutual labels:  hacktoberfest
Syntax
A website for the Syntax Podcast
Stars: ✭ 610 (-0.33%)
Mutual labels:  hacktoberfest
Bookreader
The Internet Archive BookReader
Stars: ✭ 596 (-2.61%)
Mutual labels:  hacktoberfest
Runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
Stars: ✭ 7,742 (+1165.03%)
Mutual labels:  hacktoberfest
Meshery
Meshery, the service mesh management plane
Stars: ✭ 608 (-0.65%)
Mutual labels:  hacktoberfest
Statsd exporter
StatsD to Prometheus metrics exporter
Stars: ✭ 608 (-0.65%)
Mutual labels:  hacktoberfest

Que

Build Status Coverage Status Version License

Simple Background Job Processing in Elixir ⚡️

Que is a job processing library backed by Mnesia, a distributed real-time database that comes with Erlang / Elixir. That means it doesn't depend on any external services like Redis for persisting job state. This makes it really easy to use since you don't need to install anything other than Que itself.

See the Documentation.


Installation

Add que to your project dependencies in mix.exs:

def deps do
  [{:que, "~> 0.10.1"}]
end

and then add it to your list of applications:

def application do
  [applications: [:que]]
end

Mnesia Setup

Que runs out of the box, but by default all jobs are stored in-memory. To persist jobs across application restarts, specify the DB path in your config.exs:

config :mnesia, dir: 'mnesia/#{Mix.env}/#{node()}'        # Notice the single quotes

And run the following mix task:

$ mix que.setup

This will create the Mnesia schema and job database for you. For a detailed guide, see the Mix Task Documentation. For compiled releases where Mix is not available see this.


Usage

Que is very similar to other job processing libraries such as Ku and Toniq. Start by defining a Worker with a perform/1 callback to process your jobs:

defmodule App.Workers.ImageConverter do
  use Que.Worker

  def perform(image) do
    ImageTool.save_resized_copy!(image, :thumbnail)
    ImageTool.save_resized_copy!(image, :medium)
  end
end

You can now add jobs to be processed by the worker:

Que.add(App.Workers.ImageConverter, some_image)
#=> {:ok, %Que.Job{...}}

Pattern Matching

The argument here can be any term from a Tuple to a Keyword List or a Struct. You can also pattern match and use guard clauses like any other method:

defmodule App.Workers.NotificationSender do
  use Que.Worker

  def perform(type: :like, to: user, count: count) do
    User.notify(user, "You have #{count} new likes on your posts")
  end

  def perform(type: :message, to: user, from: sender) do
    User.notify(user, "You received a new message from #{sender.name}")
  end

  def perform(to: user) do
    User.notify(user, "New activity on your profile")
  end
end

Concurrency

By default, all workers process one Job at a time, but you can customize that by passing the concurrency option:

defmodule App.Workers.SignupMailer do
  use Que.Worker, concurrency: 4

  def perform(email) do
    Mailer.send_email(to: email, message: "Thank you for signing up!")
  end
end

Job Success / Failure Callbacks

The worker can also export optional on_success/1 and on_failure/2 callbacks that handle appropriate cases.

defmodule App.Workers.ReportBuilder do
  use Que.Worker

  def perform({user, report}) do
    report.data
    |> PDFGenerator.generate!
    |> File.write!("reports/#{user.id}/report-#{report.id}.pdf")
  end

  def on_success({user, _}) do
    Mailer.send_email(to: user.email, subject: "Your Report is ready!")
  end

  def on_failure({user, report}, error) do
    Mailer.send_email(to: user.email, subject: "There was a problem generating your report")
    Logger.error("Could not generate report #{report.id}. Reason: #{inspect(error)}")
  end
end

Setup and Teardown

You can similarly export optional on_setup/1 and on_teardown/1 callbacks that are respectively run before and after the job is performed (successfully or not). But instead of the job arguments, they pass the job struct as an argument which holds a lot more internal details that can be useful for custom features such as logging, metrics, requeuing and more.

defmodule MyApp.Workers.VideoProcessor do
  use Que.Worker

  def on_setup(%Que.Job{} = job) do
    VideoMetrics.record(job.id, :start, process: job.pid, status: :starting)
  end

  def perform({user, video, options}) do
    User.notify(user, "Your video is processing, check back later.")
    FFMPEG.process(video.path, options)
  end

  def on_teardown(%Que.Job{} = job) do
    {user, video, _options} = job.arguments
    link = MyApp.Router.video_path(user.id, video.id)

    VideoMetrics.record(job.id, :end, status: job.status)
    User.notify(user, "We've finished processing your video. See the results.", link)
  end
end

Head over to Hexdocs for detailed Worker documentation.


Roadmap

  • [x] Write Documentation
  • [x] Write Tests
  • [x] Persist Job State to Disk
    • [x] Provide an API to interact with Jobs
  • [x] Add Concurrency Support
    • [x] Make jobs work in Parallel
    • [x] Allow customizing the number of concurrent jobs
  • [x] Success/Failure Callbacks
  • [x] Find a more reliable replacement for Amnesia
  • [ ] Delayed Jobs
  • [ ] Allow job cancellation
  • [ ] Job Priority
  • [ ] Support running in a multi-node enviroment
    • [ ] Recover from node failures
  • [ ] Support for more Persistence Adapters
    • [ ] Redis
    • [ ] Postgres
  • [x] Mix Task for creating Mnesia Database
  • [ ] Better Job Failures
    • [ ] Option to set timeout on workers
    • [ ] Add strategies to automatically retry failed jobs
  • [ ] Web UI

Contributing

  • Fork, Enhance, Send PR
  • Lock issues with any bugs or feature requests
  • Implement something from Roadmap
  • Spread the word ❤️

License

This package is available as open source under the terms of the MIT License.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].