faktory_worker_ruby 1.1.1 → 1.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.standard.yml +12 -0
- data/Changes.md +6 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +46 -20
- data/Rakefile +5 -4
- data/faktory_worker_ruby.gemspec +17 -19
- data/lib/active_job/queue_adapters/faktory_adapter.rb +10 -10
- data/lib/faktory/batch.rb +7 -7
- data/lib/faktory/cli.rb +51 -55
- data/lib/faktory/client.rb +46 -36
- data/lib/faktory/connection.rb +4 -3
- data/lib/faktory/exception_handler.rb +10 -13
- data/lib/faktory/fetch.rb +3 -4
- data/lib/faktory/io.rb +3 -2
- data/lib/faktory/job.rb +14 -15
- data/lib/faktory/job_logger.rb +0 -1
- data/lib/faktory/launcher.rb +12 -14
- data/lib/faktory/logging.rb +9 -9
- data/lib/faktory/manager.rb +8 -11
- data/lib/faktory/middleware/batch.rb +1 -0
- data/lib/faktory/middleware/chain.rb +3 -2
- data/lib/faktory/middleware/i18n.rb +2 -1
- data/lib/faktory/mutate.rb +10 -11
- data/lib/faktory/processor.rb +27 -31
- data/lib/faktory/rails.rb +49 -46
- data/lib/faktory/testing.rb +24 -26
- data/lib/faktory/tracking.rb +3 -4
- data/lib/faktory/util.rb +11 -12
- data/lib/faktory/version.rb +2 -1
- data/lib/faktory.rb +25 -21
- data/lib/faktory_worker_ruby.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57f98beb553cb8d38e36d45b1721c15446201a30db101827d277ef7f3b9fb542
|
4
|
+
data.tar.gz: a0d82206d826d345bdcde2271ccf300c8af2ccb7ce4c2140900f00b0330ebeac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed5afdc2c7d07f54b90eb1230d50b1d0bdfb219d3ac6f12d4c2f35c05eb7f0b73c3990c84d65c77567f127c1c082f6e858480165aa0bf1e697bef6aa81517075
|
7
|
+
data.tar.gz: 01ea007ff63b7e91a94cc7134f57d783680b9a2ba88be5677b93a505eb55d8e39d2cec9f53a3503b5270b2cfcf8a16909569082b19c59c6439d7474f402da7db
|
data/.github/workflows/ci.yml
CHANGED
@@ -2,16 +2,16 @@ name: CI
|
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
5
|
-
branches: [
|
5
|
+
branches: [ main ]
|
6
6
|
pull_request:
|
7
|
-
branches: [
|
7
|
+
branches: [ main ]
|
8
8
|
|
9
9
|
jobs:
|
10
10
|
test:
|
11
11
|
strategy:
|
12
12
|
fail-fast: false
|
13
13
|
matrix:
|
14
|
-
ruby: [2.
|
14
|
+
ruby: ["2.6", "2.7", "3.0", "3.1"]
|
15
15
|
runs-on: ubuntu-latest
|
16
16
|
services:
|
17
17
|
faktory:
|
data/.standard.yml
ADDED
data/Changes.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,52 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
faktory_worker_ruby (1.
|
4
|
+
faktory_worker_ruby (1.2.0)
|
5
5
|
connection_pool (~> 2.2, >= 2.2.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activejob (
|
11
|
-
activesupport (=
|
10
|
+
activejob (7.0.4.2)
|
11
|
+
activesupport (= 7.0.4.2)
|
12
12
|
globalid (>= 0.3.6)
|
13
|
-
activesupport (
|
13
|
+
activesupport (7.0.4.2)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
17
17
|
tzinfo (~> 2.0)
|
18
|
-
|
19
|
-
concurrent-ruby (1.
|
20
|
-
connection_pool (2.
|
18
|
+
ast (2.4.2)
|
19
|
+
concurrent-ruby (1.2.0)
|
20
|
+
connection_pool (2.3.0)
|
21
21
|
docile (1.4.0)
|
22
|
-
globalid (
|
23
|
-
activesupport (>=
|
24
|
-
i18n (1.
|
22
|
+
globalid (1.1.0)
|
23
|
+
activesupport (>= 5.0)
|
24
|
+
i18n (1.12.0)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
26
|
+
json (2.6.3)
|
27
|
+
language_server-protocol (3.17.0.3)
|
28
|
+
minitest (5.17.0)
|
27
29
|
minitest-hooks (1.5.0)
|
28
30
|
minitest (> 5.3)
|
29
|
-
|
30
|
-
|
31
|
+
parallel (1.22.1)
|
32
|
+
parser (3.2.0.0)
|
33
|
+
ast (~> 2.4.1)
|
34
|
+
rainbow (3.1.1)
|
35
|
+
rake (13.0.6)
|
36
|
+
regexp_parser (2.6.2)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rubocop (1.42.0)
|
39
|
+
json (~> 2.3)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 3.1.2.1)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.24.1)
|
49
|
+
parser (>= 3.1.1.0)
|
50
|
+
rubocop-performance (1.15.2)
|
51
|
+
rubocop (>= 1.7.0, < 2.0)
|
52
|
+
rubocop-ast (>= 0.4.0)
|
53
|
+
ruby-progressbar (1.11.0)
|
54
|
+
simplecov (0.22.0)
|
31
55
|
docile (~> 1.1)
|
32
56
|
simplecov-html (~> 0.11)
|
33
57
|
simplecov_json_formatter (~> 0.1)
|
34
58
|
simplecov-html (0.12.3)
|
35
|
-
simplecov_json_formatter (0.1.
|
36
|
-
|
59
|
+
simplecov_json_formatter (0.1.4)
|
60
|
+
standard (1.22.1)
|
61
|
+
language_server-protocol (~> 3.17.0.2)
|
62
|
+
rubocop (= 1.42.0)
|
63
|
+
rubocop-performance (= 1.15.2)
|
64
|
+
tzinfo (2.0.6)
|
37
65
|
concurrent-ruby (~> 1.0)
|
38
|
-
|
66
|
+
unicode-display_width (2.4.2)
|
39
67
|
|
40
68
|
PLATFORMS
|
41
69
|
ruby
|
42
70
|
|
43
71
|
DEPENDENCIES
|
44
|
-
activejob
|
72
|
+
activejob
|
45
73
|
faktory_worker_ruby!
|
46
74
|
minitest (~> 5)
|
47
75
|
minitest-hooks
|
48
76
|
rake
|
49
77
|
simplecov
|
50
|
-
|
51
|
-
BUNDLED WITH
|
52
|
-
2.1.4
|
78
|
+
standard
|
data/Rakefile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "standard/rake"
|
3
4
|
|
4
5
|
Rake::TestTask.new(:test) do |test|
|
5
6
|
test.libs += ["test"]
|
6
7
|
test.warning = true
|
7
|
-
test.pattern =
|
8
|
+
test.pattern = "test/**/*_test.rb"
|
8
9
|
end
|
9
10
|
|
10
|
-
task :
|
11
|
+
task default: ["standard:fix", :test]
|
data/faktory_worker_ruby.gemspec
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
-
|
2
|
-
require File.expand_path('../lib/faktory/version', __FILE__)
|
1
|
+
require File.expand_path("../lib/faktory/version", __FILE__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |gem|
|
5
|
-
gem.name
|
6
|
-
gem.authors
|
7
|
-
gem.email
|
8
|
-
gem.summary
|
9
|
-
gem.description
|
10
|
-
gem.homepage
|
11
|
-
gem.license
|
4
|
+
gem.name = "faktory_worker_ruby"
|
5
|
+
gem.authors = ["Mike Perham"]
|
6
|
+
gem.email = ["mike@contribsys.com"]
|
7
|
+
gem.summary = "Ruby worker for Faktory"
|
8
|
+
gem.description = "Ruby worker for Faktory."
|
9
|
+
gem.homepage = "https://github.com/contribsys/faktory_worker_ruby"
|
10
|
+
gem.license = "LGPL-3.0"
|
12
11
|
|
13
|
-
gem.executables
|
14
|
-
gem.files
|
15
|
-
gem.
|
16
|
-
gem.version = Faktory::VERSION
|
12
|
+
gem.executables = ["faktory-worker"]
|
13
|
+
gem.files = `git ls-files | grep -Ev '^(test|myapp|examples)'`.split("\n")
|
14
|
+
gem.version = Faktory::VERSION
|
17
15
|
gem.required_ruby_version = ">= 2.5.0"
|
18
16
|
|
19
17
|
gem.metadata = {
|
@@ -21,12 +19,12 @@ Gem::Specification.new do |gem|
|
|
21
19
|
"bug_tracker_uri" => "https://github.com/contribsys/faktory_worker_ruby/issues",
|
22
20
|
"documentation_uri" => "https://github.com/contribsys/faktory_worker_ruby/wiki",
|
23
21
|
"changelog_uri" => "https://github.com/contribsys/faktory_worker_ruby/blob/master/Changes.md",
|
24
|
-
"source_code_uri" => "https://github.com/contribsys/faktory_worker_ruby"
|
22
|
+
"source_code_uri" => "https://github.com/contribsys/faktory_worker_ruby"
|
25
23
|
}
|
26
24
|
|
27
|
-
gem.add_dependency
|
28
|
-
gem.add_development_dependency
|
29
|
-
gem.add_development_dependency
|
30
|
-
gem.add_development_dependency
|
31
|
-
gem.add_development_dependency
|
25
|
+
gem.add_dependency "connection_pool", "~> 2.2", ">= 2.2.2"
|
26
|
+
gem.add_development_dependency "activejob", ">= 5.2.0"
|
27
|
+
gem.add_development_dependency "minitest", "~> 5"
|
28
|
+
gem.add_development_dependency "minitest-hooks"
|
29
|
+
gem.add_development_dependency "rake"
|
32
30
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "active_job"
|
4
4
|
|
5
5
|
module ActiveJob
|
6
6
|
module QueueAdapters
|
@@ -10,21 +10,21 @@ module ActiveJob
|
|
10
10
|
#
|
11
11
|
# Rails.application.config.active_job.queue_adapter = :faktory
|
12
12
|
class FaktoryAdapter
|
13
|
-
def enqueue(job)
|
13
|
+
def enqueue(job) # :nodoc:
|
14
14
|
enqueue_at(job, nil)
|
15
15
|
end
|
16
16
|
|
17
|
-
def enqueue_at(job, timestamp)
|
17
|
+
def enqueue_at(job, timestamp) # :nodoc:
|
18
18
|
jid = SecureRandom.hex(12)
|
19
19
|
job.provider_job_id = jid
|
20
20
|
hash = {
|
21
|
-
"jid"
|
21
|
+
"jid" => jid,
|
22
22
|
"jobtype" => JobWrapper.to_s,
|
23
|
-
"custom"
|
24
|
-
"wrapped" => job.class.to_s
|
23
|
+
"custom" => {
|
24
|
+
"wrapped" => job.class.to_s
|
25
25
|
},
|
26
|
-
"queue"
|
27
|
-
"args"
|
26
|
+
"queue" => job.queue_name,
|
27
|
+
"args" => [job.serialize]
|
28
28
|
}
|
29
29
|
opts = job.faktory_options_hash.dup
|
30
30
|
hash["at"] = Time.at(timestamp).utc.to_datetime.rfc3339(9) if timestamp
|
@@ -40,7 +40,7 @@ module ActiveJob
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
class JobWrapper
|
43
|
+
class JobWrapper # :nodoc:
|
44
44
|
include Faktory::Job
|
45
45
|
|
46
46
|
def perform(job_data)
|
@@ -55,7 +55,7 @@ module ActiveJob
|
|
55
55
|
self.faktory_options_hash = {}
|
56
56
|
|
57
57
|
def self.faktory_options(hsh)
|
58
|
-
self.faktory_options_hash =
|
58
|
+
self.faktory_options_hash = faktory_options_hash.stringify_keys.merge(hsh.stringify_keys)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/lib/faktory/batch.rb
CHANGED
@@ -87,7 +87,7 @@ module Faktory
|
|
87
87
|
attr_reader :bid
|
88
88
|
attr_accessor :description, :parent_bid
|
89
89
|
|
90
|
-
def initialize(bid=nil)
|
90
|
+
def initialize(bid = nil)
|
91
91
|
@bid = bid
|
92
92
|
end
|
93
93
|
|
@@ -127,9 +127,9 @@ module Faktory
|
|
127
127
|
def to_callback(val)
|
128
128
|
case val
|
129
129
|
when String
|
130
|
-
basic_job.merge({
|
130
|
+
basic_job.merge({"jobtype" => val})
|
131
131
|
when Class
|
132
|
-
basic_job.merge({
|
132
|
+
basic_job.merge({"jobtype" => val})
|
133
133
|
when Hash
|
134
134
|
basic_job.merge(val)
|
135
135
|
else
|
@@ -139,9 +139,9 @@ module Faktory
|
|
139
139
|
|
140
140
|
def basic_job
|
141
141
|
{
|
142
|
-
"jid"
|
143
|
-
"args"
|
144
|
-
"queue" => "default"
|
142
|
+
"jid" => SecureRandom.hex(12),
|
143
|
+
"args" => [],
|
144
|
+
"queue" => "default"
|
145
145
|
}
|
146
146
|
end
|
147
147
|
end
|
@@ -152,7 +152,7 @@ module Faktory
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def hash
|
155
|
-
@hash ||= Faktory.server{|c| c.batch_status(@bid) }
|
155
|
+
@hash ||= Faktory.server { |c| c.batch_status(@bid) }
|
156
156
|
end
|
157
157
|
|
158
158
|
def created_at
|
data/lib/faktory/cli.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
2
|
+
|
3
3
|
$stdout.sync = true
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
5
|
+
require "yaml"
|
6
|
+
require "singleton"
|
7
|
+
require "optparse"
|
8
|
+
require "erb"
|
9
|
+
require "fileutils"
|
10
10
|
|
11
11
|
module Faktory
|
12
12
|
class CLI
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
require
|
17
|
-
require
|
16
|
+
require "faktory"
|
17
|
+
require "faktory/util"
|
18
18
|
|
19
19
|
module Faktory
|
20
20
|
class CLI
|
@@ -30,7 +30,7 @@ module Faktory
|
|
30
30
|
@code = nil
|
31
31
|
end
|
32
32
|
|
33
|
-
def parse(args=ARGV)
|
33
|
+
def parse(args = ARGV)
|
34
34
|
@code = nil
|
35
35
|
|
36
36
|
setup_options(args)
|
@@ -52,16 +52,14 @@ module Faktory
|
|
52
52
|
print_banner
|
53
53
|
|
54
54
|
self_read, self_write = IO.pipe
|
55
|
-
sigs = %w
|
55
|
+
sigs = %w[INT TERM TTIN TSTP]
|
56
56
|
|
57
57
|
sigs.each do |sig|
|
58
|
-
|
59
|
-
|
60
|
-
self_write.puts(sig)
|
61
|
-
end
|
62
|
-
rescue ArgumentError
|
63
|
-
puts "Signal #{sig} not supported"
|
58
|
+
trap sig do
|
59
|
+
self_write.puts(sig)
|
64
60
|
end
|
61
|
+
rescue ArgumentError
|
62
|
+
puts "Signal #{sig} not supported"
|
65
63
|
end
|
66
64
|
|
67
65
|
logger.info "Running in #{RUBY_DESCRIPTION}"
|
@@ -77,23 +75,23 @@ module Faktory
|
|
77
75
|
# Starting here the process will now have multiple threads running.
|
78
76
|
fire_event(:startup)
|
79
77
|
|
80
|
-
logger.debug { "Client Middleware: #{Faktory.client_middleware.map(&:klass).join(
|
81
|
-
logger.debug { "Worker Middleware: #{Faktory.worker_middleware.map(&:klass).join(
|
78
|
+
logger.debug { "Client Middleware: #{Faktory.client_middleware.map(&:klass).join(", ")}" }
|
79
|
+
logger.debug { "Worker Middleware: #{Faktory.worker_middleware.map(&:klass).join(", ")}" }
|
82
80
|
|
83
|
-
logger.info
|
81
|
+
logger.info "Starting processing, hit Ctrl-C to stop" if $stdout.tty?
|
84
82
|
|
85
|
-
require
|
83
|
+
require "faktory/launcher"
|
86
84
|
@launcher = Faktory::Launcher.new(options)
|
87
85
|
|
88
86
|
begin
|
89
87
|
launcher.run
|
90
88
|
|
91
|
-
while
|
92
|
-
signal =
|
89
|
+
while self_read.wait_readable
|
90
|
+
signal = self_read.gets.strip
|
93
91
|
handle_signal(signal)
|
94
92
|
end
|
95
93
|
rescue Interrupt
|
96
|
-
logger.info
|
94
|
+
logger.info "Shutting down"
|
97
95
|
launcher.stop
|
98
96
|
# Explicitly exit so busy Processor threads can't block
|
99
97
|
# process shutdown.
|
@@ -103,7 +101,7 @@ module Faktory
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def self.banner
|
106
|
-
%q{
|
104
|
+
%q{
|
107
105
|
,,,,
|
108
106
|
,,,, | |
|
109
107
|
| | | |
|
@@ -122,17 +120,17 @@ module Faktory
|
|
122
120
|
def handle_signal(sig)
|
123
121
|
Faktory.logger.debug "Got #{sig} signal"
|
124
122
|
case sig
|
125
|
-
when
|
123
|
+
when "INT"
|
126
124
|
raise Interrupt
|
127
|
-
when
|
125
|
+
when "TERM"
|
128
126
|
# Heroku sends TERM and then waits 30 seconds for process to exit.
|
129
127
|
raise Interrupt
|
130
|
-
when
|
128
|
+
when "TSTP"
|
131
129
|
Faktory.logger.info "Received TSTP, no longer accepting new work"
|
132
130
|
launcher.quiet
|
133
|
-
when
|
131
|
+
when "TTIN"
|
134
132
|
Thread.list.each do |thread|
|
135
|
-
Faktory.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread[
|
133
|
+
Faktory.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread["faktory_label"]}"
|
136
134
|
if thread.backtrace
|
137
135
|
Faktory.logger.warn thread.backtrace.join("\n")
|
138
136
|
else
|
@@ -146,15 +144,15 @@ module Faktory
|
|
146
144
|
|
147
145
|
def print_banner
|
148
146
|
# Print logo and banner for development
|
149
|
-
if environment ==
|
150
|
-
puts "\e[
|
147
|
+
if environment == "development" && $stdout.tty?
|
148
|
+
puts "\e[31m"
|
151
149
|
puts Faktory::CLI.banner
|
152
150
|
puts "\e[0m"
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
156
154
|
def set_environment(cli_env)
|
157
|
-
@environment = cli_env || ENV[
|
155
|
+
@environment = cli_env || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
158
156
|
end
|
159
157
|
|
160
158
|
alias_method :die, :exit
|
@@ -178,18 +176,18 @@ module Faktory
|
|
178
176
|
end
|
179
177
|
|
180
178
|
def boot_system
|
181
|
-
ENV[
|
179
|
+
ENV["RACK_ENV"] = ENV["RAILS_ENV"] = environment
|
182
180
|
|
183
181
|
raise ArgumentError, "#{options[:require]} does not exist" unless File.exist?(options[:require])
|
184
182
|
|
185
183
|
if File.directory?(options[:require])
|
186
|
-
require
|
187
|
-
require
|
184
|
+
require "rails"
|
185
|
+
require "faktory/rails"
|
188
186
|
require File.expand_path("#{options[:require]}/config/environment.rb")
|
189
187
|
options[:tag] ||= default_tag
|
190
188
|
else
|
191
|
-
not_required_message = "#{options[:require]} was not required, you should use an explicit path: "
|
192
|
-
|
189
|
+
not_required_message = "#{options[:require]} was not required, you should use an explicit path: " \
|
190
|
+
"./#{options[:require]} or /path/to/#{options[:require]}"
|
193
191
|
|
194
192
|
require(options[:require]) || raise(ArgumentError, not_required_message)
|
195
193
|
end
|
@@ -198,8 +196,8 @@ module Faktory
|
|
198
196
|
def default_tag
|
199
197
|
dir = ::Rails.root
|
200
198
|
name = File.basename(dir)
|
201
|
-
if name.to_i != 0 && prevdir = File.dirname(dir) # Capistrano release directory?
|
202
|
-
if File.basename(prevdir) ==
|
199
|
+
if name.to_i != 0 && (prevdir = File.dirname(dir)) # Capistrano release directory?
|
200
|
+
if File.basename(prevdir) == "releases"
|
203
201
|
return File.basename(File.dirname(prevdir))
|
204
202
|
end
|
205
203
|
end
|
@@ -207,10 +205,10 @@ module Faktory
|
|
207
205
|
end
|
208
206
|
|
209
207
|
def validate!
|
210
|
-
options[:queues] <<
|
208
|
+
options[:queues] << "default" if options[:queues].empty?
|
211
209
|
|
212
210
|
if !File.exist?(options[:require]) ||
|
213
|
-
|
211
|
+
(File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
|
214
212
|
logger.info "=================================================================="
|
215
213
|
logger.info " Please point Faktory to a Rails application or a Ruby file "
|
216
214
|
logger.info " to load your worker classes with -r [DIR|FILE]."
|
@@ -228,19 +226,19 @@ module Faktory
|
|
228
226
|
opts = {}
|
229
227
|
|
230
228
|
@parser = OptionParser.new do |o|
|
231
|
-
o.on
|
229
|
+
o.on "-c", "--concurrency INT", "processor threads to use" do |arg|
|
232
230
|
opts[:concurrency] = Integer(arg)
|
233
231
|
end
|
234
232
|
|
235
|
-
o.on
|
233
|
+
o.on "-e", "--environment ENV", "Application environment" do |arg|
|
236
234
|
opts[:environment] = arg
|
237
235
|
end
|
238
236
|
|
239
|
-
o.on
|
237
|
+
o.on "-g", "--tag TAG", "Process tag for procline" do |arg|
|
240
238
|
opts[:tag] = arg
|
241
239
|
end
|
242
240
|
|
243
|
-
o.on
|
241
|
+
o.on "-l", "--label LABEL", "Process label to use in Faktory UI" do |arg|
|
244
242
|
(opts[:labels] ||= []) << arg
|
245
243
|
end
|
246
244
|
|
@@ -249,11 +247,11 @@ module Faktory
|
|
249
247
|
parse_queue opts, queue, weight
|
250
248
|
end
|
251
249
|
|
252
|
-
o.on
|
250
|
+
o.on "-r", "--require [PATH|DIR]", "Location of Rails application with workers or file to require" do |arg|
|
253
251
|
opts[:require] = arg
|
254
252
|
end
|
255
253
|
|
256
|
-
o.on
|
254
|
+
o.on "-t", "--timeout NUM", "Shutdown timeout" do |arg|
|
257
255
|
opts[:timeout] = Integer(arg)
|
258
256
|
end
|
259
257
|
|
@@ -261,11 +259,11 @@ module Faktory
|
|
261
259
|
opts[:verbose] = arg
|
262
260
|
end
|
263
261
|
|
264
|
-
o.on
|
262
|
+
o.on "-C", "--config PATH", "path to YAML config file" do |arg|
|
265
263
|
opts[:config_file] = arg
|
266
264
|
end
|
267
265
|
|
268
|
-
o.on
|
266
|
+
o.on "-V", "--version", "Print version and exit" do |arg|
|
269
267
|
puts "Faktory #{Faktory::VERSION}"
|
270
268
|
die(0)
|
271
269
|
end
|
@@ -294,12 +292,10 @@ module Faktory
|
|
294
292
|
def parse_config(cfile)
|
295
293
|
opts = {}
|
296
294
|
if File.exist?(cfile)
|
297
|
-
|
295
|
+
src = ERB.new(IO.read(cfile)).result
|
296
|
+
opts = YAML.safe_load(src, permitted_classes: [Symbol], aliases: true) || {}
|
298
297
|
opts = opts.merge(opts.delete(environment) || {})
|
299
298
|
parse_queues(opts, opts.delete(:queues) || [])
|
300
|
-
else
|
301
|
-
# allow a non-existent config file so Faktory
|
302
|
-
# can be deployed by cap with just the defaults.
|
303
299
|
end
|
304
300
|
opts
|
305
301
|
end
|
@@ -308,9 +304,9 @@ module Faktory
|
|
308
304
|
queues_and_weights.each { |queue_and_weight| parse_queue(opts, *queue_and_weight) }
|
309
305
|
end
|
310
306
|
|
311
|
-
def parse_queue(opts, q, weight=nil)
|
307
|
+
def parse_queue(opts, q, weight = nil)
|
312
308
|
[weight.to_i, 1].max.times do
|
313
|
-
|
309
|
+
(opts[:queues] ||= []) << q
|
314
310
|
end
|
315
311
|
opts[:strict] = false if weight.to_i > 0
|
316
312
|
end
|