Code Monkey home page Code Monkey logo

zhong's Introduction

Zhong Build Status Code Climate Gem Version

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.

🍊 Battle-tested at Instacart

Installation

Add this line to your application’s Gemfile:

gem 'zhong'

Usage

Zhong schedule

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

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 < 0.5 }) do
      puts "something happened on wednesday, maybe"
    end
  end

  # note: callbacks that explicitly false will cause event to not run
  on(:before_tick) do
    puts "ding"
    true
  end

  on(:after_tick) do
    puts "dong"
  end

  on(:before_run) do |job, time|
    puts "running #{job}"
    true # can conditionally run a specific job
  end

  on(:after_run) do |job, time, ran|
    puts "#{job} ran?: #{ran}"
  end

  on(:before_disable) do |job|
    puts "#{job} is going to be disabled"
  end

  on(:after_disable) do |job|
    puts "#{job} disabled"
  end

  on(:before_enable) do |job|
    puts "#{job} is going to be enabled"
  end

  on(:after_enable) do |job|
    puts "#{job} enabled"
  end

  error_handler do |e, job|
    puts "dang, #{job} messed up: #{e}"
  end
end

This file only describes what should be the schedule. Nothing will be executed until we actually run

Zhong.start

after describing the Zhong schedule.

Zhong cron process

You can run the cron process that will execute your code from the definitions in the zhong.rb file by running:

zhong zhong.rb

Web UI

Zhong comes with a web application that can display jobs, their last run and enable/disable them.

This is a Sinatra application that requires at least v2.0.0. You can add to your Gemfile

gem 'sinatra', "~>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:

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

Add the following to your config/routes.rb:

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:

zhong's People

Contributors

amalrik avatar brianstorti avatar gmccreight avatar madwire avatar mlarraz avatar nickelser avatar sherin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

zhong's Issues

Mention architecture in detail

The idea sounds great, but more in-depth technical details would help.

  • Where to put the directives file?
  • Is this a separate process / daemon or can it run as a thread within a Rails server / worker?
  • If process, how are we supposed to run it? nohup bundle exec bin/zhong?
  • Are we supposed to run this process on a single server? (e.g. database master)
  • How are we supposed to monitor this process? PID or MATCHING directive with Monit?

All these details have operational implications, so the more information the better I think.

Scheduled jobs at specific times while system is down

Say I have a job scheduled to run at 3 am each night. And for whatever reason, there's not a running Ruby process at exactly 3 am -- say it stops at 2:59 and resumes at 3:01.

Does zhong provide a way to automatically run that 3 am job if that scenario were to happen?

zhong/web depends on sinatra/base, conflicts on rack with rails

The README provides an example of modifying rails' router to mount a Zhong UI.

However, following the instructions gives a dependency error because zhong/web requires sinatra/base.

The naive user (me) adds sinatra-base to their Gemfile, at which point bundler complains that sinatra-base (1.4.0) and rails (5.1.5) have conflicting rack version requirements.

In fact, the user needs to add sinatra to their Gemfile, not sinatra-base. Probably worth clarifying in the README.

Confuse at semantics

What this means in zhong: every 1.minute, 'foobar', at: '**:20'

For me it's means that I want to run it each minute in whatever hour, but only when it's 20 minutes, but I see it running every minute in the console:

web_1            | 20:34:19 web.1  | 2017-11-10 20:34:19 +0000: running: foobar
web_1            | 20:34:19 web.1  | "hey joe!!!"
web_1            | 20:35:19 web.1  | 2017-11-10 20:35:19 +0000: running: foobar
web_1            | 20:35:19 web.1  | "hey joe!!!"

Suddenly it stopped running every 1 minute and I see this on '/zhong':

screenshot from 2017-11-10 18-39-50

Would love to get an explanation about what is going on.

Issue with Rails 7.0.1

Testing an upgrade one of our app to Rails 7.0.1
We noticed a crash when starting zhong process (see below for stack trace)

This seems related to this issue on Rails.

I've tested manually to add a

require "active_support" in zhong.rb and it seems to work, but I'm not sure it's the way to go.

bundle exec zhong zhong.rb
You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
/Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/xml_mini.rb:184:in `current_thread_backend': uninitialized constant ActiveSupport::XmlMini::IsolatedExecutionState (NameError)
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/xml_mini.rb:103:in `backend='
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/xml_mini.rb:201:in `<module:ActiveSupport>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/xml_mini.rb:11:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/array/conversions.rb:3:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/array/conversions.rb:3:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/duration.rb:3:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/duration.rb:3:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/time/calculations.rb:3:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/time/calculations.rb:3:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/time.rb:4:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/core_ext/time.rb:4:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/time.rb:12:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/activesupport-7.0.1/lib/active_support/time.rb:12:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/zhong-0.3.0/lib/zhong.rb:7:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/zhong-0.3.0/lib/zhong.rb:7:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/zhong-0.3.0/bin/zhong:5:in `require'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/gems/zhong-0.3.0/bin/zhong:5:in `<top (required)>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/bin/zhong:23:in `load'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/bin/zhong:23:in `<main>'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/bin/ruby_executable_hooks:22:in `eval'
	from /Users/davidbourguignon/.rvm/gems/ruby-3.0.1@drivy-rangers/bin/ruby_executable_hooks:22:in `<main>'

Specifying multiple run times did not work

Using version 0.2.4 of the gem, I had this configuration:

every 1.day, 'call Foo', at: ['05:00', '08:00', '11:00'] do
  Foo.run( )            
end  

Foo.run( ) was only called at 5:00 am.

Do I need to change "every 1.day". to "every 1.hour" ?
Or is there a bug when using multiple times?

DelayedJob support

How hard would it be to configure the background job framework? For example, would it be terribly difficult to support DelayedJob?

Best way to run Rails classes / jobs

I love the idea of this gem.
In my config/initializers/zhong.rb I did:

Zhong.schedule do
  every 5.seconds, 'MyJob' do
    MyJob.perform_later
  end
end

However when I run zhong I get MyJob failed: uninitialized constant MyJob . MyJob is located in app/jobs/...

I can do hacky things to load but has anyone tried this and hopefully come up w a better solution? What would be the best way to autoload Rails classes?

cannot load such file -- sinatra/base (LoadError)

Once I add the zhong stuff to my routes file, my application breaks. Any insight?

routes.rb

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

  require 'sidekiq/web'
  mount Sidekiq::Web => '/sidekiq'

  require 'zhong/web'
  mount Zhong::Web => "/zhong"

  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root to: "admin/desks#index"
end
➜  ZD-DataCollector git:(zhong) ✗ rails s
=> Booting Puma
=> Rails 5.0.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Exiting
/Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require': cannot load such file -- sinatra/base (LoadError)
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/zhong-0.2.2/lib/zhong/web.rb:3:in `<top (required)>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `block in require'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:293:in `require'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config/routes.rb:8:in `block in <top (required)>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:371:in `draw'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config/routes.rb:1:in `<top (required)>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `block in load'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/activesupport-5.0.2/lib/active_support/file_update_checker.rb:77:in `execute'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application/finisher.rb:119:in `block in <module:Finisher>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `instance_exec'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `run'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
	from /Users/edahl/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/initializable.rb:54:in `run_initializers'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/application.rb:352:in `initialize!'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config/environment.rb:5:in `<top (required)>'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config.ru:3:in `require_relative'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config.ru:3:in `block in <main>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config.ru:in `new'
	from /Users/edahl/Documents/ruby/rails/ZD-DataCollector/config.ru:in `<main>'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/server.rb:59:in `app'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/server.rb:124:in `log_to_stdout'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/server.rb:77:in `start'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:90:in `block in server'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /Users/edahl/.rvm/gems/ruby-2.3.1@ZD-DataCollector/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'```

Clear last run if run time is changed

From @gmccreight:

Hey Nick,

I'm not sure how big of a deal this is, but if you define:

every 1.day, 'something at a particular time', at: '16:15' do
  Rails.logger.info "something at a particular time in process #{Process.pid}"
end

then, later on you change that to

every 1.day, 'something at a particular time', at: '18:15' do
  Rails.logger.info "something at a particular time in process #{Process.pid}"
