sidekiq-cron 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcc4ae725097b1fc4a42a3c8f0b211f10dd1a046
4
- data.tar.gz: 50589e96e308bd347d29e917ee8d7c31b00d3782
3
+ metadata.gz: 873586d3842f9498012e042967394936f59ff000
4
+ data.tar.gz: 455f2a83bca498a0b0b6d37c4a9dd359170a6f28
5
5
  SHA512:
6
- metadata.gz: 46b8ae7aa71d31dd693f0a3cf5035ed5f06bbf174da2a742de270c3c9d9d2fc6428b4bc26ca4d71a0028254e4a0b0f1228483906d544f5c92a9f40b0cc3a3eef
7
- data.tar.gz: 1819f9a1eec1a60c0f1348df9a28747eedab16e4673e10dbfccd3ae62a5b82911f11a6f90dbc1962d664021579f4b723b8d6b97c028bbc9d471af495ead82a6f
6
+ metadata.gz: 6eba0a3a0270f83abb155ac4683d03aa06f30e8d801c0b242e627dc29cd04d646f1e7d91c5a45da9b1197e8dd968d09e88fa4df3161cc216e3d097e7a319c036
7
+ data.tar.gz: 7776ad92e891399343e16020e2fb7136e472614fdc7a9503910e48bffe5e1a442456cf1785bd885d1c808a24d77f8e28ea058bc6a299b51eb0f486f7b98d4f15
data/Changes.md CHANGED
@@ -1,3 +1,9 @@
1
+ v 0.4.0
2
+ -------
3
+
4
+ - enable to work with sidekiq >= 4.0.0
5
+ - fix readme
6
+
1
7
  v 0.3.1
2
8
  -------
3
9
 
data/README.md CHANGED
@@ -17,8 +17,8 @@ Works with ActiveJob (Rails 4.2+)
17
17
  Requirements
18
18
  -----------------
19
19
 
20
- - Redis 2.4 or greater is required.
21
- - Sidekiq 4 or grater is required (for Sidekiq <4 use version sidekiq-cron 0.3.1)
20
+ - Redis 2.8 or greater is required. (Redis 3.0.3 or greater is recommended for large scale use)
21
+ - Sidekiq 4 or greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
22
22
 
23
23
  Change Log
24
24
  ----------
@@ -32,7 +32,7 @@ Installation
32
32
 
33
33
  or add to your `Gemfile`
34
34
 
35
- gem "sidekiq-cron", "~> 0.3.0"
35
+ gem "sidekiq-cron", "~> 0.4.0"
36
36
 
37
37
 
38
38
  Getting Started
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -16,7 +16,10 @@ module Sidekiq
16
16
  def should_enque? time
17
17
  enqueue = false
18
18
  enqueue = Sidekiq.redis do |conn|
19
- status == "enabled" && not_enqueued_after?(time) && conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time))
19
+ status == "enabled" &&
20
+ not_past_scheduled_time?(time) &&
21
+ not_enqueued_after?(time) &&
22
+ conn.zadd(job_enqueued_key, formated_enqueue_time(time), formated_last_time(time))
20
23
  end
21
24
  enqueue
22
25
  end
@@ -433,6 +436,10 @@ module Sidekiq
433
436
  Rufus::Scheduler::CronLine.new(@cron).previous_time(now)
434
437
  end
435
438
 
439
+ def formated_enqueue_time now = Time.now
440
+ last_time(now).getutc.to_f.to_s
441
+ end
442
+
436
443
  def formated_last_time now = Time.now
437
444
  last_time(now).getutc.iso8601
438
445
  end
@@ -480,6 +487,12 @@ module Sidekiq
480
487
  end
481
488
  end
482
489
 
490
+ def not_past_scheduled_time?(current_time)
491
+ last_cron_time = Rufus::Scheduler::CronLine.new(@cron).previous_time(current_time)
492
+ return false if (current_time - last_cron_time) > 60
493
+ true
494
+ end
495
+
483
496
  # Redis key for set of all cron jobs
484
497
  def self.jobs_key
485
498
  "cron_jobs"
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sidekiq-cron 0.4.0 ruby lib
5
+ # stub: sidekiq-cron 0.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sidekiq-cron"
9
- s.version = "0.4.0"
9
+ s.version = "0.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Ondrej Bartas"]
14
- s.date = "2015-11-17"
14
+ s.date = "2015-12-20"
15
15
  s.description = "Enables to set jobs to be run in specified time (using CRON notation)"
16
16
  s.email = "ondrej@bartas.cz"
17
17
  s.extra_rdoc_files = [
@@ -132,6 +132,25 @@ describe "Cron Job" do
132
132
  end
133
133
  end
134
134
 
135
+ describe 'formatted time' do
136
+ before do
137
+ @args = {
138
+ name: "Test",
139
+ cron: "* * * * *"
140
+ }
141
+ @job = Sidekiq::Cron::Job.new(@args)
142
+ @time = Time.new(2015, 1, 2, 3, 4, 5, '+01:00')
143
+ end
144
+
145
+ it 'returns formatted_last_time' do
146
+ assert_equal '2015-01-02T02:04:00Z', @job.formated_last_time(@time)
147
+ end
148
+
149
+ it 'returns formated_enqueue_time' do
150
+ assert_equal '1420164240.0', @job.formated_enqueue_time(@time)
151
+ end
152
+ end
153
+
135
154
  describe "new with different class inputs" do
136
155
  it "be initialized by 'klass' and Class" do
137
156
  job = Sidekiq::Cron::Job.new('klass' => CronTestClass)
@@ -794,6 +813,11 @@ describe "Cron Job" do
794
813
  refute Sidekiq::Cron::Job.new(@args).should_enque? @time + 235
795
814
  end
796
815
 
816
+ it "should not enqueue jobs that are past" do
817
+ assert Sidekiq::Cron::Job.new(@args.merge(cron: "*/1 * * * *")).should_enque? @time
818
+ refute Sidekiq::Cron::Job.new(@args.merge(cron: "0 1,13 * * *")).should_enque? @time
819
+ end
820
+
797
821
  it "remove old enque times + should be enqeued" do
798
822
  job = Sidekiq::Cron::Job.new(@args)
799
823
  assert_nil job.last_enqueue_time
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondrej Bartas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq