sidekiq-cron 0.6.3 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +145 -0
  3. data/Gemfile +3 -29
  4. data/README.md +175 -121
  5. data/Rakefile +3 -42
  6. data/lib/sidekiq/cron/job.rb +273 -144
  7. data/lib/sidekiq/cron/launcher.rb +39 -43
  8. data/lib/sidekiq/cron/locales/de.yml +2 -2
  9. data/lib/sidekiq/cron/locales/en.yml +6 -2
  10. data/lib/sidekiq/cron/locales/it.yml +23 -0
  11. data/lib/sidekiq/cron/locales/ja.yml +18 -0
  12. data/lib/sidekiq/cron/locales/pt.yml +22 -0
  13. data/lib/sidekiq/cron/locales/ru.yml +2 -2
  14. data/lib/sidekiq/cron/locales/zh-CN.yml +19 -0
  15. data/lib/sidekiq/cron/poller.rb +22 -12
  16. data/lib/sidekiq/cron/schedule_loader.rb +22 -0
  17. data/lib/sidekiq/cron/support.rb +8 -1
  18. data/lib/sidekiq/cron/version.rb +7 -0
  19. data/lib/sidekiq/cron/views/cron.erb +38 -28
  20. data/lib/sidekiq/cron/views/cron_show.erb +88 -0
  21. data/lib/sidekiq/cron/web.rb +1 -7
  22. data/lib/sidekiq/cron/web_extension.rb +19 -15
  23. data/lib/sidekiq/cron.rb +1 -0
  24. data/lib/sidekiq/options.rb +25 -0
  25. data/sidekiq-cron.gemspec +23 -108
  26. data/test/integration/performance_test.rb +13 -19
  27. data/test/models/person.rb +21 -0
  28. data/test/test_helper.rb +37 -38
  29. data/test/unit/fixtures/schedule_array.yml +13 -0
  30. data/test/unit/fixtures/schedule_erb.yml +6 -0
  31. data/test/unit/fixtures/schedule_hash.yml +12 -0
  32. data/test/unit/fixtures/schedule_string.yml +1 -0
  33. data/test/unit/job_test.rb +450 -35
  34. data/test/unit/launcher_test.rb +33 -0
  35. data/test/unit/poller_test.rb +28 -37
  36. data/test/unit/schedule_loader_test.rb +58 -0
  37. data/test/unit/web_extension_test.rb +59 -41
  38. metadata +72 -191
  39. data/.document +0 -5
  40. data/.travis.yml +0 -19
  41. data/Changes.md +0 -50
  42. data/Dockerfile +0 -32
  43. data/VERSION +0 -1
  44. data/config.ru +0 -14
  45. data/docker-compose.yml +0 -21
  46. data/examples/web-cron-ui.png +0 -0
  47. data/lib/sidekiq/cron/views/cron.slim +0 -69
@@ -0,0 +1,25 @@
1
+ require 'sidekiq'
2
+
3
+ module Sidekiq
4
+ module Options
5
+ def self.[](key)
6
+ options_field ? Sidekiq.public_send(options_field)[key] : Sidekiq[key]
7
+ end
8
+
9
+ def self.[]=(key, value)
10
+ options_field ? Sidekiq.public_send(options_field)[key] = value : Sidekiq[key] = value
11
+ end
12
+
13
+ def self.options_field
14
+ return @options_field unless @options_field.nil?
15
+ sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
16
+ @options_field = if sidekiq_version >= Gem::Version.new('7.0')
17
+ :default_configuration
18
+ elsif sidekiq_version >= Gem::Version.new('6.5')
19
+ false
20
+ else
21
+ :options
22
+ end
23
+ end
24
+ end
25
+ end
data/sidekiq-cron.gemspec CHANGED
@@ -1,125 +1,40 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: sidekiq-cron 0.6.3 ruby lib
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/sidekiq/cron/version'
6
4
 
7
5
  Gem::Specification.new do |s|
