herdst_worker 0.1.4 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/herdst_worker/adapters/database.rb +0 -1
- data/lib/herdst_worker/adapters/facade.rb +20 -20
- data/lib/herdst_worker/adapters/sentry.rb +1 -1
- data/lib/herdst_worker/application/facade.rb +98 -89
- data/lib/herdst_worker/autoload/facade.rb +67 -67
- data/lib/herdst_worker/configuration/metadata.rb +5 -1
- data/lib/herdst_worker/configuration/paths.rb +41 -41
- data/lib/herdst_worker/log/facade.rb +87 -87
- data/lib/herdst_worker/queue/facade.rb +164 -162
- data/lib/herdst_worker/queue/processor.rb +225 -223
- data/lib/herdst_worker/queue/runner.rb +137 -137
- data/lib/herdst_worker/signals/facade.rb +35 -35
- data/lib/herdst_worker/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3de398e124491be06479567865179d713005b2febcca984cade36bfe0052955f
|
4
|
+
data.tar.gz: 693dc282a8feb3450ff1f97833185aea1682a467897f075181c2235c14808e78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e0d56aac10f61c9c399471c4a7c356549cf75cf1fa8f223b1b377200ad6b54e2b675f8a20c544eb0f225574a9ba83e039bc46d06a8c7bfbf8c98e2ebbf8f52
|
7
|
+
data.tar.gz: cbf2e9433d2275e7a8ab4a4651e634f96491d0170fc71346dec6e5ad14238ae54af81bdf5a437c600378ae1601c8d18e617c8eda2d7daf2a9c438f398b8cb2b2
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require "sentry-raven"
|
2
|
-
|
3
|
-
require_relative "database"
|
4
|
-
require_relative "sentry"
|
5
|
-
|
6
|
-
|
7
|
-
module HerdstWorker
|
8
|
-
module Adapters
|
9
|
-
class Facade
|
10
|
-
|
11
|
-
|
12
|
-
def self.bootstrap(app)
|
13
|
-
HerdstWorker::Adapters::Database.setup(app)
|
14
|
-
HerdstWorker::Adapters::Sentry.setup(app)
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require "sentry-raven"
|
2
|
+
|
3
|
+
require_relative "database"
|
4
|
+
require_relative "sentry"
|
5
|
+
|
6
|
+
|
7
|
+
module HerdstWorker
|
8
|
+
module Adapters
|
9
|
+
class Facade
|
10
|
+
|
11
|
+
|
12
|
+
def self.bootstrap(app)
|
13
|
+
HerdstWorker::Adapters::Database.setup(app)
|
14
|
+
HerdstWorker::Adapters::Sentry.setup(app)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,89 +1,98 @@
|
|
1
|
-
require_relative '../configuration/facade'
|
2
|
-
require_relative '../log/facade'
|
3
|
-
require_relative '../autoload/facade'
|
4
|
-
require_relative '../signals/facade'
|
5
|
-
require_relative '../queue/facade'
|
6
|
-
require_relative '../adapters/facade'
|
7
|
-
|
8
|
-
|
9
|
-
module HerdstWorker
|
10
|
-
class Application
|
11
|
-
|
12
|
-
|
13
|
-
attr_accessor :name
|
14
|
-
attr_accessor :logger, :config, :autoload
|
15
|
-
attr_accessor :poller_enabled, :queues, :poller_url, :queue
|
16
|
-
|
17
|
-
|
18
|
-
def initialize(env, name, poller_enabled)
|
19
|
-
self.name = name
|
20
|
-
self.poller_enabled = poller_enabled
|
21
|
-
self.queues = ActiveSupport::HashWithIndifferentAccess.new
|
22
|
-
|
23
|
-
HerdstWorker.set_application(self)
|
24
|
-
|
25
|
-
self.logger = HerdstWorker::Log::Facade.new(get_logger_level(env))
|
26
|
-
self.config = HerdstWorker::Configuration::Facade.new(env, name)
|
27
|
-
self.autoload = HerdstWorker::Autoload::Facade.new(self)
|
28
|
-
self.set_inflections
|
29
|
-
|
30
|
-
HerdstWorker::Adapters::Facade.bootstrap(self)
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def configure(&block)
|
35
|
-
yield self
|
36
|
-
|
37
|
-
self.autoload.reload
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def
|
42
|
-
self.queues[name]
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
1
|
+
require_relative '../configuration/facade'
|
2
|
+
require_relative '../log/facade'
|
3
|
+
require_relative '../autoload/facade'
|
4
|
+
require_relative '../signals/facade'
|
5
|
+
require_relative '../queue/facade'
|
6
|
+
require_relative '../adapters/facade'
|
7
|
+
|
8
|
+
|
9
|
+
module HerdstWorker
|
10
|
+
class Application
|
11
|
+
|
12
|
+
|
13
|
+
attr_accessor :name
|
14
|
+
attr_accessor :logger, :config, :autoload
|
15
|
+
attr_accessor :poller_enabled, :queues, :poller_url, :queue
|
16
|
+
|
17
|
+
|
18
|
+
def initialize(env, name, poller_enabled)
|
19
|
+
self.name = name
|
20
|
+
self.poller_enabled = poller_enabled
|
21
|
+
self.queues = ActiveSupport::HashWithIndifferentAccess.new
|
22
|
+
|
23
|
+
HerdstWorker.set_application(self)
|
24
|
+
|
25
|
+
self.logger = HerdstWorker::Log::Facade.new(get_logger_level(env))
|
26
|
+
self.config = HerdstWorker::Configuration::Facade.new(env, name)
|
27
|
+
self.autoload = HerdstWorker::Autoload::Facade.new(self)
|
28
|
+
self.set_inflections
|
29
|
+
|
30
|
+
HerdstWorker::Adapters::Facade.bootstrap(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def configure(&block)
|
35
|
+
yield self
|
36
|
+
|
37
|
+
self.autoload.reload
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def get_queue(name)
|
42
|
+
if self.queues[name]
|
43
|
+
HerdstWorker::Queue::Facade.new(self, false, self.queues[name], 20)
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def add_queue(name, url, poller = false)
|
51
|
+
self.queues[name] = url
|
52
|
+
self.poller_url = url if poller
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def run
|
57
|
+
if self.queue == nil
|
58
|
+
self.logger.info "Starting Application (#{$$})"
|
59
|
+
|
60
|
+
HerdstWorker::Signals::Facade.listen(self.config.paths.temp)
|
61
|
+
|
62
|
+
self.queue = HerdstWorker::Queue::Facade.new(self, self.poller_enabled, self.poller_url, 20)
|
63
|
+
self.queue.start
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def config_for(name)
|
69
|
+
self.config.config_for(name)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
private
|
74
|
+
def set_inflections
|
75
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
76
|
+
inflect.irregular "meta", "meta"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_logger_level(env)
|
81
|
+
return "WARN" if env == "production"
|
82
|
+
return "FATAL" if env == "test"
|
83
|
+
return "DEBUG"
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def self.set_application(application)
|
91
|
+
@@application = application
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def self.application
|
96
|
+
@@application
|
97
|
+
end
|
98
|
+
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
module HerdstWorker
|
2
|
-
module Autoload
|
3
|
-
class Facade
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :root_path, :loaded, :files, :paths
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(app)
|
10
|
-
self.root_path = app.config.paths.root
|
11
|
-
|
12
|
-
self.loaded = []
|
13
|
-
self.files = []
|
14
|
-
self.paths = [ "lib" ]
|
15
|
-
|
16
|
-
self.reload
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def <<(path)
|
21
|
-
full_path = self.root_path + "/" + path
|
22
|
-
|
23
|
-
if File.directory?(full_path)
|
24
|
-
self.paths << path
|
25
|
-
else
|
26
|
-
self.files << path
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def reload
|
32
|
-
self.files.each do |file|
|
33
|
-
self.load_file(self.root_path + "/" + file)
|
34
|
-
end
|
35
|
-
|
36
|
-
self.paths.each do |folder|
|
37
|
-
concern_files = Dir.glob("#{root_path}/#{folder}/concerns/*.rb").sort
|
38
|
-
folder_files = Dir.glob("#{root_path}/#{folder}/*.rb").sort
|
39
|
-
|
40
|
-
concern_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/concerns/*.rb").sort
|
41
|
-
folder_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/*.rb").sort
|
42
|
-
|
43
|
-
files = (concern_files + folder_files + concern_sub_files + folder_sub_files).uniq
|
44
|
-
|
45
|
-
files.each do |file|
|
46
|
-
self.load_file(file)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
def has_loaded?(file)
|
53
|
-
self.loaded.include?(file)
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
def load_file(file)
|
58
|
-
unless has_loaded?(file)
|
59
|
-
load file
|
60
|
-
self.loaded << file
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
module HerdstWorker
|
2
|
+
module Autoload
|
3
|
+
class Facade
|
4
|
+
|
5
|
+
|
6
|
+
attr_accessor :root_path, :loaded, :files, :paths
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(app)
|
10
|
+
self.root_path = app.config.paths.root
|
11
|
+
|
12
|
+
self.loaded = []
|
13
|
+
self.files = []
|
14
|
+
self.paths = [ "lib" ]
|
15
|
+
|
16
|
+
self.reload
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def <<(path)
|
21
|
+
full_path = self.root_path + "/" + path
|
22
|
+
|
23
|
+
if File.directory?(full_path)
|
24
|
+
self.paths << path
|
25
|
+
else
|
26
|
+
self.files << path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def reload
|
32
|
+
self.files.each do |file|
|
33
|
+
self.load_file(self.root_path + "/" + file)
|
34
|
+
end
|
35
|
+
|
36
|
+
self.paths.each do |folder|
|
37
|
+
concern_files = Dir.glob("#{root_path}/#{folder}/concerns/*.rb").sort
|
38
|
+
folder_files = Dir.glob("#{root_path}/#{folder}/*.rb").sort
|
39
|
+
|
40
|
+
concern_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/concerns/*.rb").sort
|
41
|
+
folder_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/*.rb").sort
|
42
|
+
|
43
|
+
files = (concern_files + folder_files + concern_sub_files + folder_sub_files).uniq
|
44
|
+
|
45
|
+
files.each do |file|
|
46
|
+
self.load_file(file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def has_loaded?(file)
|
53
|
+
self.loaded.include?(file)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def load_file(file)
|
58
|
+
unless has_loaded?(file)
|
59
|
+
load file
|
60
|
+
self.loaded << file
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
module HerdstWorker
|
2
|
-
module Configuration
|
3
|
-
class Paths
|
4
|
-
|
5
|
-
|
6
|
-
attr_accessor :root_path, :paths
|
7
|
-
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
self.root_path = ENV["ROOT_PATH"] || Dir.pwd
|
11
|
-
|
12
|
-
self.paths = ActiveSupport::HashWithIndifferentAccess.new
|
13
|
-
self.paths[:root] = self.root_path
|
14
|
-
self.paths[:app] = "#{self.root_path}/app"
|
15
|
-
self.paths[:config] = "#{self.root_path}/config"
|
16
|
-
self.paths[:temp] = "#{self.root_path}/tmp"
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def []=(name, value)
|
21
|
-
self.paths[name] = "#{self.root_path}/#{value}"
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def [](name)
|
26
|
-
self.paths[name]
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def method_missing(name)
|
31
|
-
if self.paths.include?(name)
|
32
|
-
self.paths[name]
|
33
|
-
else
|
34
|
-
raise NoMethodError
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module HerdstWorker
|
2
|
+
module Configuration
|
3
|
+
class Paths
|
4
|
+
|
5
|
+
|
6
|
+
attr_accessor :root_path, :paths
|
7
|
+
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.root_path = ENV["ROOT_PATH"] || Dir.pwd
|
11
|
+
|
12
|
+
self.paths = ActiveSupport::HashWithIndifferentAccess.new
|
13
|
+
self.paths[:root] = self.root_path
|
14
|
+
self.paths[:app] = "#{self.root_path}/app"
|
15
|
+
self.paths[:config] = "#{self.root_path}/config"
|
16
|
+
self.paths[:temp] = "#{self.root_path}/tmp"
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def []=(name, value)
|
21
|
+
self.paths[name] = "#{self.root_path}/#{value}"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def [](name)
|
26
|
+
self.paths[name]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def method_missing(name)
|
31
|
+
if self.paths.include?(name)
|
32
|
+
self.paths[name]
|
33
|
+
else
|
34
|
+
raise NoMethodError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,87 +1,87 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
|
4
|
-
module HerdstWorker
|
5
|
-
module Log
|
6
|
-
|
7
|
-
|
8
|
-
DEFAULT_PROGNAME = "application"
|
9
|
-
|
10
|
-
|
11
|
-
class Facade
|
12
|
-
|
13
|
-
|
14
|
-
attr_accessor :logger, :progname, :single_line, :level
|
15
|
-
|
16
|
-
|
17
|
-
def initialize(level = "DEBUG", progname = DEFAULT_PROGNAME, single_line = false)
|
18
|
-
self.progname = progname
|
19
|
-
self.single_line = single_line
|
20
|
-
|
21
|
-
self.logger = Logger.new(STDOUT)
|
22
|
-
self.logger.progname = self.get_progname(progname)
|
23
|
-
self.set_log_level(level)
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def set_log_level(level)
|
28
|
-
self.level = level
|
29
|
-
self.logger.level = Logger.const_get(level)
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def debug(*attributes)
|
34
|
-
write_message :debug, attributes
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def info(*attributes)
|
39
|
-
write_message :info, attributes
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
def warn(*attributes)
|
44
|
-
write_message :warn, attributes
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def error(*attributes)
|
49
|
-
write_message :error, attributes
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def fatal(*attributes)
|
54
|
-
write_message :fatal, attributes
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
def method_missing(name)
|
59
|
-
full_name = self.progname === DEFAULT_PROGNAME ?
|
60
|
-
name :
|
61
|
-
"#{self.progname}.#{name}"
|
62
|
-
|
63
|
-
Facade.new(self.level, full_name, self.single_line)
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def write_message(type, message)
|
68
|
-
if self.single_line
|
69
|
-
full_message = message.map { |i| i.to_s }.join(" ")
|
70
|
-
else
|
71
|
-
full_message = message.map { |i| i.to_s }.join("\n")
|
72
|
-
end
|
73
|
-
|
74
|
-
self.logger.send(type, full_message)
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
protected
|
79
|
-
def get_progname(name)
|
80
|
-
"[#{name.upcase}]"
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
|
4
|
+
module HerdstWorker
|
5
|
+
module Log
|
6
|
+
|
7
|
+
|
8
|
+
DEFAULT_PROGNAME = "application"
|
9
|
+
|
10
|
+
|
11
|
+
class Facade
|
12
|
+
|
13
|
+
|
14
|
+
attr_accessor :logger, :progname, :single_line, :level
|
15
|
+
|
16
|
+
|
17
|
+
def initialize(level = "DEBUG", progname = DEFAULT_PROGNAME, single_line = false)
|
18
|
+
self.progname = progname
|
19
|
+
self.single_line = single_line
|
20
|
+
|
21
|
+
self.logger = Logger.new(STDOUT)
|
22
|
+
self.logger.progname = self.get_progname(progname)
|
23
|
+
self.set_log_level(level)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def set_log_level(level)
|
28
|
+
self.level = level
|
29
|
+
self.logger.level = Logger.const_get(level)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def debug(*attributes)
|
34
|
+
write_message :debug, attributes
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def info(*attributes)
|
39
|
+
write_message :info, attributes
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def warn(*attributes)
|
44
|
+
write_message :warn, attributes
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def error(*attributes)
|
49
|
+
write_message :error, attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def fatal(*attributes)
|
54
|
+
write_message :fatal, attributes
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def method_missing(name)
|
59
|
+
full_name = self.progname === DEFAULT_PROGNAME ?
|
60
|
+
name :
|
61
|
+
"#{self.progname}.#{name}"
|
62
|
+
|
63
|
+
Facade.new(self.level, full_name, self.single_line)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def write_message(type, message)
|
68
|
+
if self.single_line
|
69
|
+
full_message = message.map { |i| i.to_s }.join(" ")
|
70
|
+
else
|
71
|
+
full_message = message.map { |i| i.to_s }.join("\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
self.logger.send(type, full_message)
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
protected
|
79
|
+
def get_progname(name)
|
80
|
+
"[#{name.upcase}]"
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|