leveret 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14ea608b7f0a42d15bb1ea0ff2cf515869791c67
4
- data.tar.gz: 3385ea7758e726cacb8229d5ba0969e5ce1a89fc
3
+ metadata.gz: 0fa818a1ffcc9bc99f240661a7f4d6b8fac47ce4
4
+ data.tar.gz: 4eff94051e933d7fb226a21a7026755459bc14cc
5
5
  SHA512:
6
- metadata.gz: 5235a4ff684179954cb012bb852219a948ff2c0afd6e41f6738e97ad0e90c895f5d627b8e6ed1972a4dc9086d29f8fb35bbc5308d4958d8f9c033fccb01fbf86
7
- data.tar.gz: 57dfcf5d29949acf97b494b46d3b5c187ea6adaf7a89cd3cb0fc48fe812df3b0c2b00ea8b24e865115a20f49038052ca485af5e9b0709e07dfabb9ae02348ee1
6
+ metadata.gz: 8d3a79bede854e7fc939c5d01208a0d79463b9d2e8f6212ff9721e947d4a14c48e0bdef30bbc8b52269de7ccee0aa98437ef1f200eb98767c9dc2cf674cc4727
7
+ data.tar.gz: b93bfe1b96cae3dd7923dc005fa31a2da00d7582d80df9ba57f66fa041d318aa91516f6882c6a6251e756330ee09ac167e3427b92a360ec955a9f0c3702eedeb
data/README.md CHANGED
@@ -113,22 +113,24 @@ MyJob.enqueue(test_text: "Hi there! Please write me to the test file.", priority
113
113
  To start a leveret worker, simply run the `leveret_worker` executable included in the gem. Started with no arguments it
114
114
  will create a worker monitoring the default queue and process one job at a time.
115
115
 
116
- Changing the queues that a worker monitors requires passing a comma separated list of queue names in the environment
117
- variable `QUEUES`. The example below watches for jobs on the queues `standard` and `other`.
116
+ Changing the queues that a worker monitors requires passing a comma separated list of queue names in the option
117
+ `--queues`. The example below watches for jobs on the queues `standard` and `other`.
118
118
 
119
119
  ```bash
120
- bundle exec leveret_worker QUEUES=standard,other
120
+ bundle exec leveret_worker --queues standard,other
121
121
  ```
122
122
 
123
123
  By default, workers will only process one job at a time. For each job that is executed, a child process is forked, and
124
124
  the job run in the new process. When the job completes, the fork exits. We can process more jobs simultaniously simply
125
- by allowing more forks to run. To increase this limit set the `PROCESSES` environment variable. There is no limit to
125
+ by allowing more forks to run. To increase this limit set the `--processes` option. There is no limit to
126
126
  this variable in Leveret, but you should be aware of your own OS and resource limits.
127
127
 
128
128
  ```bash
129
- bundle exec leveret_worker PROCESSES=5
129
+ bundle exec leveret_worker --processes 5
130
130
  ```
131
131
 
132
+ It's also possible to set the log level and output from the command line, call up `--help` for more details.
133
+
132
134
  ## Configuration
133
135
 
134
136
  Configuration in Leveret is done via a configure block. In a Rails application it is recommended you place your
data/exe/leveret_worker CHANGED
@@ -2,15 +2,10 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "leveret"
5
+ require "leveret/cli"
5
6
 
6
7
  if File.exist?("./config/environment.rb")
7
8
  require File.expand_path("./config/environment.rb")
8
9
  end
9
10
 
10
- queues = ENV["QUEUES"].to_s.split(',')
11
- queues << Leveret.configuration.default_queue_name if queues.empty?
12
-
13
- concurrent_fork_count = ENV["PROCESSES"] || Leveret.configuration.concurrent_fork_count
14
-
15
- worker = Leveret::Worker.new(queues: queues, concurrent_fork_count: concurrent_fork_count)
16
- worker.do_work
11
+ Leveret::CLI.new(ARGV)
@@ -0,0 +1,77 @@
1
+ module Leveret
2
+ class CLI
3
+ attr_accessor :options
4
+
5
+ def initialize(args)
6
+ self.options = {}
7
+
8
+ parse_options(args)
9
+ configure_leveret
10
+ start_worker
11
+ end
12
+
13
+ private
14
+
15
+ def parse_options(args)
16
+ option_parser.parse!(args)
17
+ end
18
+
19
+ def configure_leveret
20
+ Leveret.configure do |config|
21
+ config.concurrent_fork_count = options[:processes] if options[:processes]
22
+ config.log_level = options[:log_level] if options[:log_level]
23
+ config.log_file = options[:log_file] if options[:log_file]
24
+ end
25
+ end
26
+
27
+ def start_worker
28
+ Leveret::Worker.new(*options[:queues]).do_work
29
+ end
30
+
31
+ def option_parser
32
+ @option_parser ||= OptionParser.new do |opts|
33
+ opts.banner = "Usage: leveret_worker [options]"
34
+ opts.separator ""
35
+ opts.separator "Options:"
36
+
37
+ opts.on "-q", "--queues [QUEUES]", String, "Comma separated list of queues to subscribe to" do |queues|
38
+ options[:queues] = queues.split(',')
39
+ end
40
+
41
+ opts.on "-p", "--processes [PROCESSES]", Integer, "Number of concurrent jobs to process" do |processes|
42
+ options[:processes] = processes
43
+ end
44
+
45
+ opts.on '-l', '--log-level [LEVEL]', String, "Level of log output (debug, info, warning, error, fatal)" do |lvl|
46
+ options[:log_level] = convert_log_level(lvl)
47
+ end
48
+
49
+ opts.on '-o', '--log-output [FILE]', String, "Location to write log file to" do |logfile|
50
+ options[:log_file] = logfile
51
+ end
52
+
53
+ opts.on_tail '-h', '--help', "Show this message" do
54
+ STDOUT.puts opts
55
+ exit
56
+ end
57
+
58
+ opts.on_tail '-v', '--version', "Show the version" do
59
+ STDOUT.puts Leveret::VERSION
60
+ exit
61
+ end
62
+ end
63
+ end
64
+
65
+ def convert_log_level(level)
66
+ case level
67
+ when 'debug' then Logger::DEBUG
68
+ when 'info' then Logger::INFO
69
+ when 'warn' then Logger::WARN
70
+ when 'error' then Logger::ERROR
71
+ when 'fatal' then Logger::FATAL
72
+ else
73
+ Logger::INFO
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module Leveret
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2".freeze
3
3
  end
@@ -15,19 +15,12 @@ module Leveret
15
15
 
16
16
  # Create a new worker to process jobs from the list of queue names passed
17
17
  #
18
- # @option options [Array<String>] queues ([Leveret.configuration.default_queue_name]) A list of queue names for
19
- # this worker to subscribe to and process
20
- # @option options [Integer] concurrent_fork_count (Leveret.configuration.concurrent_fork_count) How many messages
21
- # at a time should this worker process?
22
- def initialize(options = {})
23
- options = {
24
- queues: [configuration.default_queue_name],
25
- concurrent_fork_count: [configuration.concurrent_fork_count]
26
- }.merge(options)
27
-
28
- Leveret.configuration.concurrent_fork_count = options[:concurrent_fork_count]
29
-
30
- self.queues = options[:queues].map { |name| Leveret::Queue.new(name) }
18
+ # @param [Array<String>] queue_names ([Leveret.configuration.default_queue_name]) A list of queue names for this
19
+ # worker to subscribe to and process
20
+ def initialize(*queue_names)
21
+ queue_names << configuration.default_queue_name if queue_names.empty?
22
+
23
+ self.queues = queue_names.map { |name| Leveret::Queue.new(name) }
31
24
  self.consumers = []
32
25
  @time_to_die = false
33
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leveret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Wentworth
@@ -99,6 +99,7 @@ files:
99
99
  - exe/leveret_worker
100
100
  - leveret.gemspec
101
101
  - lib/leveret.rb
102
+ - lib/leveret/cli.rb
102
103
  - lib/leveret/configuration.rb
103
104
  - lib/leveret/job.rb
104
105
  - lib/leveret/log_formatter.rb