anway 0.1.1 → 0.2.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.
data/lib/anway/railtie.rb CHANGED
@@ -13,7 +13,16 @@ module Anway
13
13
  end
14
14
  end
15
15
 
16
+ # Pushes from the web go to the same server as the workers: the embedded
17
+ # one, or the url in config/anway.yml or ANWAY_URL. A url that the app
18
+ # sets in an initializer wins.
16
19
  config.after_initialize do |app|
20
+ path = app.root.join(Settings::DEFAULT_PATH)
21
+
22
+ settings = Settings.load(path: (path.to_s if path.exist?), environment: Rails.env)
23
+
24
+ Anway.config.url ||= settings.client_url
25
+ Anway.config.console_url ||= settings.console_url
17
26
  Anway.config.logger = Rails.logger if Rails.logger
18
27
  Anway.config.reloader = ->(&block) { app.reloader.wrap(&block) }
19
28
 
data/lib/anway/runner.rb CHANGED
@@ -16,10 +16,16 @@ module Anway
16
16
 
17
17
  attr_reader :wid
18
18
 
19
- def initialize(queues: ['default'], concurrency: 10, timeout: 25, cancel_grace: 5,
20
- labels: [], beat_interval: BEAT_INTERVAL, url: nil, logger: Anway.config.logger)
19
+ # The console shows the worker as hostname:pid with its tag. A nil
20
+ # hostname uses the machine name. The server can change the thread count
21
+ # in a BEAT reply, up to limit, such as the database pool size. autoscale,
22
+ # as { max: n } or { min: n, max: n }, starts the worker with autoscale on.
23
+ def initialize(queues: ['default'], concurrency: 10, timeout: 25, cancel_grace: 5, labels: [],
24
+ hostname: nil, tag: nil, autoscale: nil, limit: nil,
25
+ beat_interval: BEAT_INTERVAL, url: nil, logger: Anway.config.logger)
21
26
  @queues = Queues.new(queues)
22
27
  @concurrency = concurrency
28
+ @limit = limit
23
29
  @timeout = timeout
24
30
  @cancel_grace = cancel_grace
25
31
  @beat_interval = beat_interval
@@ -30,6 +36,8 @@ module Anway
30
36
  @events_reader, @events_writer = IO.pipe
31
37
  @running = {}
32
38
  @lock = Mutex.new
39
+ @processors = []
40
+ @retiring = 0
33
41
 
34
42
  @client = Client.new(
35
43
  url || Anway.config.url,
@@ -37,7 +45,11 @@ module Anway
37
45
  timeout: Anway.config.timeout,
38
46
  tls: Anway.config.tls,
39
47
  wid: @wid,
40
- labels: ['ruby', *labels]
48
+ labels: ['ruby', *labels],
49
+ identity: {
50
+ hostname: hostname, tag: tag, queues: @queues.names, concurrency: concurrency,
51
+ autoscale: autoscale, max_concurrency: limit
52
+ }
41
53
  )
42
54
  end
43
55
 
@@ -56,10 +68,12 @@ module Anway
56
68
  signal('d')
57
69
  end
58
70
 
71
+ # The first beat reports the threads, so the server can scale the worker
72
+ # at once.
59
73
  def run
60
- @client.beat
74
+ @client.heartbeat(nil, concurrency: @concurrency)
61
75
 
62
- @processors = Array.new(@concurrency) { start_processor }
76
+ @lock.synchronize { @processors = Array.new(@concurrency) { start_processor } }
63
77
 
64
78
  beat_thread = start_beat
65
79
 
@@ -123,7 +137,14 @@ module Anway
123
137
  end
124
138
 
125
139
  def beat(state)
126
- case @client.beat(state)
140
+ reply = @client.heartbeat(state, concurrency: @concurrency)
141
+
142
+ # A new count goes to the server at once, not at the next beat, so the
143
+ # console shows the threads that run, and the next autoscale step starts
144
+ # from them.
145
+ @client.heartbeat(state, concurrency: @concurrency) if reply.concurrency && resize(reply.concurrency)
146
+
147
+ case reply.state
127
148
  when 'quiet'
128
149
  quiet
129
150
 
@@ -141,6 +162,48 @@ module Anway
141
162
  state
142
163
  end
143
164
 
165
+ # Starts threads, or asks threads to stop after their job. A stop that is
166
+ # still pending is canceled first, so the count is right at once. Returns
167
+ # true when the count changed.
168
+ def resize(size)
169
+ return unless size.is_a?(Integer) && size.positive? && fetching?
170
+
171
+ size = [size, @limit].min if @limit
172
+
173
+ @lock.synchronize do
174
+ change = size - @concurrency
175
+
176
+ return if change.zero?
177
+
178
+ if change.positive?
179
+ kept = [@retiring, change].min
180
+
181
+ @retiring -= kept
182
+ @client.grow_pool(size + 1)
183
+ @processors.select!(&:alive?)
184
+ (change - kept).times { @processors << start_processor }
185
+ else
186
+ @retiring -= change
187
+ end
188
+
189
+ @concurrency = size
190
+ end
191
+
192
+ @logger.info("anway threads=#{size}")
193
+
194
+ true
195
+ end
196
+
197
+ def retire?
198
+ @lock.synchronize do
199
+ return false unless @retiring.positive?
200
+
201
+ @retiring -= 1
202
+
203
+ true
204
+ end
205
+ end
206
+
144
207
  # Shutdown stays pending outside perform, so it cannot break a report.
145
208
  def start_processor
146
209
  Thread.new do
@@ -150,7 +213,7 @@ module Anway
150
213
 
151
214
  # A fetch in progress is not canceled, because its reply can hold a job.
152
215
  def process_loop
153
- while fetching?
216
+ while fetching? && !retire?
154
217
  started = monotonic
155
218
  job = fetch_next
156
219
 
@@ -249,7 +312,9 @@ module Anway
249
312
  def join_processors(limit)
250
313
  deadline = monotonic + limit
251
314
 
252
- @processors.all? { |thread| thread.join([deadline - monotonic, 0].max) }
315
+ threads = @lock.synchronize { @processors.dup }
316
+
317
+ threads.all? { |thread| thread.join([deadline - monotonic, 0].max) }
253
318
  end
254
319
 
255
320
  def monotonic
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Anway
6
+ # Server runs the anway server binary that the platform gem carries.
7
+ # ANWAY_SERVER_PATH names another binary.
8
+ class Server < Daemon
9
+ BUNDLED = File.expand_path('../../libexec/anway-server', __dir__)
10
+
11
+ def self.executable(env = ENV)
12
+ override = env['ANWAY_SERVER_PATH'].to_s.strip
13
+
14
+ return override unless override.empty?
15
+ return BUNDLED if File.executable?(BUNDLED)
16
+
17
+ raise Error, "this install of anway has no server for #{Gem::Platform.local}. " \
18
+ 'Set ANWAY_SERVER_PATH to an anway server binary, or set url to use a server that runs apart.'
19
+ end
20
+
21
+ private
22
+
23
+ def name
24
+ 'server'
25
+ end
26
+
27
+ def address
28
+ @settings.bind
29
+ end
30
+
31
+ def env
32
+ @settings.server_env
33
+ end
34
+
35
+ def executable
36
+ self.class.executable
37
+ end
38
+
39
+ def prepare
40
+ FileUtils.mkdir_p(@settings.data)
41
+ end
42
+
43
+ def announce
44
+ @logger.info("anway: embedded server on #{@settings.bind}, data in #{@settings.data}. " \
45
+ 'On more than one host, run one server and set ANWAY_URL.')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'securerandom'
5
+ require 'yaml'
6
+
7
+ module Anway
8
+ # Settings reads config/anway.yml. The keys at the top apply to every
9
+ # environment, and the section of the current environment overrides them.
10
+ #
11
+ # queues: [critical, default]
12
+ # concurrency: 10
13
+ #
14
+ # production:
15
+ # url: <%= ENV["ANWAY_URL"] %>
16
+ #
17
+ # The server is embedded, so the app runs it, unless a url is set in the
18
+ # file or in ANWAY_URL. `server: { mode: }` or ANWAY_SERVER can still choose.
19
+ class Settings
20
+ DEFAULT_PATH = 'config/anway.yml'
21
+ DEFAULT_BIND = '127.0.0.1:7419'
22
+ DEFAULT_DATA = 'storage/anway'
23
+ DEFAULT_WEB = '127.0.0.1:7420'
24
+ DEFAULT_CONSOLE = '127.0.0.1:7421'
25
+ MODES = %w[embedded external].freeze
26
+ KEYS = %w[queues concurrency timeout labels hostname tag autoscale require url server console].freeze
27
+ SERVER_KEYS = %w[mode bind data password web web_token].freeze
28
+ CONSOLE_KEYS = %w[path bind api token].freeze
29
+
30
+ def self.environment(env = ENV)
31
+ env['RAILS_ENV'] || env['APP_ENV'] || env['RACK_ENV'] || 'development'
32
+ end
33
+
34
+ # A missing file is fine, unless the caller named it.
35
+ def self.load(path: nil, environment: nil, env: ENV)
36
+ file = path || DEFAULT_PATH
37
+
38
+ raise ArgumentError, "config file not found: #{file}" if path && !File.exist?(file)
39
+
40
+ content = File.exist?(file) ? YAML.safe_load(ERB.new(File.read(file)).result, aliases: true) : {}
41
+
42
+ new(content || {}, environment: environment || self.environment(env), env: env)
43
+ end
44
+
45
+ def initialize(content, environment:, env: ENV)
46
+ section = content[environment].is_a?(Hash) ? content[environment] : {}
47
+
48
+ @values = content.slice(*KEYS).merge(section.slice(*KEYS))
49
+ @server = section_of(content, 'server', SERVER_KEYS).merge(section_of(section, 'server', SERVER_KEYS))
50
+ @console = section_of(content, 'console', CONSOLE_KEYS).merge(section_of(section, 'console', CONSOLE_KEYS))
51
+ @env = env
52
+
53
+ check!
54
+ end
55
+
56
+ # Options for the worker, as the CLI names them.
57
+ # ANWAY_HOSTNAME and ANWAY_TAG come before the file.
58
+ def worker_options
59
+ options = @values.slice('queues', 'concurrency', 'timeout', 'labels', 'hostname', 'tag', 'require').transform_keys(&:to_sym)
60
+
61
+ options[:hostname] = present(@env['ANWAY_HOSTNAME']) || present(options[:hostname])
62
+ options[:tag] = present(@env['ANWAY_TAG']) || present(options[:tag])
63
+ options[:autoscale] = autoscale
64
+
65
+ options.compact
66
+ end
67
+
68
+ # autoscale: { max: n } or { min: n, max: n }, or nil when it is off.
69
+ def autoscale
70
+ value = @values['autoscale']
71
+
72
+ return nil unless value.is_a?(Hash)
73
+
74
+ value.slice('min', 'max').transform_keys(&:to_sym)
75
+ end
76
+
77
+ # The url of a server that runs apart: from the file, then from ANWAY_URL.
78
+ def url
79
+ present(@values['url']) || present(@env['ANWAY_URL'])
80
+ end
81
+
82
+ def mode
83
+ present(@env['ANWAY_SERVER']) || present(@server['mode']) || (url ? 'external' : 'embedded')
84
+ end
85
+
86
+ def embedded?
87
+ mode == 'embedded'
88
+ end
89
+
90
+ def bind
91
+ present(@server['bind']) || DEFAULT_BIND
92
+ end
93
+
94
+ def data
95
+ present(@server['data']) || DEFAULT_DATA
96
+ end
97
+
98
+ def password
99
+ present(@server['password'])
100
+ end
101
+
102
+ # The url that clients in this app use: the external server, or the
103
+ # embedded one on its local address.
104
+ def client_url
105
+ return url unless embedded?
106
+
107
+ host, port = split_bind
108
+ auth = password ? ":#{password}@" : ''
109
+
110
+ "tcp://#{auth}#{Daemon.local_host(host)}:#{port}"
111
+ end
112
+
113
+ # The address of the HTTP API that the web console reads. It is off
114
+ # unless it is set, or the console runs next to an embedded server.
115
+ def web
116
+ present(@server['web']) || (console? && embedded? ? DEFAULT_WEB : nil)
117
+ end
118
+
119
+ # Without a token in the file, the server and the console that this
120
+ # process starts share a random one.
121
+ def web_token
122
+ present(@server['web_token']) || (web ? (@random_token ||= SecureRandom.hex(16)) : nil)
123
+ end
124
+
125
+ # A random token changes at each start, so a server or console from an
126
+ # earlier start does not accept it.
127
+ def random_web_token?
128
+ !web.nil? && present(@server['web_token']).nil?
129
+ end
130
+
131
+ # The web console binary: ANWAY_CONSOLE_PATH, then console.path.
132
+ def console_path
133
+ path = present(@env['ANWAY_CONSOLE_PATH']) || present(@console['path'])
134
+
135
+ path && File.expand_path(path)
136
+ end
137
+
138
+ def console?
139
+ !console_path.nil?
140
+ end
141
+
142
+ def console_bind
143
+ present(@console['bind']) || DEFAULT_CONSOLE
144
+ end
145
+
146
+ # The address where `mount Anway::Web` finds the console.
147
+ def console_url
148
+ host, port = split(console_bind)
149
+
150
+ "http://#{Daemon.local_host(host)}:#{port}"
151
+ end
152
+
153
+ # The HTTP API that the console reads: console.api, or the API of the
154
+ # embedded server.
155
+ def console_api
156
+ return present(@console['api']) if present(@console['api'])
157
+ return nil unless web
158
+
159
+ host, port = split(web)
160
+
161
+ "http://#{Daemon.local_host(host)}:#{port}"
162
+ end
163
+
164
+ def console_env
165
+ host, port = split(console_bind)
166
+
167
+ { 'HOST' => host, 'PORT' => port, 'ANWAY_API_URL' => console_api, 'WEB_TOKEN' => present(@console['token']) || web_token.to_s }
168
+ end
169
+
170
+ # The environment of the server binary.
171
+ def server_env
172
+ env = { 'BIND_ADDR' => bind, 'DATA_DIR' => File.expand_path(data) }
173
+
174
+ env['SERVER_PASSWORD'] = password if password
175
+ env['WEB_ADDR'] = web if web
176
+ env['WEB_TOKEN'] = web_token if web_token
177
+
178
+ env
179
+ end
180
+
181
+ private
182
+
183
+ def section_of(hash, name, keys)
184
+ value = hash[name]
185
+
186
+ return {} if value.nil?
187
+
188
+ raise ArgumentError, "#{name} must be a hash of #{keys.join(', ')}" unless value.is_a?(Hash)
189
+
190
+ value.slice(*keys)
191
+ end
192
+
193
+ def check!
194
+ check_autoscale!
195
+ raise ArgumentError, "server mode must be embedded or external, not #{mode}" unless MODES.include?(mode)
196
+ raise ArgumentError, 'an external server needs url or ANWAY_URL' if mode == 'external' && url.nil?
197
+ raise ArgumentError, "server bind must be host:port, not #{bind}" unless split_bind.last.to_s.match?(/\A\d+\z/)
198
+ raise ArgumentError, "console bind must be host:port, not #{console_bind}" unless split(console_bind).last.to_s.match?(/\A\d+\z/)
199
+ raise ArgumentError, 'the console needs a server API: set server.web, or console.api' if console? && console_api.nil?
200
+ end
201
+
202
+ def check_autoscale!
203
+ value = @values['autoscale']
204
+
205
+ return if value.nil?
206
+
207
+ message = 'autoscale must be a hash with max, and min if you want, as positive numbers'
208
+
209
+ raise ArgumentError, message unless value.is_a?(Hash) && value['max'].is_a?(Integer) && value['max'].positive?
210
+ raise ArgumentError, message unless value['min'].nil? || (value['min'].is_a?(Integer) && value['min'].between?(1, value['max']))
211
+ end
212
+
213
+ def split_bind
214
+ split(bind)
215
+ end
216
+
217
+ def split(address)
218
+ host, _, port = address.rpartition(':')
219
+
220
+ [host, port]
221
+ end
222
+
223
+ def present(value)
224
+ text = value.to_s.strip
225
+
226
+ text.empty? ? nil : text
227
+ end
228
+ end
229
+ end
data/lib/anway/version.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anway
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
+
6
+ # The anway server that the platform gems carry, and that CI tests against.
7
+ SERVER_VERSION = '0.2.2'
5
8
  end
data/lib/anway/web.rb ADDED
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module Anway
7
+ # Web serves the Anway console inside a Rack app, such as Rails:
8
+ #
9
+ # authenticate :user, ->(user) { user.admin? } do
10
+ # mount Anway::Web => '/anway'
11
+ # end
12
+ #
13
+ # It proxies to the console process, which bin/anway starts when
14
+ # config/anway.yml sets console.path. The console gets the mount path in
15
+ # X-Forwarded-Prefix, and the browser host, so its links, redirects, and
16
+ # CSRF check work under the path. Cookies and Authorization stay in the app.
17
+ class Web
18
+ METHODS = %w[GET HEAD POST].freeze
19
+ DROPPED = %w[connection keep-alive proxy-authenticate proxy-authorization te trailer transfer-encoding upgrade content-length].freeze
20
+ PRIVATE = %w[HTTP_COOKIE HTTP_AUTHORIZATION HTTP_HOST HTTP_VERSION HTTP_CONNECTION].freeze
21
+
22
+ def self.call(env)
23
+ new.call(env)
24
+ end
25
+
26
+ def initialize(target = nil)
27
+ @target = target
28
+ end
29
+
30
+ def call(env)
31
+ return [405, { 'content-type' => 'text/plain', 'allow' => METHODS.join(', ') }, ['Method not allowed']] unless METHODS.include?(env['REQUEST_METHOD'])
32
+
33
+ response = forward(env)
34
+ headers = {}
35
+
36
+ response.each_header { |name, value| headers[name] = value unless DROPPED.include?(name) }
37
+
38
+ [response.code.to_i, headers, [response.body.to_s]]
39
+ rescue SystemCallError, IOError, Net::OpenTimeout, Net::ReadTimeout, SocketError
40
+ [502, { 'content-type' => 'text/html; charset=utf-8' }, [unavailable]]
41
+ end
42
+
43
+ private
44
+
45
+ def target
46
+ URI(@target || Anway.config.console_url || Settings.load.console_url)
47
+ end
48
+
49
+ def forward(env)
50
+ base = target
51
+ path = env['PATH_INFO'].to_s
52
+ path = '/' if path.empty?
53
+ query = env['QUERY_STRING'].to_s
54
+ request = Net::HTTPGenericRequest.new(env['REQUEST_METHOD'], env['REQUEST_METHOD'] == 'POST', env['REQUEST_METHOD'] != 'HEAD', query.empty? ? path : "#{path}?#{query}")
55
+
56
+ copy_headers(env, request)
57
+
58
+ if env['REQUEST_METHOD'] == 'POST'
59
+ request.body = body_of(env)
60
+ request['content-type'] = env['CONTENT_TYPE'] if env['CONTENT_TYPE']
61
+ end
62
+
63
+ Net::HTTP.start(base.host, base.port, open_timeout: 2, read_timeout: 30) { |http| http.request(request) }
64
+ end
65
+
66
+ # Rails reads a form post before the mount, in Rack::MethodOverride, so
67
+ # the input is at its end. It rewinds the input, and uses the raw form that
68
+ # Rack keeps when the input cannot rewind.
69
+ def body_of(env)
70
+ input = env['rack.input']
71
+
72
+ input.rewind if input.respond_to?(:rewind)
73
+
74
+ body = input&.read.to_s
75
+
76
+ body.empty? ? env['rack.request.form_vars'].to_s : body
77
+ end
78
+
79
+ def copy_headers(env, request)
80
+ env.each do |key, value|
81
+ next unless key.start_with?('HTTP_') && !PRIVATE.include?(key)
82
+
83
+ request[key.delete_prefix('HTTP_').split('_').map(&:capitalize).join('-')] = value
84
+ end
85
+
86
+ request['host'] = env['HTTP_HOST'] || "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}"
87
+ request['x-forwarded-prefix'] = env['SCRIPT_NAME'].to_s
88
+ request['x-forwarded-proto'] = env['rack.url_scheme'].to_s
89
+ request['accept-encoding'] = 'identity'
90
+ end
91
+
92
+ def unavailable
93
+ <<~HTML
94
+ <!doctype html>
95
+ <title>Anway console</title>
96
+ <div style="font-family:system-ui,sans-serif;max-width:560px;margin:15vh auto;padding:0 16px;line-height:1.5">
97
+ <h1 style="font-size:20px">The Anway console is not running</h1>
98
+ <p>Set <code>console.path</code> in <code>config/anway.yml</code> to the console binary. Then <code>bin/anway</code>, or Puma with <code>plugin :anway</code>, starts it next to the server.</p>
99
+ <p>To run it apart, use <code>bin/anway console</code>, and set <code>console.bind</code> to its address.</p>
100
+ </div>
101
+ HTML
102
+ end
103
+ end
104
+ end
data/lib/anway.rb CHANGED
@@ -11,6 +11,12 @@ require_relative 'anway/worker'
11
11
  require_relative 'anway/executor'
12
12
  require_relative 'anway/queues'
13
13
  require_relative 'anway/runner'
14
+ require_relative 'anway/settings'
15
+ require_relative 'anway/daemon'
16
+ require_relative 'anway/server'
17
+ require_relative 'anway/console'
18
+ require_relative 'anway/web'
19
+ require_relative 'anway/puma/plugin'
14
20
  require_relative 'anway/railtie' if defined?(Rails::Railtie)
15
21
 
16
22
  module Anway
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ module Anway
6
+ module Generators
7
+ # bin/rails generate anway:install [--active-job]
8
+ class InstallGenerator < Rails::Generators::Base
9
+ PUMA_LINE = 'plugin :anway'
10
+
11
+ source_root File.expand_path('templates', __dir__)
12
+
13
+ class_option :active_job, type: :boolean, default: false, desc: 'Use Anway as the Active Job adapter'
14
+
15
+ def create_settings
16
+ copy_file 'anway.yml', 'config/anway.yml'
17
+ end
18
+
19
+ def create_binstub
20
+ copy_file 'anway', 'bin/anway'
21
+ chmod 'bin/anway', 0o755
22
+ end
23
+
24
+ def add_puma_plugin
25
+ path = File.join(destination_root, 'config/puma.rb')
26
+
27
+ return unless File.exist?(path)
28
+ return if File.read(path).include?(PUMA_LINE)
29
+
30
+ append_to_file 'config/puma.rb', <<~RUBY
31
+
32
+ # Runs Anway next to Puma: the embedded server and the workers. ANWAY_IN_PUMA
33
+ # turns it on or off. Without it, it runs only in development.
34
+ #{PUMA_LINE}
35
+ RUBY
36
+ end
37
+
38
+ # The mount stays a comment: it needs a console binary, and the app must
39
+ # choose who can open it.
40
+ def add_console_route
41
+ path = File.join(destination_root, 'config/routes.rb')
42
+
43
+ return unless File.exist?(path)
44
+ return if File.read(path).include?('Anway::Web')
45
+
46
+ route <<~RUBY.chomp
47
+ # The Anway console. It needs console.path in config/anway.yml. Limit it to admins:
48
+ # authenticate :user, ->(user) { user.admin? } do
49
+ # mount Anway::Web => "/anway"
50
+ # end
51
+ RUBY
52
+ end
53
+
54
+ def set_active_job_adapter
55
+ return unless options[:active_job]
56
+
57
+ application 'config.active_job.queue_adapter = :anway'
58
+ end
59
+
60
+ def show_next_steps
61
+ say <<~TEXT
62
+
63
+ Anway is installed.
64
+
65
+ bin/dev Puma starts the Anway server and workers in development
66
+ bin/anway the server and workers, without Puma
67
+ bin/anway worker only workers, for a server that runs apart
68
+
69
+ Jobs: include Anway::Worker in a class#{options[:active_job] ? ', or use Active Job' : ', or run the generator with --active-job'}.
70
+ TEXT
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # bin/anway the embedded server, when config/anway.yml has no url, and workers
5
+ # bin/anway server only the server
6
+ # bin/anway worker only workers
7
+ Dir.chdir(File.expand_path('..', __dir__))
8
+
9
+ require_relative '../config/boot'
10
+ require 'anway/cli'
11
+
12
+ exit Anway::CLI.new(ARGV).run
@@ -0,0 +1,32 @@
1
+ # Anway settings. Keys at the top apply to every environment, and an
2
+ # environment section overrides them.
3
+ #
4
+ # Without url, this app runs the Anway server itself (embedded), with its
5
+ # data in storage/anway. Set url, or ANWAY_URL, to use a server that runs
6
+ # apart. On more than one host, run one server and set ANWAY_URL everywhere.
7
+
8
+ queues: [default]
9
+ concurrency: 10
10
+
11
+ # The console shows each worker as hostname:pid with a tag. The tag is the
12
+ # app folder by default. ANWAY_HOSTNAME and ANWAY_TAG override these.
13
+ # hostname: worker.1
14
+ # tag: my_app
15
+
16
+ # Autoscale adds threads while jobs wait, up to max, and removes them when
17
+ # the load drops. Keep max at or below the database pool of the worker.
18
+ # autoscale:
19
+ # max: 20
20
+
21
+ # The web console. bin/anway starts it next to the server, and
22
+ # `mount Anway::Web` in config/routes.rb serves it in the app.
23
+ # console:
24
+ # path: /path/to/anway-webui
25
+
26
+ production:
27
+ # url: <%= ENV["ANWAY_URL"] %>
28
+ #
29
+ # To accept workers from other hosts on the embedded server:
30
+ # server:
31
+ # bind: 0.0.0.0:7419
32
+ # password: <%= ENV["ANWAY_PASSWORD"] %>