resque_solo 0.1.0 → 0.2.0

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: dc87df1fa353f94c1d75b20c2dc6ef9f5978637b
4
- data.tar.gz: 51df2fed96c31280f6ed8fb64851529fc75fcda4
3
+ metadata.gz: 9e954b4d2492942672efaf828eda9cef99bae229
4
+ data.tar.gz: 4527347e8170f87fb2a16463eec8bda7bfaed3c6
5
5
  SHA512:
6
- metadata.gz: 927e45014a436a39aba1017cbd153d43218f3d82bee878f88f1efbc0e0d0d86e854eb03b46a626df9ad377c77b73e2e76286e7c73fb314cd9466fa8ef4e1ccf6
7
- data.tar.gz: ab499a6bb2587de31fd05a37d4092a59a79572d67e1349ff86d836066b85249be8d7505883935e187b81e25f5f2d3fa19055f4658f3e05b5a680bc45e90fde3c
6
+ metadata.gz: 0714a8209c9eddfef035591ccb049bf3d308827d015893067b2928ccf038c7b79a281ccb1f88ed60396446d7528a4270dd8ac87d9d152c9afb3887d61839157b
7
+ data.tar.gz: eadf6059eb2c9c59baefcb7d5c73d0caf11dfb911bd55514909bf2d86436f4e3609fc35f1e14a73f5f0953426f2e3a5b2785e46cd72a8470746c638924b18875
@@ -3,7 +3,7 @@ module Resque
3
3
  class << self
4
4
  # Mark an item as queued
5
5
  def create_solo(queue, klass, *args)
6
- item = {class: klass.to_s, args: args}
6
+ item = { class: klass.to_s, args: args }
7
7
  return create_without_solo(queue, klass, *args) if Resque.inline? || !ResqueSolo::Queue.is_unique?(item)
8
8
  return "EXISTED" if ResqueSolo::Queue.queued?(queue, item)
9
9
  create_return_value = false
@@ -1,11 +1,11 @@
1
1
  module Resque
2
2
  class << self
3
3
  def enqueued?(klass, *args)
4
- enqueued_in?(queue_from_class(klass), klass, *args )
4
+ enqueued_in?(queue_from_class(klass), klass, *args)
5
5
  end
6
6
 
7
7
  def enqueued_in?(queue, klass, *args)
8
- item = {class: klass.to_s, args: args}
8
+ item = { class: klass.to_s, args: args }
9
9
  return nil unless ResqueSolo::Queue.is_unique?(item)
10
10
  ResqueSolo::Queue.queued?(queue, item)
11
11
  end
@@ -1,6 +1,6 @@
1
- require 'resque'
2
- require 'resque_ext/job'
3
- require 'resque_ext/resque'
4
- require 'resque_solo/version'
5
- require 'resque_solo/queue'
6
- require 'resque_solo/unique_job'
1
+ require "resque"
2
+ require "resque_ext/job"
3
+ require "resque_ext/resque"
4
+ require "resque_solo/version"
5
+ require "resque_solo/queue"
6
+ require "resque_solo/unique_job"
@@ -53,8 +53,8 @@ module ResqueSolo
53
53
 
54
54
  redis.lrange(redis_queue, 0, -1).each do |string|
55
55
  json = Resque.decode(string)
56
- next unless json['class'] == klass
57
- next unless json['args'] == args if args.any?
56
+ next unless json["class"] == klass
57
+ next if args.any? && json["args"] != args
58
58
  ResqueSolo::Queue.mark_unqueued(queue, json)
59
59
  end
60
60
  end
@@ -64,14 +64,14 @@ module ResqueSolo
64
64
  redis.del(*keys) if keys.any?
65
65
  end
66
66
 
67
- private
67
+ private
68
68
 
69
69
  def redis
70
70
  Resque.redis
71
71
  end
72
72
 
73
73
  def item_class(item)
74
- item[:class] || item['class']
74
+ item[:class] || item["class"]
75
75
  end
76
76
 
77
77
  def const_for(item)
@@ -1,4 +1,4 @@
1
- require 'digest/md5'
1
+ require "digest/md5"
2
2
 
3
3
  module Resque
4
4
  module Plugins
@@ -31,7 +31,7 @@ module Resque
31
31
  # end
32
32
  # end
33
33
  def ttl
34
- @ttl || -1
34
+ @ttl ||= -1
35
35
  end
36
36
 
37
37
  # The default ttl of a persisting key is 0, i.e. immediately deleted.
