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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 212532c0e53da43e758379c93d9af4a619df7804
4
- data.tar.gz: 1f9cb86e8408906a3cdb4a8488a8c48f9e33315f
3
+ metadata.gz: f29a84d4cefb49cf688a2fe2fe2bc5fcfc0a29d6
4
+ data.tar.gz: 2314325e125adf600c3dc6f1190d9677574dc88a
5
5
  SHA512:
6
- metadata.gz: 95c97856b2ad9e78c1b49730d8dde8fd639abd969fdea4e3062bb5d177df3b98b441ba469aafa54c793dae8a8a9eeab12ba113bc5cc951d5f34e3eb5282a8a23
7
- data.tar.gz: 1b2ec20719f8cb13631bf3eb3502b02fc7d2f77d73d8d79f97b01f504182523c8c023eeffebe86fe567b49a11b980081c982832f370b3e40c8cc69ba18a7a8aa
6
+ metadata.gz: 8fa78c4be3782443580d74072aec81b09a6079630b7b22910a148f79f11d69d90ce178b3297ef42bee287a4d92676f685bc88d75f488184613ea4a846f71d9a2
7
+ data.tar.gz: 960d4938fe9f596f77c607a1622bda422285fdce50de362189406b684af0846846a5b51963c8d99518ed1478e242cb1c7ed80eecd8c97ef89c387b7783f1da52
data/.gems ADDED
@@ -0,0 +1,3 @@
1
+ disque -v 0.0.6
2
+ cutest -v 1.2.2
3
+ byebug -v 5.0.0
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -16,7 +16,7 @@ $ gem install disc
16
16
  requie 'disc'
17
17
 
18
18
  class CreateGameGrid
19
- include Disque::Job
19
+ include Disc::Job
20
20
  queue :urgent
21
21
 
22
22
  def perform(type)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'disc'
4
+ require ENV.fetch('DISC_REQUIRE')
5
+
6
+ if defined?(Celluloid)
7
+ raise 'not implemented yet genius'
8
+ else
9
+ Disc::Worker.run
10
+ end
@@ -1,17 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'disc'
3
- s.version = '0.0.1'
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.files = `git ls-files`.split("\n")
12
-
13
- s.add_dependency 'disque'
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
@@ -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
- :disque_timeout
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 = client || Disc.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
- ENV.fetch('QUEUES', 'default').split(',')
48
+ ENV.fetch('QUEUES', 'default').split(',')
48
49
  else
49
- raise 'Invalid Disque Queues'
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.disque=(disque)
75
- @disque = disque
78
+ def self.included(base)
79
+ base.extend(ClassMethods)
76
80
  end
77
81
 
78
- def self.disque
79
- defined?(@disque) ? @disque : Disc.disque
80
- end
82
+ module ClassMethods
83
+ def disque
84
+ defined?(@disque) ? @disque : Disc.disque
85
+ end
81
86
 
82
- def self.disc(options = {})
83
- @queue ||= options.fetch(:queue, :default)
84
- end
87
+ def disque=(disque)
88
+ @disque = disque
89
+ end
85
90
 
86
- def self.enqueue(*args, at: nil)
87
- job = new(args)
91
+ def queue
92
+ @queue ||= 'default'
93
+ end
88
94
 
89
- disque.push(
90
- job.queue,
91
- job.serializable.to_msgpack,
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
- def initialize(arguments)
98
- @arguments = arguments
99
- end
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
- def serializable
102
- {
103
- class: self.class.name,
104
- arguments: self.arguments
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
@@ -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.1
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