sidediq 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cf7c6bec3aabc4f5089e19f24099003429a48b5f651facea8ee151fa443ae5d
4
- data.tar.gz: 6c67538e0da4f6ff47087d2868e1376bf0682f316d6742c298abbc0bd5471651
3
+ metadata.gz: 8d54de6fc8a7461a3bb40c277dadeb46abe60660deb49de6de01101ade840faa
4
+ data.tar.gz: bb431aa098782c185ece9f624ca3baae2a2aa270891954421930e32ff498507d
5
5
  SHA512:
6
- metadata.gz: 9554b0306cc5689c2ce259ea0a7d8a8be91fd3e7dc07ea65551c68e75c79f67cd761dd8161e6ed4986baf530e656b2070134902d63f4fc758d9eb26c89cef84b
7
- data.tar.gz: 501f0cea9bd699592748772fdb4b83fc0886e3d36ced47daa843ade65e07760e0c85db339967641cb529b6789e6489dc083c16d2a5e336d7d19719079efacb9f
6
+ metadata.gz: 5400ef9c70b356b21758c1636a167bef99306f5b3e121f1921633212a71bb0e6a8f7e15072741c17ab01d0618a3868b586929a24b26e7da9ffb1cc8ce65a21d7
7
+ data.tar.gz: 0be234d5ad98d851023497be7843ed11036089ee34df46433b81b0a61bcfd720a0fa16cc99919b0edfdc5ac16eea5a41debbd4fdc67c1c3d4e378e46ab9ad44a
data/README.md CHANGED
@@ -4,9 +4,6 @@ ZeroMQ Rails Active Job backend
4
4
  Why? Just for fun
5
5
 
6
6
 
7
- ## Usage
8
- How to use my plugin.
9
-
10
7
  ## Installation
11
8
  Add this line to your application's Gemfile:
12
9
 
@@ -14,18 +11,22 @@ Add this line to your application's Gemfile:
14
11
  gem "sidediq"
15
12
  ```
16
13
 
17
- And then execute:
14
+ And then install it:
18
15
  ```bash
19
- $ bundle
16
+ $ bundle install
20
17
  ```
21
18
 
22
- Or install it yourself as:
23
- ```bash
24
- $ gem install sidediq
19
+ ## Configuration
20
+
21
+ ```ruby
22
+ Sidediq.configure(
23
+ bind_address: "tcp://127.0.0.1:5555",
24
+ socket_type: "pull" # only "pull" is supported for now
25
+ )
25
26
  ```
26
27
 
27
28
  ## Contributing
28
- Contribution directions go here.
29
+ Fork and send a pull request
29
30
 
30
31
  ## License
31
32
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/sidediq CHANGED
@@ -1,9 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'ffi-rzmq'
4
- require 'json'
5
- require "sidediq/job"
6
-
7
3
  require File.expand_path("./config/environment.rb")
8
4
 
9
5
  if defined?(::Rails)
@@ -16,20 +12,7 @@ else
16
12
  raise "No Rails"
17
13
  end
18
14
 
19
- context = ZMQ::Context.new
20
- socket = context.socket(ZMQ::PULL)
21
- socket.bind("tcp://127.0.0.1:5555")
15
+ require_relative "../lib/sidediq/cli"
22
16
 
23
- print "Server is running and waiting for messages...\n"
24
17
 
25
- loop do
26
- msg = ""
27
- socket.recv_string(msg)
28
- puts "Server received: #{msg}"
29
- # socket.send_string("ACK: #{msg}", 0)
30
- job_data = JSON.parse(msg)
31
- Sidediq::Job.execute(job_data)
32
- end
33
- print "Server shutting down...\n"
34
- socket.close
35
- context.terminate
18
+ Sidediq::CLI.start
@@ -0,0 +1,48 @@
1
+
2
+ require 'ffi-rzmq'
3
+ require 'json'
4
+ require "sidediq/job"
5
+
6
+ module Sidediq
7
+ extend self
8
+
9
+ CONFIG = Sidediq::Configuration.new
10
+
11
+ def configure(hash = {})
12
+ CONFIG.config.merge!(hash)
13
+ end
14
+
15
+ class CLI
16
+ def self.start
17
+
18
+ pp CONFIG.config
19
+ socket_type = case CONFIG.config[:socket_type]
20
+ when "pull"
21
+ ZMQ::PULL
22
+ else
23
+ raise "Invalid socket type (only 'pull' is supported for now)"
24
+ end
25
+
26
+ socket_bind = CONFIG.config[:bind_address]
27
+
28
+ context = ZMQ::Context.new
29
+ socket = context.socket(socket_type)
30
+ socket.bind(socket_bind)
31
+
32
+ print "Server is running and waiting for messages...\n"
33
+
34
+ loop do
35
+ msg = ""
36
+ socket.recv_string(msg)
37
+ puts "Server received: #{msg}"
38
+ # socket.send_string("ACK: #{msg}", 0)
39
+ job_data = JSON.parse(msg)
40
+ Sidediq::Job.execute(job_data)
41
+ end
42
+ print "Server shutting down...\n"
43
+ socket.close
44
+ context.terminate
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,17 @@
1
+ module Sidediq
2
+ class Configuration
3
+ attr_reader :config
4
+
5
+ def initialize
6
+ @config = {}
7
+ end
8
+
9
+ # def method_missing(method, *args, &block)
10
+ # @config.send(method, *args, &block)
11
+ # end
12
+
13
+ # def respond_to_missing?(method, include_private = false)
14
+ # @config.respond_to?(method, include_private)
15
+ # end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Sidediq
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/sidediq.rb CHANGED
@@ -2,6 +2,8 @@ require "sidediq/version"
2
2
  require "sidediq/railtie"
3
3
  require "active_job"
4
4
  require "sidediq/job"
5
+ require "sidediq/configuration"
6
+ require "sidediq/cli"
5
7
 
6
8
  module Sidediq
7
9
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidediq
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
  - fobiasmog
@@ -37,6 +37,8 @@ files:
37
37
  - bin/sidediq
38
38
  - bin/test
39
39
  - lib/sidediq.rb
40
+ - lib/sidediq/cli.rb
41
+ - lib/sidediq/configuration.rb
40
42
  - lib/sidediq/job.rb
41
43
  - lib/sidediq/railtie.rb
42
44
  - lib/sidediq/version.rb