disc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +3 -0
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/bin/disc +10 -0
- data/disc.gemspec +5 -7
- data/lib/disc.rb +46 -30
- data/test/disc_test.rb +22 -0
- metadata +7 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f29a84d4cefb49cf688a2fe2fe2bc5fcfc0a29d6
|
4
|
+
data.tar.gz: 2314325e125adf600c3dc6f1190d9677574dc88a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa78c4be3782443580d74072aec81b09a6079630b7b22910a148f79f11d69d90ce178b3297ef42bee287a4d92676f685bc88d75f488184613ea4a846f71d9a2
|
7
|
+
data.tar.gz: 960d4938fe9f596f77c607a1622bda422285fdce50de362189406b684af0846846a5b51963c8d99518ed1478e242cb1c7ed80eecd8c97ef89c387b7783f1da52
|
data/.gems
ADDED
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
CHANGED
data/bin/disc
ADDED
data/disc.gemspec
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'disc'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.2'
|
4
4
|
s.summary = 'A simple disque and powerful job implementation'
|
5
5
|
s.description = ''
|
6
6
|
s.authors = ['pote']
|
7
7
|
s.email = ['pote@tardis.com.uy']
|
8
8
|
s.homepage = 'https://github.com/pote/disque-job'
|
9
9
|
s.license = 'MIT'
|
10
|
+
s.files = `git ls-files`.split("\n")
|
10
11
|
|
11
|
-
s.
|
12
|
-
|
13
|
-
s.add_dependency
|
14
|
-
s.add_dependency 'msgpack'
|
15
|
-
s.add_dependency 'clap'
|
16
|
-
s.add_development_dependency 'cutest'
|
12
|
+
s.executables.push('disc')
|
13
|
+
s.add_dependency('disque')
|
14
|
+
s.add_dependency('msgpack')
|
17
15
|
end
|
data/lib/disc.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'disque'
|
2
3
|
require 'msgpack'
|
3
4
|
|
4
5
|
class Disc
|
5
6
|
attr_reader :disque,
|
6
|
-
|
7
|
+
:disque_timeout
|
7
8
|
|
8
9
|
def self.disque
|
9
10
|
@disque ||= Disque.new(
|
@@ -36,7 +37,7 @@ class Disc
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def initialize(disque: nil , queues: nil, count: 1, timeout: nil)
|
39
|
-
@disque =
|
40
|
+
@disque = disque || Disc.disque
|
40
41
|
@count, @timeout = count, timeout
|
41
42
|
@queues = case
|
42
43
|
when queues.is_a?(Array)
|
@@ -44,9 +45,9 @@ class Disc
|
|
44
45
|
when queues.is_a?(String)
|
45
46
|
queues.split(',')
|
46
47
|
when queues.nil?
|
47
|
-
|
48
|
+
ENV.fetch('QUEUES', 'default').split(',')
|
48
49
|
else
|
49
|
-
|
50
|
+
raise 'Invalid Disque Queues'
|
50
51
|
end
|
51
52
|
|
52
53
|
self
|
@@ -54,12 +55,14 @@ class Disc
|
|
54
55
|
|
55
56
|
|
56
57
|
def run
|
58
|
+
STDOUT.puts("Disc::Worker listening in #{queues}")
|
57
59
|
loop do
|
58
60
|
disque.fetch(
|
59
61
|
from: queues,
|
60
62
|
timeout: timeout,
|
61
63
|
count: count
|
62
64
|
) do |serialized_job, _|
|
65
|
+
job = MessagePack.unpack(serialized_job)
|
63
66
|
klass = Object.const_get(job['class'])
|
64
67
|
klass.new.perform(job['arguments'])
|
65
68
|
end
|
@@ -69,40 +72,53 @@ class Disc
|
|
69
72
|
|
70
73
|
module Job
|
71
74
|
attr_reader :arguments,
|
72
|
-
:queue
|
75
|
+
:queue,
|
76
|
+
:disque
|
73
77
|
|
74
|
-
def self.
|
75
|
-
|
78
|
+
def self.included(base)
|
79
|
+
base.extend(ClassMethods)
|
76
80
|
end
|
77
81
|
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
module ClassMethods
|
83
|
+
def disque
|
84
|
+
defined?(@disque) ? @disque : Disc.disque
|
85
|
+
end
|
81
86
|
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
def disque=(disque)
|
88
|
+
@disque = disque
|
89
|
+
end
|
85
90
|
|
86
|
-
|
87
|
-
|
91
|
+
def queue
|
92
|
+
@queue ||= 'default'
|
93
|
+
end
|
88
94
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Disc.disque_timeout,
|
93
|
-
delay: at.nil? ? nil : (at.to_i - Time.now.to_i)
|
94
|
-
)
|
95
|
-
end
|
95
|
+
def queue=(queue)
|
96
|
+
@queue = queue
|
97
|
+
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
def enqueue(*args)
|
100
|
+
disque.push(
|
101
|
+
queue,
|
102
|
+
{
|
103
|
+
class: self.new.class.name,
|
104
|
+
arguments: args
|
105
|
+
}.to_msgpack,
|
106
|
+
Disc.disque_timeout
|
107
|
+
)
|
108
|
+
end
|
100
109
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
110
|
+
def enqueue_at(datetime, *args)
|
111
|
+
disque.push(
|
112
|
+
queue,
|
113
|
+
args.to_msgpack,
|
114
|
+
Disc.disque_timeout,
|
115
|
+
delay: at.nil? ? nil : (datetime.to_time.to_i - DateTime.now.to_time.to_i)
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def disc(options = {})
|
120
|
+
self.queue = options.fetch(:queue, 'default')
|
121
|
+
end
|
106
122
|
end
|
107
123
|
end
|
108
124
|
end
|
data/test/disc_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$: << 'lib'
|
2
|
+
require 'cutest'
|
3
|
+
require 'disc'
|
4
|
+
|
5
|
+
class TestJob
|
6
|
+
include Disc::Job
|
7
|
+
disc queue: 'test_urgent'
|
8
|
+
|
9
|
+
def perform(argument)
|
10
|
+
puts argument
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
scope do
|
15
|
+
test 'basic enqueuing works' do
|
16
|
+
original_length = Disc.disque.call('QLEN', 'test_urgent').to_i
|
17
|
+
|
18
|
+
TestJob.enqueue(random: 'data')
|
19
|
+
|
20
|
+
assert Disc.disque.call('QLEN', 'test_urgent').to_i == original_length + 1
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pote
|
@@ -38,45 +38,22 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: clap
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
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: cutest
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
41
|
description: ''
|
70
42
|
email:
|
71
43
|
- pote@tardis.com.uy
|
72
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- disc
|
73
46
|
extensions: []
|
74
47
|
extra_rdoc_files: []
|
75
48
|
files:
|
49
|
+
- ".gems"
|
50
|
+
- ".gitignore"
|
76
51
|
- Makefile
|
77
52
|
- README.md
|
53
|
+
- bin/disc
|
78
54
|
- disc.gemspec
|
79
55
|
- lib/disc.rb
|
56
|
+
- test/disc_test.rb
|
80
57
|
homepage: https://github.com/pote/disque-job
|
81
58
|
licenses:
|
82
59
|
- MIT
|