disc 0.0.9 → 0.0.10

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: a8c13e7e4ec525c4779d4d13e5164e6c0db6b97d
4
- data.tar.gz: 8d423e9024f07932f44836ba3d41d5b795c5f7d9
3
+ metadata.gz: 9e7f970b9a9d1cd2cd784f821cca12490dd4152a
4
+ data.tar.gz: 4e18b6330789898e33b533229c705ff349500925
5
5
  SHA512:
6
- metadata.gz: fdbc76ac8cf2678816048219b8e7f962f2b6564c8e43b35af26d371af773720aa12c1a1113e563b982dcf4ab4dd8461926446ebd5c0ab875ebc1dbbac9f57908
7
- data.tar.gz: d10b168948292c66d2626c213eef0551d9a0044407641292d59880b4032c4a2da683d18590b680d3a29ffadcc7356d98936cb33ee96963905edeee3e1149d983
6
+ metadata.gz: 6034dd9276d0c9f9a40d160ab7299f33839cdbfc071a8ed0fd4c2695615acf0e1ba254a8cbd436f95cffee27c3b1ac8f2b3f9e487ae2381347d75ef5be1bc6d2
7
+ data.tar.gz: f74d5eb2dd9025491ccd19ad0e651bebed8f3b000a2cc46590988083a7411d4b0e503aa3deb368bd8f010f59b51e68155578e166dbe54e061befe10189a2d20d
data/README.md CHANGED
@@ -118,7 +118,7 @@ the current job as a Hash, that has the following schema.
118
118
  ## PowerUps
119
119
 
120
120
  Disc workers can run just fine on their own, but if you're using
121
- [Celluloid](https://github.com/celluloid/celluloid) you migth want Disc to take
121
+ [Celluloid](https://github.com/celluloid/celluloid) you might want Disc to take
122
122
  advantage of it and spawn multiple worker threads per process, doing this is
123
123
  trivial! Just require Celluloid before your init file:
124
124
 
@@ -130,6 +130,37 @@ Whenever Disc detects that Celluloid is available it will use it to spawn a
130
130
  number of threads equal to the `DISC_CONCURRENCY` environment variable, or 25 by
131
131
  default.
132
132
 
133
+ ## Rails and ActiveJob integration
134
+
135
+ Disc has an [ActiveJob](http://edgeguides.rubyonrails.org/active_job_basics.html) adapter, which you can use very easily:
136
+
137
+ ```ruby
138
+ # Gemfile
139
+ gem 'disc'
140
+
141
+ # config/application.rb
142
+ module YourApp
143
+ class Application < Rails::Application
144
+ config.active_job.queue_adapter = :disc
145
+ end
146
+ end
147
+
148
+ # app/jobs/clu_job.rb
149
+
150
+ class CluJob < ActiveJob::Base
151
+ queue_as :urgent
152
+
153
+ def perform(*args)
154
+ # Try to take over The Grid here...
155
+ end
156
+ end
157
+
158
+ # Wherever you want
159
+ CluJob.perform_later(a_bunch_of_arguments)
160
+ ```
161
+
162
+ As always, make sure your `disc_init.rb` file requires the necessary jobs and you'll be good to go!
163
+
133
164
  ## License
134
165
 
135
166
  The code is released under an MIT license. See the [LICENSE](./LICENSE) file for
@@ -0,0 +1,7 @@
1
+ class IncrediblyActiveJob < ActiveJob::Base
2
+ queue_as :test_medium
3
+
4
+ def perform(something)
5
+ puts something
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'date'
2
+ require 'msgpack'
3
+
4
+ module ActiveJob
5
+ module QueueAdapters
6
+ class DiscAdapter
7
+ def enqueue(job)
8
+ enqueue_at(job, nil)
9
+ end
10
+
11
+ def enqueue_at(job, timestamp)
12
+ Disc.disque.push(
13
+ job.queue_name,
14
+ {
15
+ class: job.class.name,
16
+ arguments: job.arguments
17
+ }.to_msgpack,
18
+ Disc.disque_timeout,
19
+ delay: timestamp.nil? ? nil : (timestamp.to_time.to_i - DateTime.now.to_time.to_i)
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -68,10 +68,9 @@ class Disc
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|
71
- job = MessagePack.unpack(serialized_job)
72
- job.update('id' => msgid, 'queue' => queue)
73
-
74
71
  begin
72
+ job = MessagePack.unpack(serialized_job)
73
+ job.update('id' => msgid, 'queue' => queue)
75
74
  instance = Object.const_get(job['class']).new
76
75
  instance.disc_start(job)
77
76
  instance.perform(*job['arguments'])
@@ -1,3 +1,3 @@
1
1
  class Disc
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  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.9
4
+ version: 0.0.10
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-13 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: disque
@@ -69,9 +69,11 @@ files:
69
69
  - README.md
70
70
  - bin/disc
71
71
  - disc.gemspec
72
+ - examples/active_job.rb
72
73
  - examples/disc_init.rb
73
74
  - examples/fail_job.rb
74
75
  - examples/greeter.rb
76
+ - lib/active_job/queue_adapters/disc_adapter.rb
75
77
  - lib/disc.rb
76
78
  - lib/disc/version.rb
77
79
  - test/disc_test.rb