sidekiq-tip 0.0.2 → 0.0.3

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: 2d7eaf211c19a06b21a2a28fd63f4cd92e54dbb2
4
- data.tar.gz: 9efc42c5401fbc6a331462fdea86aca532a4ac96
3
+ metadata.gz: fc90706a7ecf0f554b92712bf300101323b7e2c4
4
+ data.tar.gz: ce89342595d8da9754d2a4ad6231c83f9c7ae7a4
5
5
  SHA512:
6
- metadata.gz: d6ad3d2baa62a7efd5a68eb82650d825c792420f3e36a7bb5a9340b5a2e666585619680a87d814477fe3e405f6b9880e6988c992d5f05855b38a18543c9434d9
7
- data.tar.gz: c381869606e891e85bbd3704827f85980fee6ba26719d53249fb2ee6b4407447103d03f3f9cb4ccebb39895b4e1b2e8702654da53352c9b01a3eb491e0d699f5
6
+ metadata.gz: 50678c8055977b8b6a52e513f1eb96d1918a12c1742175342b6352fb0416ab35e99b51ae6214381e522dc7a780178f34f754010967de140f1c5c88cbc37fca09
7
+ data.tar.gz: 722325ada980b33a69050756d539ae80f3ae2feb06246015cc5e4b823242ff76343ec01c1047b9326f2e4d254ebe94e5bb1a031a43d85665fe6090282486ee2e
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ #cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.2.2
6
+ - 2.2.3
7
+ - ruby-head
8
+ script: rake
data/Gemfile CHANGED
@@ -4,8 +4,11 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :developmnt, :test do
7
+ gem 'simplecov'
8
+ gem 'coveralls', require: false
7
9
  gem 'pry'
8
10
  gem 'sidekiq', git: 'https://github.com/mperham/sidekiq.git'
11
+ gem 'celluloid'
9
12
  gem 'minitest'
10
13
  gem 'wrong'
11
14
  gem 'mocha'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Sidekiq::Tip
2
2
 
3
+ [![Build Status](https://travis-ci.org/zzet/sidekiq-tip.svg)](https://travis-ci.org/zzet/sidekiq-tip) [![Coverage Status](https://coveralls.io/repos/zzet/sidekiq-tip/badge.svg?branch=master&service=github)](https://coveralls.io/github/zzet/sidekiq-tip?branch=master)
4
+
3
5
  Perform sidekiq jobs in time interval
4
6
 
5
7
  ## Installation
@@ -13,11 +13,19 @@ module Sidekiq
13
13
  if appropriate_time_interval?
14
14
  yield
15
15
  else
16
- worker.class.perform_in(wait_time, msg)
16
+ reenqueue(msg, queue)
17
17
  end
18
18
  end
19
19
 
20
- #private
20
+ private
21
+
22
+ def reenqueue(msg, queue)
23
+ payload = Sidekiq.dump_json(msg)
24
+
25
+ Sidekiq.redis do |conn|
26
+ conn.zadd(queue, next_start_time.to_f.to_s, payload)
27
+ end
28
+ end
21
29
 
22
30
  def fetch_times(msg)
23
31
  @start_at = msg.fetch('start_at', @start_at)
@@ -42,8 +50,8 @@ module Sidekiq
42
50
  Time.now.utc
43
51
  end
44
52
 
45
- def wait_time
46
- (start_time + 86400) - current_time
53
+ def next_start_time
54
+ start_time + 86400
47
55
  end
48
56
  end
49
57
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Tip
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -2,6 +2,16 @@ require 'test_helper'
2
2
  require 'pry'
3
3
 
4
4
  class MiddlawareTest < Minitest::Test
5
+ def setup
6
+ redis = MockRedis.new
7
+ client = Object.new
8
+
9
+ redis.stubs(:client).returns(client)
10
+ client.stubs(:location).returns('MockRedis')
11
+
12
+ Sidekiq::RedisConnection.stubs(:create).returns(ConnectionPool.new({}) { redis })
13
+ end
14
+
5
15
  def test_job_in_interval
6
16
  t = Time.utc(2008, 9, 1, 1, 0, 0)
7
17
  Timecop.travel(t)
@@ -22,8 +32,18 @@ class MiddlawareTest < Minitest::Test
22
32
  assert { SomeIvarJob.jobs.size == 0 }
23
33
  SomeIvarJob.perform_async
24
34
  assert { SomeIvarJob.jobs.size == 1 }
25
- SomeJob.drain
26
- assert { SomeIvarJob.jobs.size == 1 }
35
+ jobs = []
36
+ while job = SomeIvarJob.jobs.shift do
37
+ jobs << job
38
+ end
39
+ while job = jobs.shift do
40
+ SomeIvarJob.process_job(job)
41
+ end
42
+ ej = 0
43
+ Sidekiq.redis do |conn|
44
+ ej += conn.zrange("default", 0, -1).size
45
+ end
46
+ assert { ej == 1 }
27
47
 
28
48
  Timecop.return
29
49
  end
@@ -1,28 +1,28 @@
1
- # require 'simplecov'
2
- # SimpleCov.start
1
+ require 'simplecov'
2
+ SimpleCov.start
3
3
 
4
- # require 'coveralls'
5
- # Coveralls.wear!
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
6
 
7
7
  require 'minitest/autorun'
8
8
  require 'minitest/pride'
9
9
  require 'minitest/autorun'
10
10
  require 'timecop'
11
11
  require 'wrong'
12
+ require 'mocha/setup'
13
+ require 'mock_redis'
12
14
 
15
+ require 'sidekiq'
13
16
  require 'celluloid/current'
14
17
  require 'celluloid/test'
15
18
  Celluloid.boot
16
19
 
17
- require 'sidekiq'
18
20
  require 'sidekiq/cli'
19
21
  require 'sidekiq/processor'
20
22
  require 'sidekiq/util'
21
23
 
22
- require 'sidekiq/testing'
23
- Sidekiq::Testing.fake!
24
-
25
24
  require 'sidekiq/tip'
25
+ require 'sidekiq/testing'
26
26
 
27
27
  Sidekiq::Testing.server_middleware do |chain|
28
28
  chain.add Sidekiq::Tip::Server::Middleware
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-tip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kumanyaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -47,6 +47,7 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - .gitignore
50
+ - .travis.yml
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md