8
6
  s.name = "sidekiq-cron"
9
- s.version = "0.6.3"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
7
+ s.version = Sidekiq::Cron::VERSION
8
+ s.summary = "Scheduler/Cron for Sidekiq jobs"
9
+ s.description = "Enables to set jobs to be run in specified time (using CRON notation or natural language)"
10
+ s.homepage = "https://github.com/sidekiq-cron/sidekiq-cron"
13
11
  s.authors = ["Ondrej Bartas"]
14
- s.date = "2017-06-20"
15
- s.description = "Enables to set jobs to be run in specified time (using CRON notation)"
16
12
  s.email = "ondrej@bartas.cz"
13
+ s.licenses = ["MIT"]
17
14
  s.extra_rdoc_files = [
18
15
  "LICENSE.txt",
19
16
  "README.md"
20
17
  ]
21
- s.files = [
22
- ".document",
23
- ".travis.yml",
24
- "Changes.md",
25
- "Dockerfile",
18
+ s.files = Dir.glob('lib/**/*') + Dir.glob('test/**/*') + [
19
+ "CHANGELOG.md",
26
20
  "Gemfile",
27
21
  "LICENSE.txt",
28
- "README.md",
29
22
  "Rakefile",
30
- "VERSION",
31
- "config.ru",
32
- "docker-compose.yml",
33
- "examples/web-cron-ui.png",
34
- "lib/sidekiq-cron.rb",
35
- "lib/sidekiq/cron.rb",
36
- "lib/sidekiq/cron/job.rb",
37
- "lib/sidekiq/cron/launcher.rb",
38
- "lib/sidekiq/cron/locales/de.yml",
39
- "lib/sidekiq/cron/locales/en.yml",
40
- "lib/sidekiq/cron/locales/ru.yml",
41
- "lib/sidekiq/cron/poller.rb",
42
- "lib/sidekiq/cron/support.rb",
43
- "lib/sidekiq/cron/views/cron.erb",
44
- "lib/sidekiq/cron/views/cron.slim",
45
- "lib/sidekiq/cron/web.rb",
46
- "lib/sidekiq/cron/web_extension.rb",
23
+ "README.md",
47
24
  "sidekiq-cron.gemspec",
48
- "test/integration/performance_test.rb",
49
- "test/test_helper.rb",
50
- "test/unit/job_test.rb",
51
- "test/unit/poller_test.rb",
52
- "test/unit/web_extension_test.rb"
53
25
  ]
54
- s.homepage = "http://github.com/ondrejbartas/sidekiq-cron"
55
- s.licenses = ["MIT"]
56
- s.rubygems_version = "2.5.1"
57
- s.summary = "Sidekiq Cron helps to add repeated scheduled jobs"
58
26
 
59
- if s.respond_to? :specification_version then
60
- s.specification_version = 4
27
+ s.required_ruby_version = ">= 2.7"
61
28
 
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<sidekiq>, [">= 4.2.1"])
64
- s.add_runtime_dependency(%q<rufus-scheduler>, [">= 3.3.0"])
65
- s.add_development_dependency(%q<bundler>, [">= 0"])
66
- s.add_development_dependency(%q<simplecov>, [">= 0"])
67
- s.add_development_dependency(%q<redis-namespace>, [">= 1.5.2"])
68
- s.add_development_dependency(%q<shoulda-context>, [">= 0"])
69
- s.add_development_dependency(%q<rack>, [">= 0"])
70
- s.add_development_dependency(%q<rack-test>, [">= 0"])
71
- s.add_development_dependency(%q<jeweler>, [">= 0"])
72
- s.add_development_dependency(%q<minitest>, [">= 0"])
73
- s.add_development_dependency(%q<test-unit>, [">= 0"])
74
- s.add_development_dependency(%q<sdoc>, [">= 0"])
75
- s.add_development_dependency(%q<slim>, [">= 0"])
76
- s.add_development_dependency(%q<sinatra>, [">= 0"])
77
- s.add_development_dependency(%q<mocha>, [">= 0"])
78
- s.add_development_dependency(%q<coveralls>, [">= 0"])
79
- s.add_development_dependency(%q<shotgun>, [">= 0"])
80
- s.add_development_dependency(%q<guard>, [">= 0"])
81
- s.add_development_dependency(%q<guard-minitest>, [">= 0"])
82
- else
83
- s.add_dependency(%q<sidekiq>, [">= 4.2.1"])
84
- s.add_dependency(%q<rufus-scheduler>, [">= 3.3.0"])
85
- s.add_dependency(%q<bundler>, [">= 0"])
86
- s.add_dependency(%q<simplecov>, [">= 0"])
87
- s.add_dependency(%q<redis-namespace>, [">= 1.5.2"])
88
- s.add_dependency(%q<shoulda-context>, [">= 0"])
89
- s.add_dependency(%q<rack>, [">= 0"])
90
- s.add_dependency(%q<rack-test>, [">= 0"])
91
- s.add_dependency(%q<jeweler>, [">= 0"])
92
- s.add_dependency(%q<minitest>, [">= 0"])
93
- s.add_dependency(%q<test-unit>, [">= 0"])
94
- s.add_dependency(%q<sdoc>, [">= 0"])
95
- s.add_dependency(%q<slim>, [">= 0"])
96
- s.add_dependency(%q<sinatra>, [">= 0"])
97
- s.add_dependency(%q<mocha>, [">= 0"])
98
- s.add_dependency(%q<coveralls>, [">= 0"])
99
- s.add_dependency(%q<shotgun>, [">= 0"])
100
- s.add_dependency(%q<guard>, [">= 0"])
101
- s.add_dependency(%q<guard-minitest>, [">= 0"])
102
- end
103
- else
104
- s.add_dependency(%q<sidekiq>, [">= 4.2.1"])
105
- s.add_dependency(%q<rufus-scheduler>, [">= 3.3.0"])
106
- s.add_dependency(%q<bundler>, [">= 0"])
107
- s.add_dependency(%q<simplecov>, [">= 0"])
108
- s.add_dependency(%q<redis-namespace>, [">= 1.5.2"])
109
- s.add_dependency(%q<shoulda-context>, [">= 0"])
110
- s.add_dependency(%q<rack>, [">= 0"])
111
- s.add_dependency(%q<rack-test>, [">= 0"])
112
- s.add_dependency(%q<jeweler>, [">= 0"])
113
- s.add_dependency(%q<minitest>, [">= 0"])
114
- s.add_dependency(%q<test-unit>, [">= 0"])
115
- s.add_dependency(%q<sdoc>, [">= 0"])
116
- s.add_dependency(%q<slim>, [">= 0"])
117
- s.add_dependency(%q<sinatra>, [">= 0"])
118
- s.add_dependency(%q<mocha>, [">= 0"])
119
- s.add_dependency(%q<coveralls>, [">= 0"])
120
- s.add_dependency(%q<shotgun>, [">= 0"])
121
- s.add_dependency(%q<guard>, [">= 0"])
122
- s.add_dependency(%q<guard-minitest>, [">= 0"])
123
- end
124
- end
29
+ s.add_dependency("fugit", "~> 1.8")
30
+ s.add_dependency("sidekiq", ">= 6")
31
+ s.add_dependency("globalid", ">= 1.0.1")
125
32
 
