line_up 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 893ebb96aa6db1f8b61b41954630d0f3a7922da6
4
+ data.tar.gz: 82cd227d22fd25c02785675164a263fefd841ba1
5
+ SHA512:
6
+ metadata.gz: 010f5577b11b26d98d93c7dedd378cbc196525a1b300cfcaed0834f62fe591a29aa044f60cc3210de4478fb45c3ff8e1932fe33cc00d8dff3f919ad3a1ef5e28
7
+ data.tar.gz: 46c76b54b0932de54d07828a0ffb1c0b260a07e5b0132cee83c28b745adebe378fb5ace719944c13ab27cb17044b62ef4ca1c7af398231759f0f82ccc327d5cd
data/lib/line_up.rb CHANGED
@@ -25,6 +25,14 @@ module LineUp
25
25
  end
26
26
  end
27
27
 
28
+ def self.push_throttled(application, jobclass, *args)
29
+ job = Job.new jobclass, *args
30
+ unless recent? application, job
31
+ push(application, jobclass, *args)
32
+ recent! application, job
33
+ end
34
+ end
35
+
28
36
  def self.queue_length(application, jobclass)
29
37
  redis_for application do |r|
30
38
  job = Job.new jobclass
@@ -37,6 +45,19 @@ module LineUp
37
45
 
38
46
  private
39
47
 
48
+ def self.recent?(application, job)
49
+ redis_for application do |r|
50
+ return true if r.exists "throttled:#{job.checksum}"
51
+ end
52
+ false
53
+ end
54
+
55
+ def self.recent!(application, job)
56
+ redis_for application do |r|
57
+ r.setex "throttled:#{job.checksum}", config.recency_ttl, "true"
58
+ end
59
+ end
60
+
40
61
  def self.redis_for(application, &block)
41
62
  config.redis.namespace [StringExtensions.underscore(application), :resque].compact.join(':'), &block
42
63
  end
@@ -2,11 +2,12 @@ require 'logger'
2
2
 
3
3
  module LineUp
4
4
  class Configuration
5
- attr_accessor :logger, :redis
5
+ attr_accessor :logger, :redis, :recency_ttl
6
6
 
7
7
  def initialize(options={})
8
- @logger = options[:logger] || default_logger
9
- @redis = options[:redis] || default_redis
8
+ @logger = options[:logger] || default_logger
9
+ @redis = options[:redis] || default_redis
10
+ @recency_ttl = options[:recency_ttl] || default_recency_ttl
10
11
  end
11
12
 
12
13
  private
@@ -24,6 +25,11 @@ module LineUp
24
25
  return Resque.redis if defined?(Resque)
25
26
  Redis::Namespace.new nil
26
27
  end
28
+
29
+ def default_recency_ttl
30
+ 5
31
+ end
32
+
27
33
  end
28
34
  end
29
35
 
data/lib/line_up/job.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'line_up/string_extensions'
2
2
  require 'multi_json'
3
+ require 'digest/sha1'
3
4
 
4
5
  module LineUp
5
6
  class Job
@@ -11,6 +12,10 @@ module LineUp
11
12
  @args = args
12
13
  end
13
14
 
15
+ def checksum
16
+ Digest::SHA1.hexdigest(encode)
17
+ end
18
+
14
19
  def encode
15
20
  MultiJson.dump class: klass.to_s, args: args
16
21
  end
@@ -2,7 +2,7 @@ module LineUp
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
@@ -7,6 +7,7 @@ describe LineUp do
7
7
  let(:args) { [123, some: :thing] }
8
8
  let(:redis) { $raw_redis }
9
9
  let(:logger) { mock(:logger) }
10
+ let(:lineup_job) { LineUp::Job.new job, *args }
10
11
 
11
12
  let(:lineup) { LineUp }
12
13
 
@@ -124,4 +125,29 @@ describe LineUp do
124
125
  lineup.ensure application, job, *args
125
126
  end
126
127
  end
128
+
129
+ describe ".push_throttled" do
130
+
131
+ it "pushes same consecutive job just once" do
132
+ lineup.should_receive(:push).once
133
+ lineup.push_throttled application, job, *args
134
+ lineup.push_throttled application, job, *args
135
+ end
136
+
137
+ it "pushes again when previous identical job has expired" do
138
+ lineup.should_receive(:push).twice
139
+
140
+ lineup.push_throttled application, job, *args
141
+ redis.del "other_app:resque:throttled:#{lineup_job.checksum}"
142
+ lineup.push_throttled application, job, *args
143
+ end
144
+
145
+ it "stores throttle with configured ttl" do
146
+ lineup.push_throttled application, job, *args
147
+ ttl = redis.ttl "other_app:resque:throttled:#{lineup_job.checksum}"
148
+ ttl.should == lineup.config.recency_ttl
149
+ end
150
+
151
+ end
152
+
127
153
  end
metadata CHANGED
@@ -1,112 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line_up
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.1
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - bukowskis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
11
+ date: 2014-07-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
14
+ name: trouble
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- none: false
21
- name: trouble
22
20
  type: :runtime
23
21
  prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
22
+ version_requirements: !ruby/object:Gem::Requirement
25
23
  requirements:
26
- - - ! '>='
24
+ - - ">="
27
25
  - !ruby/object:Gem::Version
28
26
  version: '0'
