soda-core 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/soda.rb +1 -0
- data/lib/soda/cli.rb +10 -1
- data/lib/soda/client.rb +25 -10
- data/lib/soda/extensions/active_job.rb +27 -0
- data/lib/soda/fetcher.rb +1 -1
- data/lib/soda/processor.rb +1 -1
- data/lib/soda/rails.rb +0 -1
- data/lib/soda/retrier.rb +1 -1
- data/lib/soda/version.rb +1 -1
- data/lib/soda/worker.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5890ee17efa45584d1824c9bb5afb701f1787da78afe0d493fa02ecf2d18d734
|
4
|
+
data.tar.gz: 75be3aff3d00251c90ab6c36f54638e00cc4f5852035a73ec315358f5084bbdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46fc65693b7dba0ce1e36da8cd12eef30025b443ac0c028430066d8d2b6e509503c091a5510298530ef04fd567c038ff474a272b77192d4f40d0cb72fef5ac0
|
7
|
+
data.tar.gz: 8c64c47b3c7c9452f002ef36182cf0ce55ba81cd8ae68584fdbf0dc578f268913d4b1d4926492d6d91652d0d6cf4772fec8ecd0bd1b153be98c2d4a4ef4040db
|
data/lib/soda.rb
CHANGED
data/lib/soda/cli.rb
CHANGED
@@ -23,10 +23,15 @@ module Soda
|
|
23
23
|
def run
|
24
24
|
build_options
|
25
25
|
|
26
|
+
logger.info("🥤 %s v%s" % [Soda::NAME, Soda::VERSION])
|
27
|
+
|
26
28
|
if rails?
|
27
29
|
if Rails::VERSION::MAJOR >= 5
|
30
|
+
require "./config/application.rb"
|
28
31
|
require "./config/environment.rb"
|
29
32
|
require "soda/rails"
|
33
|
+
require "soda/extensions/active_job"
|
34
|
+
|
30
35
|
logger.info("Loaded Rails v%s application." % ::Rails.version)
|
31
36
|
else
|
32
37
|
raise "Not compatible with Rails v%s!" % Rails.version
|
@@ -98,9 +103,13 @@ module Soda
|
|
98
103
|
opts.merge!(require: val)
|
99
104
|
end
|
100
105
|
|
101
|
-
o.on("-q", "--
|
106
|
+
o.on("-q", "--queue QUEUE[,WEIGHT]", "Queue to listen to, with optional weights") do |val|
|
102
107
|
opts.merge!(queues: opts.fetch(:queues, []).push(val.split(/\,+/)))
|
103
108
|
end
|
109
|
+
|
110
|
+
o.on("-c", "--concurrency [INT]", "Number of processor threads") do |val|
|
111
|
+
opts.merge!(concurrency: Integer(val))
|
112
|
+
end
|
104
113
|
end
|
105
114
|
end
|
106
115
|
|
data/lib/soda/client.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
module Soda
|
2
2
|
class Client
|
3
|
+
DEFAULTS = {
|
4
|
+
"retry" => true,
|
5
|
+
"delay" => 0,
|
6
|
+
}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def push(*args)
|
10
|
+
new.push(*args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
3
15
|
def push(item)
|
4
|
-
copy
|
5
|
-
mw = Soda.client_middleware
|
16
|
+
copy = normalize!(item)
|
6
17
|
|
18
|
+
mw = Soda.client_middleware
|
7
19
|
mw.use(item["klass"], copy, copy["queue"]) do
|
8
|
-
|
20
|
+
jid = copy["id"]
|
21
|
+
jid.tap do
|
22
|
+
queue = Soda.queue(copy["queue"])
|
9
23
|
queue.push_in(copy["delay"], Soda.dump_json(copy))
|
10
24
|
end
|
11
25
|
end
|
@@ -14,19 +28,20 @@ module Soda
|
|
14
28
|
private
|
15
29
|
|
16
30
|
def normalize!(item)
|
17
|
-
item
|
18
|
-
|
19
|
-
|
31
|
+
item = DEFAULTS.merge(item)
|
32
|
+
item.tap do
|
33
|
+
item.keys.each do |key|
|
34
|
+
item.merge!(String(key) => item.delete(key))
|
20
35
|
end
|
21
36
|
|
22
37
|
id = SecureRandom.base64(10)
|
23
|
-
klass =
|
24
|
-
delay =
|
25
|
-
queue =
|
38
|
+
klass = item["klass"].to_s
|
39
|
+
delay = item["delay"].to_i
|
40
|
+
queue = item["queue"] || Soda.default_queue!.name
|
26
41
|
|
27
42
|
# TODO: add validation
|
28
43
|
#
|
29
|
-
|
44
|
+
item.merge!(
|
30
45
|
"id" => id,
|
31
46
|
"klass" => klass,
|
32
47
|
"delay" => delay,
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveJob
|
2
|
+
module QueueAdapters
|
3
|
+
class SodaAdapter
|
4
|
+
def enqueue(job)
|
5
|
+
enqueue_at(job, Time.now)
|
6
|
+
end
|
7
|
+
|
8
|
+
def enqueue_at(job, ts)
|
9
|
+
job.provider_job_id = ::Soda::Client.push(
|
10
|
+
"klass" => JobWrapper,
|
11
|
+
"wrapped" => job.class,
|
12
|
+
"queue" => job.queue_name,
|
13
|
+
"delay" => [0, (ts - Time.now).to_i].max,
|
14
|
+
"args" => [job.serialize],
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
class JobWrapper
|
19
|
+
include ::Soda::Worker
|
20
|
+
|
21
|
+
def perform(data = {})
|
22
|
+
Base.execute(data.merge("provider_job_id" => id))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/soda/fetcher.rb
CHANGED
data/lib/soda/processor.rb
CHANGED
data/lib/soda/rails.rb
CHANGED
data/lib/soda/retrier.rb
CHANGED
data/lib/soda/version.rb
CHANGED
data/lib/soda/worker.rb
CHANGED
@@ -28,6 +28,7 @@ module Soda
|
|
28
28
|
)
|
29
29
|
end
|
30
30
|
end
|
31
|
+
alias_method :perform_at, :perform_in
|
31
32
|
|
32
33
|
private
|
33
34
|
|
@@ -70,6 +71,12 @@ module Soda
|
|
70
71
|
@options = options
|
71
72
|
end
|
72
73
|
|
74
|
+
%i[id].each do |method|
|
75
|
+
define_method(method) do
|
76
|
+
options.fetch(String(method))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
73
80
|
private
|
74
81
|
|
75
82
|
attr_reader :options
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soda-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Portes Chaikin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-sqs
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/soda.rb
|
64
64
|
- lib/soda/cli.rb
|
65
65
|
- lib/soda/client.rb
|
66
|
+
- lib/soda/extensions/active_job.rb
|
66
67
|
- lib/soda/fetcher.rb
|
67
68
|
- lib/soda/logger.rb
|
68
69
|
- lib/soda/manager.rb
|