q 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class DelayedJobUser
4
+ include Q::Methods::DelayedJob
5
+
6
+ def self.bar; end
7
+
8
+ queue(:foo) do |value|
9
+ puts "Calling DelayedJobUser::Foo with value #{value}"
10
+ DelayedJobUser.bar
11
+ end
12
+ end
13
+
14
+ class DelayedJobTest < Test::Unit::TestCase
15
+
16
+ def setup
17
+ # @pid, @capture = start_delayed_job
18
+ end
19
+
20
+ def teardown
21
+ # kill_process(@pid)
22
+ end
23
+
24
+ def output
25
+ @output ||= ""
26
+ @output << @capture.string
27
+ end
28
+
29
+ # def test_delayed_job_non_inline_works
30
+ # value = rand(1..99)
31
+ # DelayedJobUser.queue.foo(value)
32
+ # sleep 1
33
+ # assert_match "Calling DelayedJobUser::Foo with value #{value}", output
34
+ # end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ SETUP_RESQUE_NAMESPACE.call
4
+
5
+ class ResqueUser
6
+ include Q::Methods::Resque
7
+
8
+ def self.bar; end
9
+
10
+ queue(:foo) do |value|
11
+ Resque.logger.info "Calling ResqueUser::Foo with value #{value}"
12
+ ResqueUser.bar
13
+ end
14
+ end
15
+
16
+ class ResqueTest < Test::Unit::TestCase
17
+
18
+ def setup
19
+ @pid, @capture = start_resque
20
+ end
21
+
22
+ def teardown
23
+ kill_process(@pid)
24
+ end
25
+
26
+ def output
27
+ @output ||= ""
28
+ @output << @capture.string
29
+ end
30
+
31
+ def test_resque_non_inline_works
32
+ value = rand(1..99)
33
+ ResqueUser.queue.foo(value)
34
+ sleep 5
35
+ assert_match "Calling ResqueUser::Foo with value #{value}", output
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+ require 'q/methods/resque'
3
+
4
+
5
+ class SidekiqTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @pid, @capture = start_sidekiq
9
+ end
10
+
11
+ def teardown
12
+ kill_process(@pid)
13
+ end
14
+
15
+ def output
16
+ @output ||= ""
17
+ @output << @capture.string
18
+ end
19
+
20
+ def test_sidekiq_non_inline_works
21
+ value = rand(1..99)
22
+ SidekiqUser.queue.foo(value)
23
+ sleep 1
24
+ assert_match output, "Calling SidekiqUser::Foo with value #{value}"
25
+ end
26
+
27
+ # def test_sidekiq_with_inline_works
28
+ # value = rand(1..99)
29
+ # Q.queue_config.inline = true
30
+
31
+ # SidekiqUser.queue.foo(value)
32
+ # sleep 1
33
+ # assert_match "Calling SidekiqUser::Foo with value #{value}", output
34
+ # ensure
35
+ # Q.queue_config.inline = false
36
+ # end
37
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ # TODO: seperate threaded tests from Q general regession tests in this file
4
+ class User
5
+ include Q::Methods::Threaded
6
+
7
+ def self.find(id)
8
+ self.new
9
+ end
10
+
11
+ queue :foo do
12
+ end
13
+
14
+ def self.bar(*args)
15
+ end
16
+
17
+ queue :bar do |*args|
18
+ User.bar(*args)
19
+ end
20
+ end
21
+
22
+ class Foo
23
+ include Q::Methods::Threaded
24
+
25
+ def self.bar(*args)
26
+ end
27
+
28
+ queue :bar do |*args|
29
+ Foo.bar(*args)
30
+ end
31
+
32
+ queue :early_return_if do |bool|
33
+ return true if bool
34
+ Foo.bar
35
+ end
36
+ end
37
+
38
+
39
+ class ThreadedTest < Test::Unit::TestCase
40
+
41
+ def setup
42
+ Q.queue_config.inline = true
43
+ end
44
+
45
+ def teardown
46
+ Q.queue_config.inline = false
47
+ end
48
+
49
+ def test_queue_is_defined
50
+ assert_match "foo", User.queue.methods.join(', ')
51
+ end
52
+
53
+ def test_dequeue
54
+ args = [1,2,3]
55
+ User.expects(:bar).with(args).twice
56
+
57
+ user = User
58
+ user.queue.bar(args)
59
+
60
+ user = User.new
61
+ user.queue.bar(args)
62
+ end
63
+
64
+ # make sure the namespace works correctly Foo::Bar and User::Bar
65
+ def test_namespacing_works
66
+ refute_equal Foo::Bar, User::Bar
67
+ end
68
+
69
+ def test_early_returns_do_not_blow_up
70
+ Foo.expects(:bar).once
71
+ Foo.queue.early_return_if false
72
+ Foo.queue.early_return_if true
73
+ end
74
+
75
+ def test_non_inline
76
+ Q.queue_config.inline = false
77
+
78
+ args = [1,2,3]
79
+ User.expects(:bar).with(args).twice
80
+
81
+ user = User
82
+ user.queue.bar(args)
83
+
84
+ user = User.new
85
+ user.queue.bar(args)
86
+ ensure
87
+ Q.queue_config.stop
88
+ end
89
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+
4
+ f = Proc.new do |queue_type|
5
+
6
+
7
+ class MtPoro
8
+ include Q::Methods
9
+
10
+ queue(:quux) do
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ class MethodsTest < Test::Unit::TestCase
17
+
18
+ def teardown
19
+ Q.reset_queue!
20
+ end
21
+
22
+ def test_propper_switching
23
+
24
+ Q.queue = :threaded
25
+
26
+ assert_equal Q::Methods::Threaded, Q.queue
27
+ Q::Methods::Threaded::QueueBuild.expects(:call).once
28
+ Q::Methods::Threaded::QueueMethod.expects(:call).once
29
+
30
+ Class.new do
31
+ include Q::Methods
32
+ queue(:quux) {}
33
+ end
34
+
35
+ Q.queue = :resque
36
+
37
+ assert_equal Q::Methods::Resque, Q.queue
38
+ Q::Methods::Resque::QueueBuild.expects(:call).once
39
+ Q::Methods::Resque::QueueMethod.expects(:call).once
40
+
41
+ Class.new do
42
+ include Q::Methods
43
+ queue(:quux){}
44
+ end
45
+ end
46
+
47
+ def test_env
48
+ Q.queue = :threaded
49
+ assert Q.env.threaded?
50
+ refute Q.env.resque?
51
+
52
+ Q.reset_queue!
53
+
54
+ assert Q.env.threaded?
55
+ refute Q.env.resque?
56
+
57
+ Q.queue = :resque
58
+
59
+ refute Q.env.threaded
60
+ assert Q.env.resque?
61
+ end
62
+
63
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class QTest < Test::Unit::TestCase
5
+
6
+ def test_queue_lookup
7
+ assert_equal Q::Methods::Resque, Q.queue_lookup[:resque].call
8
+ assert_equal Q::Methods::Sidekiq, Q.queue_lookup[:sidekiq].call
9
+ assert_equal Q::Methods::DelayedJob, Q.queue_lookup[:delayed_job].call
10
+ assert_equal Q::Methods::Threaded, Q.queue_lookup[:threaded].call
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ require 'delayed_job_active_record'
2
+
3
+ require 'q/methods/delayed_job'
4
+
5
+ require 'delayed_job'
6
+
7
+
8
+ ESTABLISH_ACTIVERECORD = Proc.new do
9
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "test/db/test.db"
10
+
11
+ ActiveRecord::Schema.define do
12
+ create_table :delayed_jobs, :force => true do |table|
13
+ table.integer :priority, :default => 0
14
+ table.integer :attempts, :default => 0
15
+ table.text :handler
16
+ table.text :last_error
17
+ table.datetime :run_at
18
+ table.datetime :locked_at
19
+ table.datetime :failed_at
20
+ table.string :locked_by
21
+ table.string :queue
22
+ table.timestamps
23
+ end
24
+ end
25
+ end
26
+
27
+ ESTABLISH_ACTIVERECORD.call
28
+
29
+ def start_delayed_job
30
+ stdout = StringIO.new
31
+ pid = Process.fork do
32
+ ESTABLISH_ACTIVERECORD.call
33
+ Delayed::Worker.logger = Logger.new(stdout)
34
+ Q::Methods::DelayedJob::QueueTask.call
35
+ end
36
+
37
+ return pid, stdout
38
+ end
39
+
40
+
41
+ namespace :jobs do
42
+
43
+ desc "Clear the delayed_job queue."
44
+ task :clear do
45
+ Delayed::Job.delete_all
46
+ end
47
+
48
+ desc "Start a delayed_job worker."
49
+ task :work => :environment_options do
50
+ Delayed::Worker.new(@worker_options).start
51
+ end
52
+
53
+ desc "Start a delayed_job worker and exit when all available jobs are complete."
54
+ task :workoff => :environment_options do
55
+ Delayed::Worker.new(@worker_options.merge({:exit_on_complete => true})).start
56
+ end
57
+
58
+ task :environment_options do
59
+ @worker_options = {
60
+ :min_priority => ENV['MIN_PRIORITY'],
61
+ :max_priority => ENV['MAX_PRIORITY'],
62
+ :queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
63
+ :quiet => false
64
+ }
65
+ end
66
+ end
@@ -0,0 +1,25 @@
1
+ require 'resque'
2
+ require 'resque/tasks'
3
+
4
+ require 'q/methods/resque'
5
+
6
+ RESQUE_NAMESPACE = "q:redis:namespace"
7
+
8
+ # useful so we don't accidentally run other code
9
+ SETUP_RESQUE_NAMESPACE = Proc.new do
10
+ Resque.redis.namespace = RESQUE_NAMESPACE
11
+ end
12
+
13
+ SETUP_RESQUE_NAMESPACE.call
14
+
15
+ def start_resque
16
+ stdout = StringIO.new
17
+ Resque.inline = false
18
+ pid = Process.fork do
19
+ SETUP_RESQUE_NAMESPACE.call
20
+ Resque.logger = Logger.new(stdout)
21
+ Q::Methods::Resque::QueueTask.call
22
+ end
23
+
24
+ return pid, stdout
25
+ end
@@ -0,0 +1,38 @@
1
+ require 'q'
2
+ require 'sidekiq'
3
+ require 'q/methods/sidekiq'
4
+
5
+ SIDEKIQ_NAMESPACE = "q:sidekiq:namespace"
6
+
7
+ SETUP_SIDEKIQ_NAMESPACE = Proc.new do
8
+ Sidekiq.configure_client do |config|
9
+ config.redis = { :namespace => SIDEKIQ_NAMESPACE }
10
+ end
11
+ end
12
+
13
+ def start_sidekiq
14
+ stdout = StringIO.new
15
+ Q::Methods::Sidekiq::QueueConfig.call.inline = false
16
+ pid = Process.fork do
17
+ SETUP_SIDEKIQ_NAMESPACE.call
18
+ # Object.const_set(:STDOUT, stdout
19
+ Sidekiq.logger = Logger.new(stdout)
20
+ Q::Methods::Sidekiq::QueueTask.call
21
+ end
22
+
23
+ return pid, stdout
24
+ end
25
+
26
+
27
+ SETUP_SIDEKIQ_NAMESPACE.call
28
+
29
+ class SidekiqUser
30
+ include Q::Methods::Sidekiq
31
+
32
+ def self.bar; end
33
+
34
+ queue(:foo) do |value|
35
+ Sidekiq.logger.info "Calling SidekiqUser::Foo with value #{value}"
36
+ SidekiqUser.bar
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ require 'threaded_in_memory_queue'
2
+
3
+ ThreadedInMemoryQueue.configure do |config|
4
+ config.size = 2
5
+ end
@@ -0,0 +1,22 @@
1
+ Bundler.require
2
+
3
+ require 'q'
4
+ require 'test/unit'
5
+ require "mocha/setup"
6
+
7
+
8
+ Dir.glob("test/support/*.rb").each do |support|
9
+ require support.gsub('test/', '').gsub('.rb', '')
10
+ end
11
+
12
+ class Dummy
13
+ end
14
+
15
+ def kill_process(pid)
16
+ Process.kill :INT, pid
17
+ end
18
+
19
+ if defined?(Rake)
20
+ task = Rake::Task.define_task("environment") do
21
+ end
22
+ end
metadata CHANGED
@@ -1,146 +1,200 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: q
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 0
10
- version: 0.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
11
5
  platform: ruby
