pika_que 0.1.0 → 0.1.1

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: b062334f6fd120c3cbdd8f9dbab1d0a50119c6e1
4
- data.tar.gz: f9b3e62818fe79276aec1cb54435de8c51767eb1
3
+ metadata.gz: 39faa9df72e909b96bdc74876b9a68b87d26634c
4
+ data.tar.gz: edb0a973f47f8b872e1815cd162f42cffd6a9f8a
5
5
  SHA512:
6
- metadata.gz: 8aaab568dd9e153e2942534ad74341e5b6da4e87ed389dfb2c2bfa85cb1c5629d94382d8dcec02b4b888bb61a728b4fa4c8ecc1a293144ae4274ba686db7f896
7
- data.tar.gz: af5f17435c0992adbe6bb142cd3db5f20f29aef8a8bd54a7646084a9e1a1b9c8c4451c462d6003cfa7034ba26a0c1fe32978562e3f8873974e426b6fdef3411d
6
+ metadata.gz: 9f3f5b73288368228458ad5aef2002640447a037fa336866aecd6ff8f5637064b1acca53a6df86ab721601052c8010c0195c908642b5de6c62ab79772561baf4
7
+ data.tar.gz: 16438758d34dc710056d6c04139d8d68f602ee262495a43b3b20cf0479154c1f1d73ec3cd775e16fdf010fd46d49a9d54381a438924d00a2702b251cf81b3976
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # PikaQue
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pika_que`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A RabbitMQ background processing framework for Ruby with built-in support for Rails integration.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ PikaQue is inspired by Sneakers, Hutch, and Sidekiq. It is intended to implement more support for Rails a la Sidekiq.
6
+ It supports retry (both constant and exponential backoffs) and delayed/scheduled execution.
6
7
 
7
8
  ## Installation
8
9
 
@@ -12,17 +13,69 @@ Add this line to your application's Gemfile:
12
13
  gem 'pika_que'
13
14
  ```
14
15
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
16
  Or install it yourself as:
20
17
 
21
18
  $ gem install pika_que
22
19
 
23
20
  ## Usage
24
21
 
25
- TODO: Write usage instructions here
22
+ To create a worker:
23
+
24
+ ```ruby
25
+ class PokeWorker
26
+ include PikaQue::Worker
27
+ from_queue "rocket"
28
+
29
+ def perform(msg)
30
+ # do something with msg["greeting"]
31
+ # or below for active job
32
+ ActiveJob::Base.execute msg
33
+ ack!
34
+ end
35
+ end
36
+ ```
37
+
38
+ To enqueue a job:
39
+
40
+ ```ruby
41
+ PokeWorker.enqueue({ greeting: "I Challenge You!" })
42
+ ```
43
+
44
+ To run server:
45
+
46
+ $ bundle exec pika_que
47
+
48
+ ### Rails and ActiveJob
49
+
50
+ Create workers in:
51
+
52
+ app/workers
53
+
54
+ Create a initializer file `pika_que.rb` in:
55
+
56
+ config/initializers
57
+
58
+ ```ruby
59
+ # pika_que.rb
60
+
61
+ require 'active_job/queue_adapters/pika_que_adapter'
62
+
63
+ # override default queue_name for ActiveJob::Base and ActionMailer::DeliveryJob here if necessary
64
+
65
+ # setup workers here or with config/pika_que.yml
66
+ PikaQue.config.add_processor(workers: [PokeWorker])
67
+ PikaQue.config[:codec] = PikaQue::Codecs::RAILS
68
+ ```
69
+
70
+ Set the backend for active job in `config/application.rb`:
71
+
72
+ config.active_job.queue_adapter = :pika_que
73
+
74
+ Then run the server.
75
+
76
+ ## Specs
77
+
78
+ Coming soon. See examples for reference.
26
79
 
27
80
  ## Development
28
81
 
@@ -32,7 +85,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
85
 
33
86
  ## Contributing
34
87
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pika_que. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dwkoogt/pika_que. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
89
 
37
90
 
38
91
  ## License
@@ -14,7 +14,7 @@ module ActiveJob
14
14
  #
15
15
  # Rails.application.config.active_job.queue_adapter = :pika_que
16
16
  #
17
- class PikaQueAdapter
17
+ class PikaQueRails4
18
18
  @monitor = Monitor.new
19
19
 
20
20
  class << self
@@ -37,6 +37,30 @@ module ActiveJob
37
37
  end
38
38
  end
39
39
 
40
- autoload :PikaQueAdapter
40
+ class PikaQueRails5
41
+ def initialize
42
+ @monitor = Monitor.new
43
+ end
44
+
45
+ def enqueue(job) #:nodoc:
46
+ @monitor.synchronize do
47
+ JobWrapper.enqueue job.serialize, to_queue: job.queue_name
48
+ end
49
+ end
50
+
51
+ def enqueue_at(job, timestamp) #:nodoc:
52
+ @monitor.synchronize do
53
+ JobWrapper.enqueue_at job.serialize, timestamp, routing_key: job.queue_name
54
+ end
55
+ end
56
+
57
+ class JobWrapper #:nodoc:
58
+ extend PikaQue::Worker::ClassMethods
59
+ config codec: PikaQue::Codecs::RAILS
60
+ end
61
+ end
62
+
63
+ PikaQueAdapter = (::Rails::VERSION::MAJOR < 5) ? PikaQueRails4 : PikaQueRails5
64
+
41
65
  end
42
66
  end
@@ -42,3 +42,5 @@ module PikaQue
42
42
  end
43
43
 
44
44
  end
45
+
46
+ require 'pika_que/rails' if defined?(::Rails::Engine)
@@ -22,7 +22,8 @@ module PikaQue
22
22
  if File.exist? config_file
23
23
  PIKA_QUE_CONFIG = YAML.load_file(config_file)
24
24
  else
25
- PIKA_QUE_CONFIG = { "processors" => [{ "workers" => [{ "queue" => ActiveJob::Base.queue_name }, { "queue" => ActionMailer::DeliveryJob.queue_name}] }] }
25
+ mailer_queue = (::Rails::VERSION::MAJOR < 5) ? ActionMailer::DeliveryJob.queue_name : ActionMailer::Base.deliver_later_queue_name
26
+ PIKA_QUE_CONFIG = { "processors" => [{ "workers" => [{ "queue" => ActiveJob::Base.queue_name }, { "queue" => mailer_queue.to_s }] }] }
26
27
  end
27
28
 
28
29
  workers_dir = Rails.root.join('app').join('workers')
@@ -1,3 +1,3 @@
1
1
  module PikaQue
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pika_que
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dong Wook Koo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-02 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.4.5.2
177
+ rubygems_version: 2.5.2.2
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Ruby background processor for RabbitMQ.