33
+ s.add_development_dependency("minitest", "~> 5.15")
34
+ s.add_development_dependency("mocha", "~> 1.14")
35
+ s.add_development_dependency("rack", "~> 2.2")
36
+ s.add_development_dependency("rack-test", "~> 1.1")
37
+ s.add_development_dependency("rake", "~> 13.0")
38
+ s.add_development_dependency("simplecov", "~> 0.21")
39
+ s.add_development_dependency("simplecov-cobertura", "~> 2.1")
40
+ end
@@ -1,39 +1,33 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require './test/test_helper'
3
2
  require 'benchmark'
4
3
 
5
- describe 'Perfromance Poller' do
6
- X = 10000
4
+ describe 'Performance Poller' do
5
+ JOBS_NUMBER = 10_000
6
+ MAX_SECONDS = 60
7
+
7
8
  before do
8
- Sidekiq.redis = REDIS
9
+ # Clear all previous saved data from Redis.
9
10
  Sidekiq.redis do |conn|
10
11
  conn.flushdb
11
12
  end
12
13
 
13
- #clear all previous saved data from redis
14
- Sidekiq.redis do |conn|
15
- conn.keys("cron_job*").each do |key|
16
- conn.del(key)
17
- end
18
- end
19
-
20
14
  args = {
21
15
  queue: "default",
22
16
  cron: "*/2 * * * *",
23
17
  klass: "CronTestClass"
24
18
  }
