workerholic 0.0.7 → 0.0.8
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/Gemfile.lock +1 -1
- data/bin/workerholic +1 -9
- data/lib/workerholic.rb +0 -2
- data/lib/workerholic/cli.rb +63 -10
- data/lib/workerholic/job_processor.rb +2 -2
- data/lib/workerholic/log_manager.rb +8 -0
- data/lib/workerholic/queue.rb +1 -1
- data/lib/workerholic/version.rb +1 -1
- data/lib/workerholic/worker.rb +1 -1
- data/lib/workerholic/worker_balancer.rb +2 -2
- data/pkg/workerholic-0.0.7.gem +0 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '02909e2b39a8d03796f21f57c2914f56a4b58a7b'
|
4
|
+
data.tar.gz: 7696ea1dd34cf1df6c6ed21b5a627ea1ce1e4f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '03138c50a4edcc225af7d17b9a55cc7cf3799ac3a8612864768629b3685bfc2d67a8a798edcc758130b2543c1e04469338fbbe4129f0fd4b1bd61f3272f49b22'
|
7
|
+
data.tar.gz: ff0cff28763276952f390d9b2263eb399a2c3910133f28d16d2015aea6c8f12c6dea1f0ac30b438f493e50af8c63ef30af4e1c81ad314d53b966764984a8c9e3
|
data/Gemfile.lock
CHANGED
data/bin/workerholic
CHANGED
@@ -2,12 +2,4 @@
|
|
2
2
|
|
3
3
|
require_relative '../lib/workerholic/cli'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
if defined?(Rails)
|
8
|
-
puts 'Loading Rails...'
|
9
|
-
require File.expand_path("./config/environment.rb")
|
10
|
-
require 'workerholic/adapters/active_job_adapter'
|
11
|
-
end
|
12
|
-
|
13
|
-
Workerholic::CLI.run
|
5
|
+
Workerholic::CLI.instance.run
|
data/lib/workerholic.rb
CHANGED
@@ -23,8 +23,6 @@ require 'workerholic/job_serializer'
|
|
23
23
|
require 'workerholic/statistics'
|
24
24
|
require 'workerholic/log_manager'
|
25
25
|
|
26
|
-
require_relative '../app_test/job_test' # require the application code
|
27
|
-
|
28
26
|
module Workerholic
|
29
27
|
def self.workers_count
|
30
28
|
@workers_count || 25
|
data/lib/workerholic/cli.rb
CHANGED
@@ -1,21 +1,74 @@
|
|
1
1
|
$LOAD_PATH << __dir__ + '/..'
|
2
2
|
|
3
3
|
require 'workerholic'
|
4
|
+
require 'optparse'
|
5
|
+
require 'singleton'
|
4
6
|
|
5
7
|
module Workerholic
|
6
8
|
class CLI
|
7
|
-
|
8
|
-
auto_balance = ARGV.any? { |arg| arg == '--auto-balance' }
|
9
|
-
workers_count = ARGV.find { |arg| arg.match? /^--workers=\d+$/ }
|
9
|
+
include Singleton
|
10
10
|
|
11
|
-
|
12
|
-
workers_count = workers_count[/\d+/].to_i
|
13
|
-
Workerholic.workers_count = workers_count
|
14
|
-
end
|
11
|
+
attr_reader :logger, :options
|
15
12
|
|
16
|
-
|
13
|
+
def initialize
|
14
|
+
@logger = LogManager.new
|
17
15
|
end
|
18
|
-
end
|
19
|
-
end
|
20
16
|
|
17
|
+
def run
|
18
|
+
parse_options
|
19
|
+
set_options
|
20
|
+
|
21
|
+
load_app
|
22
|
+
|
23
|
+
Manager.new(auto_balance: options[:auto_balance]).start
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_options
|
27
|
+
@options = {}
|
28
|
+
|
29
|
+
OptionParser.new do |opts|
|
30
|
+
opts.banner = 'Usage: workerholic [options]'
|
31
|
+
|
32
|
+
opts.on '-ab', '--auto-balance', 'auto-balance workers based on number of jobs in each queue' do
|
33
|
+
options[:auto_balance] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on '-w', '--workers INT', 'number of concurrent workers' do |count|
|
37
|
+
options[:workers] = count.to_i
|
38
|
+
end
|
21
39
|
|
40
|
+
opts.on '-r', '--require PATH', 'file to be required to load your application' do |file|
|
41
|
+
options[:require] = file
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on '-h', '--help', 'show help' do
|
45
|
+
logger.info(opts)
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
end.parse!
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_options
|
52
|
+
Workerholic.workers_count = options[:workers_count] if options[:workers_count]
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_app
|
56
|
+
if File.exist?('./config/environment.rb')
|
57
|
+
require File.expand_path('./config/environment.rb')
|
58
|
+
require 'workerholic/adapters/active_job_adapter'
|
59
|
+
elsif options[:require]
|
60
|
+
if File.exist?(options[:require])
|
61
|
+
require File.expand_path(options[:require])
|
62
|
+
else
|
63
|
+
log.info('The file you specified to load your application is not valid!')
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
else
|
67
|
+
logger.info('If you are using a Rails app, make sure to navigate to your root directory before starting Workerholic!')
|
68
|
+
logger.info('If you are not using a Rails app, you can load your app by using the option --require and specifying the file needing to be required in order to load your application.')
|
69
|
+
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -13,14 +13,14 @@ module Workerholic
|
|
13
13
|
job_result = job.perform
|
14
14
|
job.statistics.completed_at = Time.now.to_f
|
15
15
|
|
16
|
-
# @logger.
|
16
|
+
# @logger.info("Completed: your job from class #{job.klass} was completed on #{job.statistics.completed_at}.")
|
17
17
|
|
18
18
|
job_result
|
19
19
|
rescue Exception => e
|
20
20
|
job.statistics.errors.push([e.class, e.message])
|
21
21
|
JobRetry.new(job: job)
|
22
22
|
|
23
|
-
# @logger.
|
23
|
+
# @logger.error("Failed: your job from class #{job.class} was unsuccessful. Retrying in 10 seconds.")
|
24
24
|
end
|
25
25
|
|
26
26
|
# Push job into some collection
|
data/lib/workerholic/queue.rb
CHANGED
@@ -11,7 +11,7 @@ module Workerholic
|
|
11
11
|
|
12
12
|
def enqueue(serialized_job)
|
13
13
|
storage.push(name, serialized_job)
|
14
|
-
logger.
|
14
|
+
logger.info("Your job was placed in the #{name} queue on #{Time.now}.")
|
15
15
|
end
|
16
16
|
|
17
17
|
def dequeue
|
data/lib/workerholic/version.rb
CHANGED
data/lib/workerholic/worker.rb
CHANGED
@@ -87,8 +87,8 @@ module Workerholic
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def output_balancer_stats
|
90
|
-
@logger.
|
91
|
-
@logger.
|
90
|
+
@logger.info(queues.map { |q| { name: q.name, size: q.size } })
|
91
|
+
@logger.info(current_workers_count_per_queue)
|
92
92
|
end
|
93
93
|
|
94
94
|
def assign_one_worker_per_queue
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workerholic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Leclercq
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- pkg/workerholic-0.0.4.gem
|
144
144
|
- pkg/workerholic-0.0.5.gem
|
145
145
|
- pkg/workerholic-0.0.6.gem
|
146
|
+
- pkg/workerholic-0.0.7.gem
|
146
147
|
- spec/helpers/helper_methods.rb
|
147
148
|
- spec/helpers/job_tests.rb
|
148
149
|
- spec/integration/dequeuing_and_job_processing_spec.rb
|