anway 0.5.2-x86_64-linux-gnu → 0.6.0-x86_64-linux-gnu
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 +4 -4
- data/README.md +117 -2
- data/lib/anway/api.rb +73 -0
- data/lib/anway/cli.rb +41 -4
- data/lib/anway/client.rb +17 -0
- data/lib/anway/configuration.rb +2 -1
- data/lib/anway/cron.rb +46 -0
- data/lib/anway/daemon.rb +1 -1
- data/lib/anway/inspect.rb +93 -0
- data/lib/anway/inspect_command.rb +143 -0
- data/lib/anway/job_info.rb +47 -0
- data/lib/anway/options.rb +7 -5
- data/lib/anway/runner.rb +88 -6
- data/lib/anway/server.rb +7 -0
- data/lib/anway/settings.rb +57 -7
- data/lib/anway/testing.rb +24 -1
- data/lib/anway/version.rb +2 -2
- data/lib/anway/worker.rb +29 -5
- data/lib/anway.rb +77 -0
- data/lib/generators/anway/install/templates/anway.yml +9 -0
- data/libexec/anway-server +0 -0
- metadata +6 -1
data/lib/anway.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative 'anway/version'
|
|
|
4
4
|
require_relative 'anway/errors'
|
|
5
5
|
require_relative 'anway/configuration'
|
|
6
6
|
require_relative 'anway/options'
|
|
7
|
+
require_relative 'anway/cron'
|
|
7
8
|
require_relative 'anway/job'
|
|
8
9
|
require_relative 'anway/connection'
|
|
9
10
|
require_relative 'anway/pool'
|
|
@@ -17,6 +18,10 @@ require_relative 'anway/daemon'
|
|
|
17
18
|
require_relative 'anway/server'
|
|
18
19
|
require_relative 'anway/console'
|
|
19
20
|
require_relative 'anway/web'
|
|
21
|
+
require_relative 'anway/api'
|
|
22
|
+
require_relative 'anway/job_info'
|
|
23
|
+
require_relative 'anway/inspect'
|
|
24
|
+
require_relative 'anway/inspect_command'
|
|
20
25
|
require_relative 'anway/puma/plugin'
|
|
21
26
|
require_relative 'anway/railtie' if defined?(Rails::Railtie)
|
|
22
27
|
|
|
@@ -113,11 +118,83 @@ module Anway
|
|
|
113
118
|
results
|
|
114
119
|
end
|
|
115
120
|
|
|
121
|
+
# Replaces all cron entries of the tag on the server. In a test mode,
|
|
122
|
+
# Anway::Testing keeps them in Testing.schedules.
|
|
123
|
+
#
|
|
124
|
+
# Anway.schedule('shop', [{ schedule: '0 0 * * *', job: { type: 'credits.refill' } }])
|
|
125
|
+
def schedule(tag, entries)
|
|
126
|
+
testing = const_defined?(:Testing) ? Testing : nil
|
|
127
|
+
|
|
128
|
+
return testing.schedule(tag, entries) if testing&.mode
|
|
129
|
+
|
|
130
|
+
client.schedule(tag, entries)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Removes all cron entries of the tag. A missing tag is not an error.
|
|
134
|
+
def unschedule(tag)
|
|
135
|
+
testing = const_defined?(:Testing) ? Testing : nil
|
|
136
|
+
|
|
137
|
+
return testing.unschedule(tag) if testing&.mode
|
|
138
|
+
|
|
139
|
+
client.unschedule(tag)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# The cron entries that the worker sends with SCHEDULE when it starts:
|
|
143
|
+
# those of the job classes (anway_options cron:), then those of the cron
|
|
144
|
+
# key of config/anway.yml, with no duplicates. An app spec can check its
|
|
145
|
+
# declarations with it.
|
|
146
|
+
def cron(settings = Settings.load)
|
|
147
|
+
(Worker.cron_entries + settings.cron).uniq
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# The jobs on the server. With no set, a summary of each set. With a set
|
|
151
|
+
# (:waiting, :working, :retries, :scheduled, :dead or "queue:name"), an
|
|
152
|
+
# Enumerable of JobInfo that reads pages only as far as it is read.
|
|
153
|
+
#
|
|
154
|
+
# Anway.jobs
|
|
155
|
+
# Anway.jobs(set: :retries, type: "EmitInvoiceJob").first(5)
|
|
156
|
+
def jobs(set: nil, type: nil, queue: nil)
|
|
157
|
+
if fake_testing?
|
|
158
|
+
infos = Inspect.fake(Testing.jobs)
|
|
159
|
+
|
|
160
|
+
return set ? infos.select { |info| set.to_s == 'waiting' && (type.nil? || info.name.include?(type.to_s)) && (queue.nil? || info.queue == queue) } : Inspect::Summary.new(sets: [{ set: 'waiting', count: infos.size }])
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
return Inspect.summary(api) unless set
|
|
164
|
+
|
|
165
|
+
Inspect::Jobs.new(api, set: set, type: type, queue: queue)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# One job by its jid, as JobInfo, or nil when it finished or never
|
|
169
|
+
# existed. Active Job sets provider_job_id to the jid:
|
|
170
|
+
#
|
|
171
|
+
# Anway.job(MyJob.perform_later(id).provider_job_id)
|
|
172
|
+
def job(jid)
|
|
173
|
+
return Inspect.fake(Testing.jobs).find { |info| info.jid == jid } if fake_testing?
|
|
174
|
+
|
|
175
|
+
reply = api.job(jid)
|
|
176
|
+
|
|
177
|
+
reply && JobInfo.from_api(reply['job'], set: reply['set'])
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# The HTTP API client for Anway.jobs and Anway.job.
|
|
181
|
+
def api
|
|
182
|
+
@api ||= Api.from_settings
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
attr_writer :api
|
|
186
|
+
|
|
116
187
|
def reset!
|
|
117
188
|
@lock.synchronize do
|
|
118
189
|
@client&.close
|
|
119
190
|
@client = nil
|
|
120
191
|
end
|
|
192
|
+
|
|
193
|
+
@api = nil
|
|
121
194
|
end
|
|
195
|
+
|
|
196
|
+
private
|
|
197
|
+
|
|
198
|
+
def fake_testing? = const_defined?(:Testing) && Testing.mode == :fake
|
|
122
199
|
end
|
|
123
200
|
end
|
|
@@ -18,6 +18,15 @@ concurrency: 10
|
|
|
18
18
|
# autoscale:
|
|
19
19
|
# max: 20
|
|
20
20
|
|
|
21
|
+
# Cron entries that the worker sends to the server when it starts, as the
|
|
22
|
+
# cron entries of the server conf.d. They need a tag. A job class can also
|
|
23
|
+
# declare them: anway_options cron: "0 0 * * *". Schedules use UTC.
|
|
24
|
+
# cron:
|
|
25
|
+
# - schedule: "0 0 * * *"
|
|
26
|
+
# job:
|
|
27
|
+
# type: credits.refill
|
|
28
|
+
# queue: default
|
|
29
|
+
|
|
21
30
|
# The web console. bin/anway starts it next to the server, and
|
|
22
31
|
# `mount Anway::Web` in config/routes.rb serves it in the app.
|
|
23
32
|
# console:
|
data/libexec/anway-server
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: anway
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: x86_64-linux-gnu
|
|
6
6
|
authors:
|
|
7
7
|
- Thadeu
|
|
@@ -33,15 +33,20 @@ files:
|
|
|
33
33
|
- exe/anway
|
|
34
34
|
- lib/active_job/queue_adapters/anway_adapter.rb
|
|
35
35
|
- lib/anway.rb
|
|
36
|
+
- lib/anway/api.rb
|
|
36
37
|
- lib/anway/cli.rb
|
|
37
38
|
- lib/anway/client.rb
|
|
38
39
|
- lib/anway/configuration.rb
|
|
39
40
|
- lib/anway/connection.rb
|
|
40
41
|
- lib/anway/console.rb
|
|
42
|
+
- lib/anway/cron.rb
|
|
41
43
|
- lib/anway/daemon.rb
|
|
42
44
|
- lib/anway/errors.rb
|
|
43
45
|
- lib/anway/executor.rb
|
|
46
|
+
- lib/anway/inspect.rb
|
|
47
|
+
- lib/anway/inspect_command.rb
|
|
44
48
|
- lib/anway/job.rb
|
|
49
|
+
- lib/anway/job_info.rb
|
|
45
50
|
- lib/anway/options.rb
|
|
46
51
|
- lib/anway/pool.rb
|
|
47
52
|
- lib/anway/puma/plugin.rb
|