25
19
 
26
- X.times do |i|
20
+ JOBS_NUMBER.times do |i|
27
21
  Sidekiq::Cron::Job.create(args.merge(name: "Test#{i}"))
28
22
  end
29
23
 
30
- @poller = Sidekiq::Cron::Poller.new
31
- now = Time.now.utc
32
- enqueued_time = Time.new(now.year, now.month, now.day, now.hour + 1, 10, 5)
24
+ @poller = Sidekiq::Cron::Poller.new(Sidekiq.const_defined?(:Config) ? Sidekiq::Config.new : {})
25
+ now = Time.now.utc + 3600
26
+ enqueued_time = Time.new(now.year, now.month, now.day, now.hour, 10, 5)
33
27
  Time.stubs(:now).returns(enqueued_time)
34
28
  end
35
29
 
36
- it 'should enqueue 10000 jobs in less than 30s' do
30
+ it "should enqueue #{JOBS_NUMBER} jobs in less than #{MAX_SECONDS}s" do
37
31
  Sidekiq.redis do |conn|
38
32
  assert_equal 0, conn.llen("queue:default"), 'Queue should be empty'
39
33
  end
@@ -43,10 +37,10 @@ describe 'Perfromance Poller' do
43
37
  }
44
38
 
45
39
  Sidekiq.redis do |conn|
46
- assert_equal X, conn.llen("queue:default"), 'Queue should be full'
40
+ assert_equal JOBS_NUMBER, conn.llen("queue:default"), 'Queue should be full'
47
41
  end
48
42
 
49
- puts "Perfomance test finished in #{bench.real}"
50
- assert_operator 30, :>, bench.real
43
+ puts "Performance test finished in #{bench.real}"
44
+ assert_operator bench.real, :<, MAX_SECONDS
51
45
  end
52
46
  end
@@ -0,0 +1,21 @@
1
+ class Person
2
+ include GlobalID::Identification
3
+
4
+ attr_reader :id
5
+
6
+ def self.find(id)
7
+ new(id)
8
+ end
9
+
10
+ def initialize(id)
11
+ @id = id
12
+ end
13
+
14
+ def to_global_id(options = {})
15
+ super app: "app"
16
+ end
17
+
18
+ def ==(other_person)
19
+ other_person.is_a?(Person) && id.to_s == other_person.id.to_s
20
+ end
21
+ end
data/test/test_helper.rb CHANGED
@@ -1,50 +1,38 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
1
+ $TESTING = true
2
+ ENV['RACK_ENV'] = 'test'
10
3
 
11
4
  require 'simplecov'
12
- SimpleCov.start do
13
- add_filter "/test/"
14
5
 
15
- add_group 'SidekiqCron', 'lib/'
6
+ if ENV['CI']
7
+ require 'simplecov-cobertura'
8
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
9
+ end
10
+
11
+ SimpleCov.start do
12
+ add_filter "test/"
13
+ add_group 'Sidekiq-Cron', 'lib/'
16
14
  end