29
- none: false
30
27
  - !ruby/object:Gem::Dependency
31
- version_requirements: !ruby/object:Gem::Requirement
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
32
30
  requirements:
33
- - - ! '>='
31
+ - - ">="
34
32
  - !ruby/object:Gem::Version
35
33
  version: '0'
36
- none: false
37
- name: multi_json
38
34
  type: :runtime
39
35
  prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
36
+ version_requirements: !ruby/object:Gem::Requirement
41
37
  requirements:
42
- - - ! '>='
38
+ - - ">="
43
39
  - !ruby/object:Gem::Version
44
40
  version: '0'
45
- none: false
46
41
  - !ruby/object:Gem::Dependency
47
- version_requirements: !ruby/object:Gem::Requirement
42
+ name: redis-namespace
43
+ requirement: !ruby/object:Gem::Requirement
48
44
  requirements:
49
- - - ! '>='
45
+ - - ">="
50
46
  - !ruby/object:Gem::Version
51
47
  version: 1.3.0
52
- none: false
53
- name: redis-namespace
54
48
  type: :runtime
55
49
  prerelease: false
56
- requirement: !ruby/object:Gem::Requirement
50
+ version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
- - - ! '>='
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
54
  version: 1.3.0
61
- none: false
62
55
  - !ruby/object:Gem::Dependency
63
- version_requirements: !ruby/object:Gem::Requirement
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - ! '>='
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
61
  version: '0'
68
- none: false
69
- name: rspec
70
62
  type: :development
71
63
  prerelease: false
72
- requirement: !ruby/object:Gem::Requirement
64
+ version_requirements: !ruby/object:Gem::Requirement
73
65
  requirements:
74
- - - ! '>='
66
+ - - ">="
75
67
  - !ruby/object:Gem::Version
76
68
  version: '0'
77
- none: false
78
69
  - !ruby/object:Gem::Dependency
79
- version_requirements: !ruby/object:Gem::Requirement
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
80
72
  requirements:
81
- - - ! '>='
73
+ - - ">="
82
74
  - !ruby/object:Gem::Version
83
75
  version: '0'
84
- none: false
85
- name: guard-rspec
86
76
  type: :development
87
77
  prerelease: false
88
- requirement: !ruby/object:Gem::Requirement
78
+ version_requirements: !ruby/object:Gem::Requirement
89
79
  requirements:
90
- - - ! '>='
80
+ - - ">="
91
81
  - !ruby/object:Gem::Version
92
82
  version: '0'
93
- none: false
94
83
  - !ruby/object:Gem::Dependency
95
- version_requirements: !ruby/object:Gem::Requirement
84
+ name: rb-fsevent
85
+ requirement: !ruby/object:Gem::Requirement
96
86
  requirements:
97
- - - ! '>='
87
+ - - ">="
98
88
  - !ruby/object:Gem::Version
99
89
  version: '0'
100
- none: false
101
- name: rb-fsevent
102
90
  type: :development
103
91
  prerelease: false
104
- requirement: !ruby/object:Gem::Requirement
92
+ version_requirements: !ruby/object:Gem::Requirement
105
93
  requirements:
106
- - - ! '>='
94
+ - - ">="
107
95
  - !ruby/object:Gem::Version
108
96
  version: '0'
109
- none: false
110
97
  description: No more need to maintain two separate redis connections when using namespaces.
111
98
  LineUp does not even need Resque itself.
112
99
  email:
@@ -114,42 +101,41 @@ executables: []
114
101
  extensions: []
115
102
  extra_rdoc_files: []
116
103
  files:
104
+ - LICENSE
105
+ - README.md
106
+ - lib/line_up.rb
117
107
  - lib/line_up/configuration.rb
118
108
  - lib/line_up/job.rb
119
109
  - lib/line_up/string_extensions.rb
120
110
  - lib/line_up/version.rb
121
- - lib/line_up.rb
122
111
  - spec/lib/line_up/configuration_spec.rb
123
112
  - spec/lib/line_up_spec.rb
124
113
  - spec/spec_helper.rb
125
- - README.md
126
- - LICENSE
127
114
  homepage: https://github.com/bukowskis/line_up
128
115
  licenses:
129
116
  - MIT
117
+ metadata: {}
130
118
  post_install_message:
131
119
  rdoc_options:
132
- - --encoding
120
+ - "--encoding"
133
121
  - UTF-8
134
122
  require_paths:
135
123
  - lib
136
124
  required_ruby_version: !ruby/object:Gem::Requirement
137
125
  requirements:
138
- - - ! '>='
126
+ - - ">="
139
127
  - !ruby/object:Gem::Version
140
128
  version: '0'
141
- none: false
142
129
  required_rubygems_version: !ruby/object:Gem::Requirement
143
130
  requirements:
144
- - - ! '>='
131
+ - - ">="
145
132
  - !ruby/object:Gem::Version
146
133
  version: '0'
147
- none: false
148
134
  requirements: []
149
135
  rubyforge_project:
150
- rubygems_version: 1.8.23
136
+ rubygems_version: 2.2.2
151
137
  signing_key:
152
- specification_version: 3
138
+ specification_version: 4
153
139
  summary: Enqueue Resque Jobs directly via Redis so that you can choose the namespace
154
140
  yourself
155
141
  test_files: []