herdst_worker 0.1.5 → 0.1.8

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: 2a22c87720c3490c3c559fb6504879578873ee9528ba097ac87b734cbe9006e9
4
- data.tar.gz: 3573d7bf2938987eb30746c2d3d0c8f81550e48490b4e86d64b712677a19cc43
3
+ metadata.gz: 0a1ae23a9aa07daa5d91b6d45638c6db57b506c9652f1faed6255dc0545d6dfe
4
+ data.tar.gz: fc312df7ea263f0a72d1ef3bac0ee03bef0326f8f7b093105c5c0174a53204b6
5
5
  SHA512:
6
- metadata.gz: 42b58f80f8afd138a3e293b4c03281a04175a0c99c0e03f53bc5290055ca9ac74d795b9375c244ecfc2a14c53aa01cb1843234ff3f4fdf0e441cd3efc9eb652c
7
- data.tar.gz: 739409b7e24a5af700013e0baaede632471a7ff0a876a095c85ab5a5c6f7c9e3cdc9431115b5f02751e349e62915972af6bf9fd08af06e5aae915f73dbb3e08f
6
+ metadata.gz: c7312f0e0debcd8fe80d8cac228b032689ea826c4c43ffb9457c663a1fcc52e49063cf8d27006da5309a7ad0d71163745069e0761d6f482e97998acea85fe23d
7
+ data.tar.gz: 48590ab2c15f342e70ded837c24997986cf8d2a0d965808325c1c38a7a2f59cd9ab2d4cdf358545f1dd42e7207070192157abe2d6bf6229056c164ff5d52d459
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ args = ARGV
4
+ .flat_map { |s| s.scan(/--?([^=\s]+)(?:=(\S+))?/) }
5
+ .select { |i| i[1] != "" }
6
+
7
+ arg_pair = Hash[ args ]
8
+ application_name = arg_pair["name"]
9
+ application_file = arg_pair["application"] || "application.rb"
10
+ application_path = "#{Dir.pwd}/#{application_file}"
11
+ application_env = arg_pair["env"] || "development"
12
+
13
+ raise "Please specify a name for the application E.g. --name=[name]" unless application_name
14
+
15
+ require "irb"
16
+ require "irb/completion"
17
+ require_relative "../lib/herdst_worker"
18
+
19
+ application_instance = HerdstWorker::Application.new(application_env, application_name, false)
20
+
21
+ require_relative application_path
22
+
23
+ ARGV.clear
24
+ IRB.start
@@ -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 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