12
- authors:
13
- - Christopher M. Hobbs
6
+ authors:
7
+ - Richard Schneeman
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-07-05 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: i18n
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: proc_to_lambda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
33
20
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: trollop
37
21
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: threaded_in_memory_queue
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
47
34
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: chronic
51
35
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: dm-core
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
65
49
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- type: :runtime
76
- version_requirements: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: dm-migrations
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
79
63
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
89
- type: :runtime
90
- version_requirements: *id005
91
- description: q is a command line activity logger/time tracker.
92
- email:
93
- - chris@altbit.org
94
- executables:
95
- - q
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: resque
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sidekiq
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: delayed_job_active_record
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: ' A universal interface for Ruby queueing backends. '
126
+ email:
127
+ - richard.schneeman+rubygems@gmail.com
128
+ executables: []
96
129
  extensions: []
97
-
98
130
  extra_rdoc_files: []
99
-
100
- files:
131
+ files:
101
132
  - .gitignore
102
- - .rvmrc
133
+ - CHANGELOG.md
103
134
  - Gemfile
135
+ - QUEUE_AUTHORS.md
104
136
  - README.md
105
137
  - Rakefile
106
- - bin/q
107
138
  - lib/q.rb
139
+ - lib/q/errors.rb
140
+ - lib/q/helpers.rb
141
+ - lib/q/methods.rb
142
+ - lib/q/methods/base.rb
143
+ - lib/q/methods/delayed_job.rb
144
+ - lib/q/methods/resque.rb
145
+ - lib/q/methods/sidekiq.rb
146
+ - lib/q/methods/threaded_in_memory_queue.rb
147
+ - lib/q/tasks.rb
108
148
  - lib/q/version.rb