@@ -45,7 +45,7 @@ module Resque
45
45
  # end
46
46
  # end
47
47
  def lock_after_execution_period
48
- @lock_after_execution_period || 0
48
+ @lock_after_execution_period ||= 0
49
49
  end
50
50
  end
51
51
  end
@@ -1,3 +1,3 @@
1
1
  module ResqueSolo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.25.1
19
+ version: '1.25'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.25.1
26
+ version: '1.25'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,26 +87,14 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".gitignore"
91
- - ".ruby-version"
92
- - ".travis.yml"
93
- - Gemfile
94
90
  - LICENSE.txt
95
91
  - README.md
96
- - Rakefile
97
92
  - lib/resque_ext/job.rb
98
93
  - lib/resque_ext/resque.rb
99
94
  - lib/resque_solo.rb
100
95
  - lib/resque_solo/queue.rb
101
96
  - lib/resque_solo/unique_job.rb
102
97
  - lib/resque_solo/version.rb
103
- - resque_solo.gemspec
104
- - test/fake_jobs.rb
105
- - test/job_test.rb
106
- - test/queue_test.rb
107
- - test/resque_test.rb
108
- - test/test_helper.rb
109
- - test/unique_job_test.rb
110
98
  homepage: https://github.com/neighborland/resque_solo
111
99
  licenses:
112
100
  - MIT
@@ -127,15 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
115
  version: '0'
128
116
  requirements: []
129
117
  rubyforge_project:
130
- rubygems_version: 2.2.2
118
+ rubygems_version: 2.6.2
131
119
  signing_key:
132
120
  specification_version: 4
133
121
  summary: Resque plugin to add unique jobs