end

it doesn't run at 18:15.

We will need to store the desired run time, and then expire the last run if the desired run time in storage does not match the desired run time in code

Incomplete documentation.

The README.md to this project suggests that all you have to do is set up Redis, evaluate a Zhong.schedule call, and boom! the job happens as specified. But there is a missing step.

For example, I ran the following in a Rails console running Instacart's own catalog app, which uses Zhong in production. If Zhong "just works" with no configuration whatsoever, evaluating the following should result in a string being printed to the terminal every second:

Zhong.schedule do
  every 1.seconds, 'This should do something' do
    puts 'Hello!'
  end
end

Instead of seeing anything printed to STDOUT, that expression just returns some object and does nothing else.

Zhong does absolutely nothing until the following is evaluated from somewhere:

Zhong.start

There is a bin/zhong script included with this Gem that does almost nothing but this.

Zhong process is stucked

zhong.rb: https://gist.github.com/lefty313/ac57df1dfd97133c9672c8f9f0e77540

Most of my zhong jobs are spawning sidekiq background process, it works fine since months

screen shot 2017-04-11 at 13 52 38

as you see single job is schedule once per minute

recently I added following non sidekiq job to my zhong configuration

    every 15.seconds, "check access matches" do
      min5   = $redis.zcount("matches:accessed", 5.minutes.ago.to_i, "+inf")
      min25  = $redis.zcount("matches:accessed", 25.minutes.ago.to_i, "+inf")
      hour1  = $redis.zcount("matches:accessed", 1.hour.ago.to_i, "+inf")
      hour24 = $redis.zcount("matches:accessed", 24.hour.ago.to_i, "+inf")
      week   = $redis.zcount("matches:accessed", 7.days.ago.to_i, "+inf")
      total  = $redis.zcount("matches:accessed", "-inf", "+inf")

      NewRelic::Agent.record_metric("Database/MatchAccess/Last5Min", min5)
      NewRelic::Agent.record_metric("Database/MatchAccess/Last25Min", min25)
      NewRelic::Agent.record_metric("Database/MatchAccess/LastHour", hour1)
      NewRelic::Agent.record_metric("Database/MatchAccess/LastDay", hour24)
      NewRelic::Agent.record_metric("Database/MatchAccess/LastWeek", week)
      NewRelic::Agent.record_metric("Database/MatchAccess/Alltime", total)
    end

screen shot 2017-04-11 at 13 51 55

screen shot 2017-04-11 at 13 58 58

as you see it's not reporting at time to time. I can fix it by calling

$redis.del($redis.keys("zhong*"))

but than it will lock after few minutes again. During lock phase zhong is still working fine for other jobs.

Am I doing something wrong here ?

ps: I have autoscalling policy on my production server so one of my servers could be killed when zhong is working. Keep in mind that zhong is running on every single instance and there is always at least one

Zhong process dies without explanation on Heroku

We have been running Zhong for months; occasionally, all of a sudden the process just stops without warning, no memory or dyno load issues, exceptions or anything.

We have added this to try to get more information. Any other suggestions, has anyone else seen this behavior?

  on(:before_run) do |job, time|
    puts "starting: #{job}, lock_key: #{job.lock_key}"
  end

  on(:after_run) do |job, time, ran|
    puts "finished: #{job} ran: #{ran}, lock_key: #{job.lock_key} "
  end

Notice in the logs we see starting/finishing then just heroku samples

image

Copied code

Oops

Looks like you lifted a significant amount of LGPL code from Sidekiq. You will need to rewrite that code or relicense as LGPL.

gemspec line #19

You only have 1 real executable. The setup and console files in your bin directory are not important and should not be identified in your gemspec as globally executable.

unable to run due to client error: Suo::LockClientError

Hello Nick,

I have this error "unable to run due to client error: Suo::LockClientError" when trying to run zhong on our staging server (redis is located on different instance). Locally everything works fine.
Could it be some permission/configuration missing?

Thank you,
Alex

production ready?

Hi thanks for the gem.
I want to use zhong in my company for a rails project already in production.
I see the gem is still on 0.2.1, is it stable enough to use in production?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.