disc 0.0.12 → 0.0.13

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: 6ffe5775ac38d2ed07abc9c602d02bece9ed62be
4
- data.tar.gz: 3bb2ef3b149eedcfe99f15ea8b5a9c2a5bfcdc47
3
+ metadata.gz: 98230b94d3119aa8d3b6173dd2df9758961e88eb
4
+ data.tar.gz: 3ad4fe6b39858293874a1891fad05c21016cd996
5
5
  SHA512:
6
- metadata.gz: d4d2f921456d0843e97101bda9a408db66ecd9bac51c961edddcfb05ca330a71d447354bf3fe9d805daa6ac65358aae51bd56d248edfd721cf0c541758bca8e7
7
- data.tar.gz: a6ca018282b0c2d773424d823524e48814b67d67c1e7272baf8cedc6dbb70825fc0a6aed5bc6f2d8452516ee6e02476f102b0265987df176acc707857e0852fa
6
+ metadata.gz: 24c241f496c3bef60e8229bd0b138500e6192d6f7ce9b5d23b4f27500bbf3bcec654d1099e2cf170d4f79c1ff8faaaa3c40dc1c081047f7a6fe4324aadb8adf8
7
+ data.tar.gz: 5349b3bb90a78c4170456344fecc5775024b9668d3bf3410f8e8a797d85643a4a499c9073d10bd8f3d92bd2011f34ee0048ae84e8c0f1c443cc3a63b1977d066
data/bin/disc CHANGED
@@ -8,7 +8,7 @@ Clap.run ARGV,
8
8
 
9
9
  if defined?(Celluloid)
10
10
  concurrency = ENV.fetch('DISC_CONCURRENCY', '25').to_i
11
- STDOUT.puts(
11
+ $stdout.puts(
12
12
  "[Notice] Disc running in celluloid mode! Current DISC_CONCURRENCY is\
13
13
  #{ concurrency }."
14
14
  )
@@ -32,6 +32,6 @@ if defined?(Celluloid)
32
32
  )
33
33
  end
34
34
  else
35
- STDOUT.puts("[Notice] Disc running in non-threaded mode")
35
+ $stdout.puts("[Notice] Disc running in non-threaded mode")
36
36
  Disc::Worker.run
37
37
  end
data/examples/echoer.rb CHANGED
@@ -2,11 +2,9 @@ require 'disc'
2
2
 
3
3
  class Echoer
4
4
  include Disc::Job
5
- disc queue: 'test_medium'
5
+ disc queue: 'test_urgent'
6
6
 
7
7
  def perform(first, second, third)
8
- puts "First: #{ first }"
9
- puts "Second: #{ second }"
10
- puts "Third: #{ third }"
8
+ puts "First: #{ first }, Second: #{ second }, Third: #{ third }"
11
9
  end
12
10
  end
data/lib/disc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Disc
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/lib/disc.rb CHANGED
@@ -29,7 +29,7 @@ class Disc
29
29
  end
30
30
 
31
31
  def self.on_error(exception, job)
32
- STDERR.puts exception
32
+ $stderr.puts exception
33
33
  end
34
34
 
35
35
  class Worker
@@ -64,7 +64,7 @@ class Disc
64
64
  end
65
65
 
66
66
  def run
67
- STDOUT.puts("Disc::Worker listening in #{queues}")
67
+ $stdout.puts("Disc::Worker listening in #{queues}")
68
68
  loop do
69
69
  jobs = disque.fetch(from: queues, timeout: timeout, count: count)
70
70
  Array(jobs).each do |queue, msgid, serialized_job|
@@ -113,15 +113,15 @@ class Disc
113
113
  end
114
114
 
115
115
  def enqueue(*args)
116
- enqueue_at(nil, args)
116
+ enqueue_at(nil, *args)
117
117
  end
118
118
 
119
119
  def enqueue_at(datetime, *args)
120
120
  disque.push(
121
121
  queue,
122
122
  {
123
- class: self.new.class.name,
124
- arguments: args.first
123
+ class: self.name,
124
+ arguments: args
125
125
  }.to_msgpack,
126
126
  Disc.disque_timeout,
127
127
  delay: datetime.nil? ? nil : (datetime.to_time.to_i - DateTime.now.to_time.to_i)
data/test/disc_test.rb CHANGED
@@ -1,18 +1,9 @@
1
- $: << 'lib'
2
1
  require 'cutest'
3
2
  require 'disc'
4
3
  require 'msgpack'
4
+ require 'pty'
5
5
 
6
- class TestJob
7
- include Disc::Job
8
- disc queue: 'test_urgent'
9
-
10
- def perform(first, second, third)
11
- puts "First: #{ first }"
12
- puts "Second: #{ second }"
13
- puts "Third: #{ third }"
14
- end
15
- end
6
+ require_relative '../examples/echoer'
16
7
 
17
8
  prepare do
18
9
  Disc.disque.call('DEBUG', 'FLUSHALL')
@@ -20,19 +11,20 @@ end
20
11
 
21
12
  scope do
22
13
  test 'jobs are enqueued to the correct Disque queue with appropriate parameters and class' do
23
- TestJob.enqueue('one argument', { random: 'data' }, 3)
14
+ jobid = Echoer.enqueue('one argument', { random: 'data' }, 3)
24
15
 
25
16
  jobs = Array(Disc.disque.fetch(from: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
26
17
  assert jobs.any?
27
18
  assert_equal 1, jobs.count
28
19
 
29
- jobs.first.tap do |queue, _, serialized_job|
20
+ jobs.first.tap do |queue, id, serialized_job|
30
21
  job = MessagePack.unpack(serialized_job)
31
22
 
32
23
  assert job.has_key?('class')
33
24
  assert job.has_key?('arguments')
34
25
 
35
- assert_equal 'TestJob', job['class']
26
+ assert_equal 'Echoer', job['class']
27
+ assert_equal jobid, id
36
28
 
37
29
  args = job['arguments']
38
30
  assert_equal 3, args.size
@@ -41,4 +33,57 @@ scope do
41
33
  assert_equal(3, args[2])
42
34
  end
43
35
  end
36
+
37
+ test 'enqueue_at behaves properly' do
38
+ in_3_seconds = (Time.now + 3).to_datetime
39
+ jobid = Echoer.enqueue_at(in_3_seconds, 'one argument', { random: 'data' }, 3)
40
+
41
+ jobs = Array(Disc.disque.fetch(from: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
42
+ assert jobs.empty?
43
+
44
+ sleep 1
45
+ jobs = Array(Disc.disque.fetch(from: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
46
+ assert jobs.empty?
47
+
48
+ sleep 2
49
+ jobs = Array(Disc.disque.fetch(from: ['test_urgent'], timeout: Disc.disque_timeout, count: 1))
50
+ assert jobs.any?
51
+ assert_equal 1, jobs.size
52
+
53
+ jobs.first.tap do |queue, id, serialized_job|
54
+ assert_equal 'test_urgent', queue
55
+ assert_equal jobid, id
56
+ job = MessagePack.unpack(serialized_job)
57
+ assert job.has_key?('class')
58
+ assert job.has_key?('arguments')
59
+ assert_equal 'Echoer', job['class']
60
+ assert_equal 3, job['arguments'].size
61
+ end
62
+ end
63
+
64
+ test 'jobs are executed' do
65
+ begin
66
+ Echoer.enqueue('one argument', { random: 'data' }, 3)
67
+
68
+ cout, _, pid = PTY.spawn(
69
+ 'QUEUES=test_urgent ruby -Ilib bin/disc -r ./examples/echoer'
70
+ )
71
+ sleep 0.5
72
+
73
+ jobs = Disc.disque.fetch(from: ['test_urgent'], timeout: Disc.disque_timeout, count: 1)
74
+ assert jobs.nil?
75
+
76
+ matched = false
77
+ counter = 0
78
+ while !matched && counter < 5
79
+ counter += 1
80
+ matched = cout.gets.match(/First: one argument, Second: {"random"=>"data"}, Third: 3/)
81
+ sleep(1) unless matched
82
+ end
83
+
84
+ assert matched
85
+ ensure
86
+ Process.kill("KILL", pid)
87
+ end
88
+ end
44
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - pote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: disque