All Projects → robacarp → Mosquito

robacarp / Mosquito

Licence: mit
A generic background task runner for crystal applications supporting periodic (CRON) and manually queued jobs

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to Mosquito

Finitediff.jl
Fast non-allocating calculations of gradients, Jacobians, and Hessians with sparsity support
Stars: ✭ 123 (-16.33%)
Mutual labels:  fast
Samsara
Samsara is a real-time analytics platform
Stars: ✭ 132 (-10.2%)
Mutual labels:  fast
Resque Scheduler
A light-weight job scheduling system built on top of Resque
Stars: ✭ 1,713 (+1065.31%)
Mutual labels:  background-jobs
Fast
Develop, build, deploy, redeploy, and teardown frontend projects fast.
Stars: ✭ 126 (-14.29%)
Mutual labels:  fast
Xamarin Crossdownloadmanager
A cross platform download manager for Xamarin
Stars: ✭ 131 (-10.88%)
Mutual labels:  background-jobs
Cachewebview
Custom implement Android WebView cache, offline website, let cahe config more simple and flexible
Stars: ✭ 1,767 (+1102.04%)
Mutual labels:  fast
Pbscan
Faster and more efficient stateless SYN scanner and banner grabber due to userland TCP/IP stack usage.
Stars: ✭ 122 (-17.01%)
Mutual labels:  fast
Myhtml
Fast HTML5 Parser with css selectors for Crystal language
Stars: ✭ 146 (-0.68%)
Mutual labels:  fast
Gosora
Gosora is an ultra-fast and secure forum software written in Go that balances usability with functionality.
Stars: ✭ 131 (-10.88%)
Mutual labels:  fast
Foxify
The fast, easy to use & typescript ready web framework for Node.js
Stars: ✭ 138 (-6.12%)
Mutual labels:  fast
Eix
eix can access Gentoo portage ebuild information and description very quickly (using a local cache). It can also be used to access information on installed packages, local settings, and local and external overlays, and informs about changes in the tree
Stars: ✭ 126 (-14.29%)
Mutual labels:  fast
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (-10.88%)
Mutual labels:  fast
Sidekiq
Simple, efficient background processing for Ruby
Stars: ✭ 11,450 (+7689.12%)
Mutual labels:  background-jobs
Litecraft
Open source, clean room implementation of Minecraft Client
Stars: ✭ 124 (-15.65%)
Mutual labels:  fast
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 (+1253.06%)
Mutual labels:  background-jobs
Fastrand
Fast and scalable pseudorandom generator for Go
Stars: ✭ 122 (-17.01%)
Mutual labels:  fast
Nimscan
🚀 Fast Port Scanner 🚀
Stars: ✭ 134 (-8.84%)
Mutual labels:  fast
Shelby
Shelby is a fast ⚡️ , lightweight ☁️ , minimal✨, shell prompt written in Go.
Stars: ✭ 148 (+0.68%)
Mutual labels:  fast
Nanoexpress
Professional backend framework for Node.js
Stars: ✭ 140 (-4.76%)
Mutual labels:  fast
Marian Dev
Fast Neural Machine Translation in C++ - development repository
Stars: ✭ 136 (-7.48%)
Mutual labels:  fast
mosquito

GitHub Workflow Status Crystal Version GitHub

Mosquito is a generic background job runner written specifically for Crystal. Significant inspiration from my experience with the successes and failings of the Ruby gem Sidekiq.

Mosquito currently provides these features:

  • Delayed execution
  • Scheduled / Periodic execution
  • Job Storage in Redis
  • Crystal hash style ? methods for parameter getters which return nil instead of raise
  • Automatic rescheduling of failed jobs
  • Progressively increasing delay of failed jobs
  • Dead letter queue of jobs which have failed too many times
  • Rate limited jobs

Current Limitations:

  • Job failure delay, maximum retry count, and several other variables cannot be easily configured.
  • Visibility into the job queue is difficult and must be done through redis manually.

