Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Z

zhong

> 数据库
Open source

Reliable, distributed cron.

302 stars0 likes1 views
WebsiteGitHub

About

Reliable, distributed cron.

Zhong

Useful, reliable distributed cron. Tired of your cron-like scheduler running key jobs twice? Would you like to be able to run your cron server on multiple machines and have it "just work"? Have we got the gem for you.

Zhong uses Redis to acquire exclusive locks on jobs, as well as recording when they last ran. This means that you can rest easy at night, knowing that your customers are getting their monthly Goat Fancy magazine subscriptions and you are rolling around in your piles of money without a care in the world.

:tangerine: Battle-tested at Instacart

Installation

Add this line to your application’s Gemfile:

ruby
gem 'zhong'

Usage

Zhong schedule

Create a definition file, let's call it zhong.rb:

ruby
Zhong.redis = Redis.new(url: ENV["ZHONG_REDIS_URL"])

Zhong.schedule do
  category "stuff" do
    every 5.seconds, "foo" do
      puts "foo"
    end

    every(1.minute, "running biz at 26th and 27th minute", at: ["**:26", "**:27"]) { puts "biz" }
    every(1.week, "running baz on mon and wed", at: ["mon 22:45", "wed 23:13"]) { puts "baz" }
    every(10.seconds, "boom every 10 seconds") { raise "fail" }
  end

  category "clutter" do
    every(1.second, "compute", if: -> (t) { t.wday == 3 && rand 2.0"

It can be protected by HTTP basic authentication by setting the following environment variables:

  • ZHONG_WEB_USERNAME: the username
  • ZHONG_WEB_PASSWORD: the password

You'll need to load the Zhong schedule to be able to see jobs in the web UI, typically by requiring your zhong.rb definition file.

Rails

Load the Zhong schedule by creating an initializer at config/initializers/zhong.rb, with the following content:

ruby
require "#{Rails.root}/zhong.rb"

Add the following to your config/routes.rb:

ruby
require 'zhong/web'

Rails.application.routes.draw do
  # Other routes here...

  mount Zhong::Web, at: "/zhong"
end

History

View the changelog.

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

Issues· 9 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubycrondistributed-cronlocksmemcached

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库