{"id":27160863,"url":"https://github.com/robacarp/mosquito","last_synced_at":"2025-04-09T00:01:41.945Z","repository":{"id":41107914,"uuid":"109764921","full_name":"mosquito-cr/mosquito","owner":"mosquito-cr","description":"A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs","archived":false,"fork":false,"pushed_at":"2024-10-29T13:45:46.000Z","size":998,"stargazers_count":226,"open_issues_count":18,"forks_count":24,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-31T06:02:15.455Z","etag":null,"topics":["background-jobs","crystal","fast","redis"],"latest_commit_sha":null,"homepage":"","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mosquito-cr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"robacarp","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null}},"created_at":"2017-11-07T00:10:26.000Z","updated_at":"2024-10-29T13:45:24.000Z","dependencies_parsed_at":"2023-12-21T07:00:49.768Z","dependency_job_id":"1b174629-c33b-408b-b68d-5807034eddbb","html_url":"https://github.com/mosquito-cr/mosquito","commit_stats":null,"previous_names":["robacarp/mosquito"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito-cr%2Fmosquito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito-cr%2Fmosquito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito-cr%2Fmosquito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mosquito-cr%2Fmosquito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mosquito-cr","download_url":"https://codeload.github.com/mosquito-cr/mosquito/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247947842,"owners_count":21023065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["background-jobs","crystal","fast","redis"],"created_at":"2025-04-09T00:01:37.631Z","updated_at":"2025-04-09T00:01:41.923Z","avatar_url":"https://github.com/mosquito-cr.png","language":"Crystal","funding_links":["https://github.com/sponsors/robacarp"],"categories":["Queues and Messaging"],"sub_categories":[],"readme":"\u003cimg src=\"logo/logotype_horizontal.svg\" alt=\"mosquito\"\u003e\n\n[![GitHub](https://img.shields.io/github/license/mosquito-cr/mosquito.svg?style=for-the-badge)](https://tldrlegal.com/license/mit-license)\n\n\u003cimg src=\"https://mosquito-cr.github.io/images/amber-mosquito-small.png\" align=\"right\"\u003e\n\nMosquito is a generic background job runner written primarily for Crystal. Significant inspiration from experience with the successes and failings many Ruby gems in this vein. Once compiled, a mosquito binary can start work in about 10 milliseconds.\n\nMosquito currently provides these features:\n\n- Delayed execution (`SendEmailJob.new(email: :welcome, address: user.email).enqueue(in: 3.minutes)`)\n- Scheduled / Periodic execution (`RunEveryHourJob.new`)\n- Job Storage in Redis\n- Automatic rescheduling of failed jobs\n- Progressively increasing delay of rescheduled failed jobs\n- Dead letter queue of jobs which have failed too many times\n- Rate limited jobs\n\nCurrent Limitations:\n- Visibility into a running job network and queue is limited. There is a working proof of concept [visualization API](https://github.com/mosquito-cr/mosquito/issues/90) and [bare-bones terminal application](https://github.com/mosquito-cr/tui-visualizer).\n\n## Project State\n\nThe Mosquito project is stable. A few folks are using Mosquito in production, and it's going well.\n\nThere are some features which would be nice to have, but what is here is both tried and tested.\n\nIf you're using Mosquito, please [get in touch](https://github.com/mosquito-cr/mosquito/discussions) on the Discussion board or [on Crystal chat](https://crystal-lang.org/community/) with any questions, feature suggestions, or feedback.\n\n## Installation\n\nUpdate your `shard.yml` to include mosquito:\n\n```diff\ndependencies:\n+  mosquito:\n+    github: mosquito-cr/mosquito\n```\n\n## Usage\n\n### Step 1: Define a queued job\n\n```crystal\n# src/jobs/puts_job.cr\nclass PutsJob \u003c Mosquito::QueuedJob\n  param message : String\n\n  def perform\n    puts message\n  end\nend\n```\n\n### Step 2: Trigger that job\n\n```crystal\n# src/\u003csomewher\u003e/\u003csomefile\u003e.cr\nPutsJob.new(message: \"ohai background job\").enqueue\n```\n\n### Step 3: Run your worker to process the job\n\n```crystal\n# src/worker.cr\n\nMosquito.configure do |settings|\n  settings.redis_url = ENV[\"REDIS_URL\"]\nend\n\nMosquito::Runner.start\n```\n\n```text\ncrystal run src/worker.cr\n```\n\n### Success\n\n```\n\u003e crystal run src/worker.cr\n2017-11-06 17:07:29 - Mosquito is buzzing...\n2017-11-06 17:07:51 - Running task puts_job\u003c...\u003e from puts_job\n2017-11-06 17:07:51 - [PutsJob] ohai background job\n2017-11-06 17:07:51 - task puts_job\u003c...\u003e succeeded, took 0.0 seconds\n```\n\n[More information about queued jobs](https://mosquito-cr.github.io/manual/index.html#queued-jobs) in the manual.\n\n------\n\n## Periodic Jobs\n\nPeriodic jobs run according to a predefined period -- once an hour, etc.\n\nThis periodic job:\n```crystal\nclass PeriodicallyPutsJob \u003c Mosquito::PeriodicJob\n  run_every 1.minute\n\n  def perform\n    emotions = %w{happy sad angry optimistic political skeptical epuhoric}\n    puts \"The time is now #{Time.local} and the wizard is feeling #{emotions.sample}\"\n  end\nend\n```\n\nWould produce this output:\n```crystal\n2017-11-06 17:20:13 - Mosquito is buzzing...\n2017-11-06 17:20:13 - Queues: periodically_puts_job\n2017-11-06 17:20:13 - Running task periodically_puts_job\u003c...\u003e from periodically_puts_job\n2017-11-06 17:20:13 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:20:13 and the wizard is feeling skeptical\n2017-11-06 17:20:13 - task periodically_puts_job\u003c...\u003e succeeded, took 0.0 seconds\n2017-11-06 17:21:14 - Queues: periodically_puts_job\n2017-11-06 17:21:14 - Running task periodically_puts_job\u003c...\u003e from periodically_puts_job\n2017-11-06 17:21:14 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:21:14 and the wizard is feeling optimistic\n2017-11-06 17:21:14 - task periodically_puts_job\u003c...\u003e succeeded, took 0.0 seconds\n2017-11-06 17:22:15 - Queues: periodically_puts_job\n2017-11-06 17:22:15 - Running task periodically_puts_job\u003c...\u003e from periodically_puts_job\n2017-11-06 17:22:15 - [PeriodicallyPutsJob] The time is now 2017-11-06 17:22:15 and the wizard is feeling political\n2017-11-06 17:22:15 - task periodically_puts_job\u003c...\u003e succeeded, took 0.0 seconds\n```\n\n[More information on periodic jobs](https://mosquito-cr.github.io/manual/index.html#periodic-jobs) in the manual.\n\n## Advanced usage\n\nFor more advanced topics, including [use with Lucky Framework](https://mosquito-cr.github.io/manual/lucky_framework.html), [throttling or rate limiting](https://mosquito-cr.github.io/manual/rate_limiting.html), check out the [full manual](https://mosquito-cr.github.io/manual).\n\n## Contributing\n\nContributions are welcome. Please fork the repository, commit changes on a branch, and then open a pull request.\n\n### Crystal Versions\n\nMosquito aims to be compatible with the latest Crystal release, and the [latest patch for all post-1.0 minor crystal versions](https://github.com/mosquito-cr/mosquito/blob/master/.github/workflows/ci.yml#L17).\n\nFor development purposes [you're encouraged to stay in sync with `.tool-versions`](https://github.com/mosquito-cr/mosquito/blob/master/.tool-versions).\n\n### Testing\n\n`crystal spec` Will run the tests, or `make test` will too.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobacarp%2Fmosquito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobacarp%2Fmosquito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobacarp%2Fmosquito/lists"}