sidediq 0.1.0
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 +7 -0
- data/README.md +31 -0
- data/Rakefile +3 -0
- data/bin/rubocop +8 -0
- data/bin/sidediq +35 -0
- data/bin/test +5 -0
- data/lib/sidediq/job.rb +24 -0
- data/lib/sidediq/railtie.rb +4 -0
- data/lib/sidediq/version.rb +3 -0
- data/lib/sidediq.rb +89 -0
- data/lib/tasks/sidediq_tasks.rake +4 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6cf7c6bec3aabc4f5089e19f24099003429a48b5f651facea8ee151fa443ae5d
|
|
4
|
+
data.tar.gz: 6c67538e0da4f6ff47087d2868e1376bf0682f316d6742c298abbc0bd5471651
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9554b0306cc5689c2ce259ea0a7d8a8be91fd3e7dc07ea65551c68e75c79f67cd761dd8161e6ed4986baf530e656b2070134902d63f4fc758d9eb26c89cef84b
|
|
7
|
+
data.tar.gz: 501f0cea9bd699592748772fdb4b83fc0886e3d36ced47daa843ade65e07760e0c85db339967641cb529b6789e6489dc083c16d2a5e336d7d19719079efacb9f
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Sidediq
|
|
2
|
+
ZeroMQ Rails Active Job backend
|
|
3
|
+
|
|
4
|
+
Why? Just for fun
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
How to use my plugin.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "sidediq"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
```bash
|
|
19
|
+
$ bundle
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
```bash
|
|
24
|
+
$ gem install sidediq
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
Contribution directions go here.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/rubocop
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "rubygems"
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
|
|
5
|
+
# explicit rubocop config increases performance slightly while avoiding config confusion.
|
|
6
|
+
ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))
|
|
7
|
+
|
|
8
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/sidediq
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'ffi-rzmq'
|
|
4
|
+
require 'json'
|
|
5
|
+
require "sidediq/job"
|
|
6
|
+
|
|
7
|
+
require File.expand_path("./config/environment.rb")
|
|
8
|
+
|
|
9
|
+
if defined?(::Rails)
|
|
10
|
+
if Rails.autoloaders.zeitwerk_enabled?
|
|
11
|
+
::Zeitwerk::Loader.eager_load_all
|
|
12
|
+
else
|
|
13
|
+
::Rails.application.eager_load!
|
|
14
|
+
end
|
|
15
|
+
else
|
|
16
|
+
raise "No Rails"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context = ZMQ::Context.new
|
|
20
|
+
socket = context.socket(ZMQ::PULL)
|
|
21
|
+
socket.bind("tcp://127.0.0.1:5555")
|
|
22
|
+
|
|
23
|
+
print "Server is running and waiting for messages...\n"
|
|
24
|
+
|
|
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
|
data/bin/test
ADDED
data/lib/sidediq/job.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'ffi-rzmq'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'active_job'
|
|
4
|
+
|
|
5
|
+
module Sidediq
|
|
6
|
+
class Job
|
|
7
|
+
class << self
|
|
8
|
+
def perform(job_data, at: nil)
|
|
9
|
+
context = ZMQ::Context.new
|
|
10
|
+
socket = context.socket(ZMQ::PUSH)
|
|
11
|
+
socket.connect("tcp://127.0.0.1:5555")
|
|
12
|
+
|
|
13
|
+
res = socket.send_string(JSON.dump(job_data), ZMQ::DONTWAIT)
|
|
14
|
+
puts "Client received: #{res}"
|
|
15
|
+
socket.close
|
|
16
|
+
context.terminate
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def execute(...)
|
|
20
|
+
ActiveJob::Base.execute(...)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/sidediq.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require "sidediq/version"
|
|
2
|
+
require "sidediq/railtie"
|
|
3
|
+
require "active_job"
|
|
4
|
+
require "sidediq/job"
|
|
5
|
+
|
|
6
|
+
module Sidediq
|
|
7
|
+
class << self
|
|
8
|
+
def enqueue(job)
|
|
9
|
+
serialized = job.serialize
|
|
10
|
+
Sidediq::Job.perform(serialized)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Serializer
|
|
15
|
+
extend ActiveSupport::Concern
|
|
16
|
+
|
|
17
|
+
module ClassMethods
|
|
18
|
+
def serializer(klass=nil, &block)
|
|
19
|
+
self.serializer_block = block if block_given?
|
|
20
|
+
self.serializer_class = klass
|
|
21
|
+
end
|
|
22
|
+
def deserializer(klass=nil)
|
|
23
|
+
self.deserializer_class = klass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
included do
|
|
28
|
+
class_attribute :serializer_block
|
|
29
|
+
class_attribute :serializer_class
|
|
30
|
+
class_attribute :deserializer_class
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
module ActiveJob
|
|
37
|
+
class Base
|
|
38
|
+
include Sidediq::Serializer
|
|
39
|
+
|
|
40
|
+
def initialize(...)
|
|
41
|
+
@serializer_block = self.class.serializer_block
|
|
42
|
+
@serializer_class = self.class.serializer_class
|
|
43
|
+
@deserializer_class = self.class.deserializer_class or self.class.serializer_class
|
|
44
|
+
super(...)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module Core
|
|
49
|
+
private
|
|
50
|
+
def serialize_arguments(args)
|
|
51
|
+
case [serializer_block, serializer_class]
|
|
52
|
+
when [true, true]
|
|
53
|
+
message_data = serializer_block.call(*args)
|
|
54
|
+
serializer_class.encode(
|
|
55
|
+
serializer_class.new(message_data)
|
|
56
|
+
)
|
|
57
|
+
when [true, false]
|
|
58
|
+
serializer_block.call(*args)
|
|
59
|
+
when [false, true]
|
|
60
|
+
serializer_class.encode(
|
|
61
|
+
serializer_class.new(*args)
|
|
62
|
+
)
|
|
63
|
+
else
|
|
64
|
+
raise NotImplementedError
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def deserialize_arguments(arguments)
|
|
69
|
+
raise NotImplementedError unless deserializer_class
|
|
70
|
+
[
|
|
71
|
+
Hash.ruby2_keywords_hash(
|
|
72
|
+
deserializer_class.decode(arguments).to_hash
|
|
73
|
+
)
|
|
74
|
+
]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
module QueueAdapters
|
|
79
|
+
class SidediqAdapter
|
|
80
|
+
def enqueue(job)
|
|
81
|
+
Sidediq.enqueue(job)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def enqueue_at(job, timestamp)
|
|
85
|
+
raise NotImplementedError, "Sidediq does not support scheduled jobs"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sidediq
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- fobiasmog
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 8.0.4
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 8.0.4
|
|
26
|
+
description: Like Sidekiq but diq, made just for fun.
|
|
27
|
+
email:
|
|
28
|
+
- zbrejkin@yandex.ru
|
|
29
|
+
executables:
|
|
30
|
+
- sidediq
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- README.md
|
|
35
|
+
- Rakefile
|
|
36
|
+
- bin/rubocop
|
|
37
|
+
- bin/sidediq
|
|
38
|
+
- bin/test
|
|
39
|
+
- lib/sidediq.rb
|
|
40
|
+
- lib/sidediq/job.rb
|
|
41
|
+
- lib/sidediq/railtie.rb
|
|
42
|
+
- lib/sidediq/version.rb
|
|
43
|
+
- lib/tasks/sidediq_tasks.rake
|
|
44
|
+
homepage: https://github.com/fobiasmog/sidediq
|
|
45
|
+
licenses: []
|
|
46
|
+
metadata:
|
|
47
|
+
homepage_uri: https://github.com/fobiasmog/sidediq
|
|
48
|
+
source_code_uri: https://github.com/fobiasmog/sidediq
|
|
49
|
+
changelog_uri: https://github.com/fobiasmog/sidediq
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubygems_version: 3.7.2
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: 'Sidediq: ZeroMQ ActiveJob adapter for Ruby on Rails'
|
|
67
|
+
test_files: []
|