109
149
  - q.gemspec
110
- - spec/.gitignore
111
- has_rdoc: true
112
- homepage: http://github.com/hooobs/q
113
- licenses: []
114
-
150
+ - test/methods/base_test.rb
151
+ - test/methods/delayed_job_test.rb
152
+ - test/methods/resque_test.rb
153
+ - test/methods/sidekiq_test.rb
154
+ - test/methods/threaded_test.rb
155
+ - test/methods_test.rb
156
+ - test/q_test.rb
157
+ - test/support/delayed_job.rb
158
+ - test/support/resque.rb
159
+ - test/support/sidekiq.rb
160
+ - test/support/threaded_in_memory_queue.rb
161
+ - test/test_helper.rb
162
+ homepage: https://github.com/schneems/q
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
115
166
  post_install_message:
116
167
  rdoc_options: []
117
-
118
- require_paths:
168
+ require_paths:
119
169
  - lib
120
- required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 3
126
- segments:
127
- - 0
128
- version: "0"
129
- required_rubygems_version: !ruby/object:Gem::Requirement
130
- none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- hash: 3
135
- segments:
136
- - 0
137
- version: "0"
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
138
180
  requirements: []
139
-
140
181
  rubyforge_project:
141
- rubygems_version: 1.5.2
182
+ rubygems_version: 2.0.3
142
183
  signing_key:
143
- specification_version: 3
144
- summary: q is for Journal
145
- test_files:
146
- - spec/.gitignore
184
+ specification_version: 4
185
+ summary: Use Q to switch betwen queue backends as you please. Simplifies creating
186
+ and calling background jobs
187
+ test_files:
188
+ - test/methods/base_test.rb
189
+ - test/methods/delayed_job_test.rb
190
+ - test/methods/resque_test.rb
191
+ - test/methods/sidekiq_test.rb
192
+ - test/methods/threaded_test.rb
193
+ - test/methods_test.rb
194
+ - test/q_test.rb
195
+ - test/support/delayed_job.rb
196
+ - test/support/resque.rb
197
+ - test/support/sidekiq.rb
198
+ - test/support/threaded_in_memory_queue.rb
199
+ - test/test_helper.rb
200
+ has_rdoc: