que 1.0.0.beta2 → 1.0.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.
@@ -18,12 +18,14 @@ module Que
18
18
  default_require_file: RAILS_ENVIRONMENT_FILE
19
19
  )
20
20
 
21
- options = {}
22
- queues = []
23
- log_level = 'info'
24
- log_internals = false
25
- poll_interval = 5
26
- connection_url = nil
21
+ options = {}
22
+ queues = []
23
+ log_level = 'info'
24
+ log_internals = false
25
+ poll_interval = 5
26
+ connection_url = nil
27
+ worker_count = nil
28
+ worker_priorities = nil
27
29
 
28
30
  parser =
29
31
  OptionParser.new do |opts|
@@ -58,6 +60,26 @@ module Que
58
60
  log_level = l
59
61
  end
60
62
 
63
+ opts.on(
64
+ '-p',
65
+ '--worker-priorities [LIST]',
66
+ Array,
67
+ "List of priorities to assign to workers (default: 10,30,50,any,any,any)",
68
+ ) do |priority_array|
69
+ worker_priorities =
70
+ priority_array.map do |p|
71
+ case p
72
+ when /\Aany\z/i
73
+ nil
74
+ when /\A\d+\z/
75
+ Integer(p)
76
+ else
77
+ output.puts "Invalid priority option: '#{p}'. Please use an integer or the word 'any'."
78
+ return 1
79
+ end
80
+ end
81
+ end
82
+
61
83
  opts.on(
62
84
  '-q',
63
85
  '--queue-name [NAME]',
@@ -69,6 +91,15 @@ module Que
69
91
  queues << queue_name
70
92
  end
71
93
 
94
+ opts.on(
95
+ '-w',
96
+ '--worker-count [COUNT]',
97
+ Integer,
98
+ "Set number of workers in process (default: 6)",
99
+ ) do |w|
100
+ worker_count = w
101
+ end
102
+
72
103
  opts.on(
73
104
  '-v',
74
105
  '--version',
@@ -79,15 +110,6 @@ module Que
79
110
  return 0
80
111
  end
81
112
 
82
- opts.on(
83
- '-w',
84
- '--worker-count [COUNT]',
85
- Integer,
86
- "Set number of workers in process (default: 6)",
87
- ) do |w|
88
- options[:worker_count] = w
89
- end
90
-
91
113
  opts.on(
92
114
  '--connection-url [URL]',
93
115
  String,
@@ -130,19 +152,21 @@ module Que
130
152
  ) do |p|
131
153
  options[:wait_period] = p
132
154
  end
133
-
134
- opts.on(
135
- '--worker-priorities [LIST]',
136
- Array,
137
- "List of priorities to assign to workers, " \
138
- "unspecified workers take jobs of any priority (default: 10,30,50)",
139
- ) do |p|
140
- options[:worker_priorities] = p.map(&:to_i)
141
- end
142
155
  end
143
156
 
144
157
  parser.parse!(args)
145
158
 
159
+ options[:worker_priorities] =
160
+ if worker_count && worker_priorities
161
+ worker_priorities.values_at(0...worker_count)
162
+ elsif worker_priorities
163
+ worker_priorities
164
+ elsif worker_count
165
+ Array.new(worker_count) { nil }
166
+ else
167
+ [10, 30, 50, nil, nil, nil]
168
+ end
169
+
146
170
  if args.length.zero?
147
171
  if File.exist?(default_require_file)
148
172
  args << default_require_file
@@ -159,8 +183,8 @@ OUTPUT
159
183
  args.each do |file|
160
184
  begin
161
185
  require file
162
- rescue LoadError
163
- output.puts "Could not load file '#{file}'"
186
+ rescue LoadError => e
187
+ output.puts "Could not load file '#{file}': #{e}"
164
188
  return 1
165
189
  end
166
190
  end