17
- require 'coveralls'
18
- Coveralls.wear!
19
15
 
20
16
  require "minitest/autorun"
21
- require 'shoulda-context'
22
17
  require "rack/test"
23
- require "mocha/setup"
24
-
25
- ENV['RACK_ENV'] = 'test'
26
-
27
- #SIDEKIQ Require - need to have sidekiq running!
18
+ require 'mocha/minitest'
28
19
  require 'sidekiq'
29
- require 'sidekiq/util'
30
20
  require 'sidekiq/web'
21
+ require "sidekiq/cli"
22
+ require 'sidekiq-cron'
23
+ require 'sidekiq/cron/web'
31
24
 
32
25
  Sidekiq.logger.level = Logger::ERROR
33
-
34
- require 'sidekiq/redis_connection'
35
- redis_url = ENV['REDIS_URL'] || 'redis://0.0.0.0:6379'
36
- REDIS = Sidekiq::RedisConnection.create(:url => redis_url, :namespace => 'testy')
37
-
38
26
  Sidekiq.configure_client do |config|
39
- config.redis = { :url => redis_url, :namespace => 'testy' }
27
+ config.redis = { url: ENV['REDIS_URL'] || 'redis://0.0.0.0:6379' }
40
28
  end
41
29
 
42
-
43
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
44
- $LOAD_PATH.unshift(File.dirname(__FILE__))
45
- require 'sidekiq-cron'
46
- require 'sidekiq/cron/web'
47
- require 'pp'
30
+ # For testing symbolize args
31
+ class Hash
32
+ def symbolize_keys
33
+ transform_keys { |key| key.to_sym rescue key }
34
+ end
35
+ end
48
36
 
49
37
  class CronTestClass
50
38
  include Sidekiq::Worker
@@ -66,6 +54,13 @@ end
66
54
 
67
55
  module ActiveJob
68
56
  class Base
57
+ attr_accessor *%i[job_class provider_job_id queue_name arguments]
58
+
59
+ def initialize
60
+ yield self if block_given?
61
+ self.provider_job_id ||= SecureRandom.hex(12)
62
+ end
63
+
69
64
  def self.queue_name_prefix
70
65
  @queue_name_prefix
71
66
  end
@@ -80,12 +75,16 @@ module ActiveJob
80
75
  self
81
76
  end
82
77
 
78
+ def try(method, *args, &block)
79
+ send method, *args, &block if respond_to? method
80
+ end
81
+
83
82
  def self.perform_later(*args)
84
- {
85
- "job_class" => self.class.name,
86
- "queue_name" => @queue,
87
- "args" => [*args],
88
- }
83
+ new do |instance|
84
+ instance.job_class = self.class.name
85
+ instance.queue_name = @queue
86
+ instance.arguments = [*args]
87
+ end
89
88
  end
90
89
  end
91
90
  end
@@ -0,0 +1,13 @@
1
+ ---
2
+ -
3
+ name: "my_first_job"
4
+ cron: "*/5 * * * *"
5
+ class: "HardWorker"
6
+ queue: "hard_worker"
7
+ -
8
+ name: "second_job"
9
+ cron: "*/30 * * * *"
10
+ class: "HardWorker"
11
+ queue: "hard_worker_long"
12
+ args:
13
+ hard: "stuff"
@@ -0,0 +1,6 @@
1
+ ---
2
+ default: &default
3
+ cron: <%= "every day at 5 pm" %>
4
+ class: <%= "DailyJob" %>
5
+
6
+ daily_job: *default
@@ -0,0 +1,12 @@
1
+ ---
2
+ my_first_job:
3
+ cron: "*/5 * * * *"
4
+ class: "HardWorker"
5
+ queue: hard_worker
6
+
7
+ second_job:
8
+ cron: "*/30 * * * *"
9
+ class: "HardWorker"
10
+ queue: hard_worker_long
11
+ args:
12
+ hard: "stuff"
@@ -0,0 +1 @@
1
+ --- string