Project State

Updated 2020-10-26

Stable.

A few projects are using Mosquito in production, and it's going okay.

If you're using Mosquito, please get in touch.

Installation

Update your shard.yml to include mosquito:

dependencies:
+  mosquito:
+    github: robacarp/mosquito

Further installation instructions are available for use with Amber as well as a vanilla crystal application:

Usage

Step 1: Define a queued job

# src/jobs/puts_job.cr
class PutsJob < Mosquito::QueuedJob
  params message : String

  def perform
    puts message
  end
end

Step 2: Trigger that job

# src/<somewher>/<somefile>.cr
PutsJob.new(message: "ohai background job").enqueue

Step 3: Run your worker to process the job

# src/worker.cr

Mosquito.configure do |settings|
  settings.redis_url = ENV["REDIS_URL"]
end

Mosquito::Runner.start
crystal run src/worker.cr

Success

> crystal run src/worker.cr
2017-11-06 17:07:29 - Mosquito is buzzing...
2017-11-06 17:07:51 - Running task puts_job<...> from puts_job
2017-11-06 17:07:51 - [PutsJob] ohai background job
2017-11-06 17:07:51 - task puts_job<...> succeeded, took 0.0 seconds

More information about queued jobs in the wiki.


Periodic Jobs

Periodic jobs run according to a predefined period.

This periodic job:

class PeriodicallyPutsJob < Mosquito::PeriodicJob
  run_every 1.minute

  def perform
    emotions = %w{happy sad angry optimistic political skeptical epuhoric}
    puts "The time is now #{Time.local} and the wizard is feeling #{emotions.sample}"
  end
end

Would produce this output:

2017-11-06 17:20:13 - Mosquito is buzzing...
2017-11-06 17:20:13 - Queues: periodically_puts_job
2017-11-06 17:20:13 - Running task periodically_puts_job<...> from periodically_puts_job
2017-11-06 17:20:13 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:20:13 and the wizard is feeling skeptical
2017-11-06 17:20:13 - task periodically_puts_job<...> succeeded, took 0.0 seconds
2017-11-06 17:21:14 - Queues: periodically_puts_job
2017-11-06 17:21:14 - Running task periodically_puts_job<...> from periodically_puts_job
2017-11-06 17:21:14 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:21:14 and the wizard is feeling optimistic
2017-11-06 17:21:14 - task periodically_puts_job<...> succeeded, took 0.0 seconds
2017-11-06 17:22:15 - Queues: periodically_puts_job
2017-11-06 17:22:15 - Running task periodically_puts_job<...> from periodically_puts_job
2017-11-06 17:22:15 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:22:15 and the wizard is feeling political
2017-11-06 17:22:15 - task periodically_puts_job<...> succeeded, took 0.0 seconds

More information: periodic jobs on the wiki

Throttling Jobs

Jobs can be throttled to limit the number of messages that get executed within a given period of time. For example, if 10 messages were enqueued for ThrottledJob at one time; 5 would be executed immediately, then pause for a minute, then execute the last 5.

class ThrottledJob < Mosquito::QueuedJob
  params message : String
  throttle limit: 5, period: 60

  def perform
    puts message
  end
end

Connecting to Redis

Mosquito uses Redis to schedule jobs and store metadata about those jobs. Conventionally, redis connections are configured by an environment variable. To pass that configuration to Mosqito,

Mosquito.configure do |settings|
  settings.redis_url = ENV["REDIS_URL"]
end

Contributing

Contributions are welcome. Please fork the repository, commit changes on a branch, and then open a pull request.

Testing

This repository uses minitest for testing. As a result, crystal spec doesn't do anything helpful. Do this instead:

make test

In lieu of crystal spec bells and whistles, Minitest provides a nice alternative to running one test at a time instead of the whole suite.

Contributors

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].