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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4db06011c97482874347cf7e1c3300a9be6c6e2f624e5d4e5b47583db671762
4
- data.tar.gz: 5451e470825822eaa0387cef72c55a12d7b44c79ea829fef6a455f065932841c
3
+ metadata.gz: 3de398e124491be06479567865179d713005b2febcca984cade36bfe0052955f
4
+ data.tar.gz: 693dc282a8feb3450ff1f97833185aea1682a467897f075181c2235c14808e78
5
5
  SHA512:
6
- metadata.gz: 5471195f87658b0b67125bfd648026d5bc36c82debc634f8b3424e72e7049877e375466c032aac6c4b14277c296c473f50979dd1e0b8a7fa31c7122f26aedd22
7
- data.tar.gz: 6601e22494f9049c2133553e7af958d0e00979a07ca55f1ab0256981e942348b1ed5dc651dd1a41e4990062e69855f6c130a2bab466acac983b195e6ff9cffd4
6
+ metadata.gz: 05e0d56aac10f61c9c399471c4a7c356549cf75cf1fa8f223b1b377200ad6b54e2b675f8a20c544eb0f225574a9ba83e039bc46d06a8c7bfbf8c98e2ebbf8f52
7
+ data.tar.gz: cbf2e9433d2275e7a8ab4a4651e634f96491d0170fc71346dec6e5ad14238ae54af81bdf5a437c600378ae1601c8d18e617c8eda2d7daf2a9c438f398b8cb2b2
@@ -4,7 +4,6 @@ module HerdstWorker
4
4
 
5
5
 
6
6
  def self.setup(app)
7
-
8
7
  begin
9
8
  db_config = app.config_for(:database)
10
9
 
@@ -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
@@ -7,7 +7,7 @@ module HerdstWorker
7
7
 
8
8
 
9
9
  def self.setup(app)
10
- rescue
10
+ begin
11
11
  environment = app.config.metadata[:DEPLOYMENT_ENV]
12
12
  release = app.config.metadata[:RELEASE_VERSION]
13
13
  sentry_key = app.config.metadata[:SENTRY_KEY]
@@ -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 add_queue(name, url, poller = false)
42
- self.queues[name] = url
43
- self.poller_url = url if poller
44
- end
45
-
46
-
47
- def run
48
- if self.queue == nil
49
- self.logger.info "Starting Application (#{$$})"
50
-
51
- HerdstWorker::Signals::Facade.listen(self.config.paths.temp)
52
-
53
- self.queue = HerdstWorker::Queue::Facade.new(self, self.poller_enabled, self.poller_url, 20)
54
- self.queue.start
55
- end
56
- end
57
-
58
-
59
- def config_for(name)
60
- self.config.config_for(name)
61
- end
62
-
63
-
64
- private
65
- def set_inflections
66
- ActiveSupport::Inflector.inflections do |inflect|
67
- inflect.irregular "meta", "meta"
68
- end
69
- end
70
-
71
- def get_logger_level(env)
72
- return "WARN" if env == "production"
73
- return "FATAL" if env == "test"
74
- return "DEBUG"
75
- end
76
-
77
-
78
- end
79
-
80
-
81
- def self.set_application(application)
82
- @@application = application
83
- end
84
-
85
-
86
- def self.application
87
- @@application
88
- end
89
- end
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
@@ -24,7 +24,11 @@ module HerdstWorker
24
24
  begin
25
25
  self.reload!
26
26
  rescue Exception => ex
27
- raise ex unless self.is_prod?
27
+ if self.is_prod?
28
+ puts "Failed to load metadata: #{ex.message}"
29
+ else
30
+ raise ex
31
+ end
28
32
  end
29
33
  end
30
34
 
@@ -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