134
- test_files:
135
- - test/fake_jobs.rb
136
- - test/job_test.rb
137
- - test/queue_test.rb
138
- - test/resque_test.rb
139
- - test/test_helper.rb
140
- - test/unique_job_test.rb
122
+ test_files: []
141
123
  has_rdoc:
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- .bundle
2
- .config
3
- Gemfile.lock
4
- coverage
5
- pkg
6
- tmp
@@ -1 +0,0 @@
1
- ruby-2.1.1
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1
4
- - 2.0.0
5
- - 1.9.3
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :test do
4
- unless ENV['TRAVIS']
5
- gem 'pry-byebug', platform: :mri_21
6
- end
7
- gem 'simplecov', require: false
8
- end
9
-
10
- gemspec
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
- require 'rake/testtask'
4
-
5
- desc 'Run tests'
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.pattern = 'test/**/*_test.rb'
9
- t.verbose = false
10
- end
11
-
12
- task default: :test
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'resque_solo/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "resque_solo"
8
- spec.version = ResqueSolo::VERSION
9
- spec.authors = ["Tee Parham"]
10
- spec.email = %w(tee@neighborland.com)
11
- spec.description = %q{Resque plugin to add unique jobs}
12
- spec.summary = %q{Resque plugin to add unique jobs}
13
- spec.homepage = "https://github.com/neighborland/resque_solo"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = []
18
- spec.test_files = spec.files.grep(%r{^(test|features)/})
19
- spec.require_paths = %w(lib)
20
-
21
- spec.required_ruby_version = ">= 1.9.3"
22
-
23
- spec.add_dependency "resque", "~> 1.25.1"
24
-
25
- spec.add_development_dependency "bundler", "~> 1.5"
26
- spec.add_development_dependency "fakeredis", "~> 0.4"
27
- spec.add_development_dependency "minitest", "~> 5.3"
28
- spec.add_development_dependency "rake", "~> 10.1"
29
- end
@@ -1,38 +0,0 @@
1
- class FakeJob
2
- @queue = :normal
3
- end
4
-
5
- class FakeUniqueJob
6
- include Resque::Plugins::UniqueJob
7
- @queue = :unique
8
-
9
- def self.perform(_)
10
- end
11
- end
12
-
13
- class FailingUniqueJob
14
- include Resque::Plugins::UniqueJob
15
- @queue = :unique
16
-
17
- def self.perform(_)
18
- raise "Fail"
19
- end
20
- end
21
-
22
- class UniqueJobWithTtl
23
- include Resque::Plugins::UniqueJob
24
- @queue = :unique_with_ttl
25
- @ttl = 300
26
-
27
- def self.perform(*_)
28
- end
29
- end
30
-
31
- class UniqueJobWithLock
32
- include Resque::Plugins::UniqueJob
33
- @queue = :unique_with_lock
34
- @lock_after_execution_period = 150
35
-
36
- def self.perform(*_)
37
- end
38
- end
@@ -1,107 +0,0 @@
1
- require 'test_helper'
2
-
3
- class JobTest < MiniTest::Spec
4
- before do
5
- Resque.redis.flushall
6
- end
7
-
8
- it "enqueue identical jobs once" do
9
- Resque.enqueue FakeUniqueJob, "x"
10
- Resque.enqueue FakeUniqueJob, "x"
11
- assert_equal 1, Resque.size(:unique)
12
- end
13
-
14
- it "allow the same jobs to be executed one after the other" do
15
- Resque.enqueue FakeUniqueJob, "foo"
16
- Resque.enqueue FakeUniqueJob, "foo"
17
- assert_equal 1, Resque.size(:unique)
18
- Resque.reserve(:unique)
19
- assert_equal 0, Resque.size(:unique)
20
- Resque.enqueue FakeUniqueJob, "foo"
21
- Resque.enqueue FakeUniqueJob, "foo"
22
- assert_equal 1, Resque.size(:unique)
23
- end
24
-
25
- it "consider equivalent hashes regardless of key order" do
26
- Resque.enqueue FakeUniqueJob, bar: 1, foo: 2
27
- Resque.enqueue FakeUniqueJob, foo: 2, bar: 1
28
- assert_equal 1, Resque.size(:unique)
29
- end
30
-
31
- it "treat string and symbol keys equally" do
32
- Resque.enqueue FakeUniqueJob, bar: 1, foo: 1
33
- Resque.enqueue FakeUniqueJob, bar: 1, "foo" => 1
34
- assert_equal 1, Resque.size(:unique)
35
- end
36
-
37
- it "mark jobs as unqueued, when Job.destroy is killing them" do
38
- Resque.enqueue FakeUniqueJob, "foo"
39
- Resque.enqueue FakeUniqueJob, "foo"
40
- assert_equal 1, Resque.size(:unique)
41
- Resque::Job.destroy(:unique, FakeUniqueJob)
42
- assert_equal 0, Resque.size(:unique)
43
- Resque.enqueue FakeUniqueJob, "foo"
44
- Resque.enqueue FakeUniqueJob, "foo"
45
- assert_equal 1, Resque.size(:unique)
46
- end
47
-
48
- it "mark jobs as unqueued when they raise an exception" do
49
- 2.times { Resque.enqueue( FailingUniqueJob, "foo" ) }
50
- assert_equal 1, Resque.size(:unique)
51
- worker = Resque::Worker.new(:unique)
52
- worker.work 0
53
- assert_equal 0, Resque.size(:unique)
54
- 2.times { Resque.enqueue( FailingUniqueJob, "foo" ) }
55
- assert_equal 1, Resque.size(:unique)
56
- end
57
-
58
- it "report if a unique job is enqueued" do
59
- Resque.enqueue FakeUniqueJob, "foo"
60
- assert Resque.enqueued?(FakeUniqueJob, "foo")
61
- refute Resque.enqueued?(FakeUniqueJob, "bar")
62
- end
63
-
64
- it "report if a unique job is enqueued in another queue" do
65
- default_queue = FakeUniqueJob.instance_variable_get(:@queue)
66
- FakeUniqueJob.instance_variable_set(:@queue, :other)
67
- Resque.enqueue FakeUniqueJob, "foo"
68
- assert Resque.enqueued_in?(:other, FakeUniqueJob, "foo")
69
- FakeUniqueJob.instance_variable_set(:@queue, default_queue)
70
- refute Resque.enqueued?(FakeUniqueJob, "foo")
71
- end
72
-
73
- it "cleanup when a queue is destroyed" do
74
- Resque.enqueue FakeUniqueJob, "foo"
75
- Resque.enqueue FailingUniqueJob, "foo"
76
- Resque.remove_queue(:unique)
77
- Resque.enqueue(FakeUniqueJob, "foo")
78
- assert_equal 1, Resque.size(:unique)
79
- end
80
-
81
- it "honor ttl in the redis key" do
82
- Resque.enqueue UniqueJobWithTtl
83
- assert Resque.enqueued?(UniqueJobWithTtl)
84
- keys = Resque.redis.keys "solo:queue:unique_with_ttl:job:*"
85
- assert_equal 1, keys.length
86
- assert_in_delta UniqueJobWithTtl.ttl, Resque.redis.ttl(keys.first), 2
87
- end
88
-
89
- it "not allow the same job to be enqueued after execution if lock_after_execution_period is set" do
90
- Resque.enqueue UniqueJobWithLock, "foo"
91
- Resque.enqueue UniqueJobWithLock, "foo"
92
- assert_equal 1, Resque.size(:unique_with_lock)
93
- Resque.reserve(:unique_with_lock)
94
- assert_equal 0, Resque.size(:unique_with_lock)
95
- Resque.enqueue UniqueJobWithLock, "foo"
96
- assert_equal 0, Resque.size(:unique_with_lock)
97
- end
98
-
99
- it "honor lock_after_execution_period in the redis key" do
100
- Resque.enqueue UniqueJobWithLock
101
- Resque.reserve(:unique_with_lock)
102
- keys = Resque.redis.keys "solo:queue:unique_with_lock:job:*"
103
- assert_equal 1, keys.length
104
- assert_in_delta UniqueJobWithLock.lock_after_execution_period, Resque.redis.ttl(keys.first), 2
105
- end
106
-
107
- end
@@ -1,57 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ResqueSolo
4
- class QueueTest < MiniTest::Spec
5
- describe ".is_unique?" do
6
- it "is false for non-unique job" do
7
- refute Queue.is_unique?(class: 'FakeJob')
8
- end
9
-
10
- it "is false for invalid job class" do
11
- refute Queue.is_unique?(class: 'InvalidJob')
12
- end
13
-
14
- it "is true for unique job" do
15
- assert Queue.is_unique?(class: 'FakeUniqueJob')
16
- end
17
- end
18
-
19
- describe ".item_ttl" do
20
- it "is -1 for non-unique job" do
21
- assert_equal -1, Queue.item_ttl(class: 'FakeJob')
22
- end
23
-
24
- it "is -1 for invalid job class" do
25
- assert_equal -1, Queue.item_ttl(class: 'InvalidJob')
26
- end
27
-
28
- it "is -1 for unique job" do
29
- assert_equal -1, Queue.item_ttl(class: 'FakeUniqueJob')
30
- end
31
-
32
- it "is job TTL" do
33
- assert_equal 300, UniqueJobWithTtl.ttl
34
- assert_equal 300, Queue.item_ttl(class: 'UniqueJobWithTtl')
35
- end
36
- end
37
-
38
- describe ".lock_after_execution_period" do
39
- it "is 0 for non-unique job" do
40
- assert_equal 0, Queue.lock_after_execution_period(class: 'FakeJob')
41
- end
42
-
43
- it "is 0 for invalid job class" do
44
- assert_equal 0, Queue.lock_after_execution_period(class: 'InvalidJob')
45
- end
46
-
47
- it "is 0 for unique job" do
48
- assert_equal 0, Queue.lock_after_execution_period(class: 'FakeUniqueJob')
49
- end
50
-
51
- it "is job lock period" do
52
- assert_equal 150, UniqueJobWithLock.lock_after_execution_period
53
- assert_equal 150, Queue.lock_after_execution_period(class: 'UniqueJobWithLock')
54
- end
55
- end
56
- end
57
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ResqueTest < MiniTest::Spec
4
- before do
5
- Resque.redis.flushall
6
- end
7
-
8
- it "is a valid plugin" do
9
- Resque::Plugin.lint(Resque::Plugins::UniqueJob)
10
- end
11
-
12
- it "enqueues normal jobs" do
13
- Resque.enqueue FakeJob, "x"
14
- Resque.enqueue FakeJob, "x"
15
- assert_equal 2, Resque.size(:normal)
16
- end
17
-
18
- it "is not able to report if a non-unique job was enqueued" do
19
- assert_nil Resque.enqueued?(FakeJob)
20
- end
21
-
22
- it "does not raise when deleting an empty queue" do
23
- Resque.remove_queue(:unique)
24
- end
25
-
26
- end
@@ -1,14 +0,0 @@
1
- if ENV['SIMPLE_COV']
2
- require 'simplecov'
3
- SimpleCov.start
4
- end
5
-
6
- require 'minitest/autorun'
7
- require 'resque_solo'
8
- require 'fake_jobs'
9
- require 'fakeredis'
10
- begin
11
- require 'pry-byebug'
12
- rescue LoadError
13
- # ignore
14
- end
@@ -1,5 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UniqueJobTest < MiniTest::Spec
4
-
5
- end