herdst_worker 0.1.6 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd3d83d5c9eed1daf41c0c8e9da9da90bce24f9abcf9e8e244b7c8da1115947c
4
- data.tar.gz: 127e7147df4a561a8f1fcb6d9030e679d46e044e942333ae8e94eab2d018df0d
3
+ metadata.gz: e394fc18334aecfcbb21d5c9e639067a1f777b2d137edd9fb404bc6c86722613
4
+ data.tar.gz: ed79d59376596ec7f57d753d9c87f5ed939362834fdbde91a84392857f304a65
5
5
  SHA512:
6
- metadata.gz: d5eff402b28ecb69fa5a084ee36d624a6d1f33b42345d6137f14df98069103221ccbce40582c4b95c1d13eb277cd7665576d4ee16d770fa9bd4b0b71f52ddef3
7
- data.tar.gz: a1c1648befbdb86e76d76d39d59a090ccfc1a93c477c200637f8ec738b0e356c077d84c770501723cd65ac95dc7a430c15dd1a8fdb8782e6b45be83d92a5e661
6
+ metadata.gz: 8e4f9442a39b0d8b0e14ce93c14963ce7ca9297e054a9df5d66e0a1e335de543731ccef5b8fd41939efa74907ca7c1167bb3b60ed65404d7c6f497da84ca7739
7
+ data.tar.gz: 49e2e8e2e01b3fcebf58b48f253cf763f59b18013b560aabe80f719ed2f52b0594494f9809e2e3c0bb3429ba71644622b9c04632cd90fc4118a55219bffaace5
@@ -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
@@ -6,23 +6,17 @@ module HerdstWorker
6
6
  def self.setup(app)
7
7
  begin
8
8
  db_config = app.config_for(:database)
9
-
9
+ db_config.each do |k, v|
10
+ db_config[k] = ActiveRecord::DatabaseConfigurations::HashConfig.new(app.config.env, k, v)
11
+ end
12
+
10
13
  if app.config.is_dev?
11
14
  ActiveRecord::Base.logger = app.logger.activerecord
12
15
  end
13
16
 
17
+ ActiveRecord::Base.configurations = db_config.values
14
18
  ActiveRecord::Base.default_timezone = :utc
15
- ActiveRecord::Base.establish_connection(
16
- adapter: db_config[:adapter],
17
- encoding: db_config[:encoding],
18
- charset: db_config[:charset],
19
- collation: db_config[:collation],
20
- pool: db_config[:pool],
21
- host: db_config[:host],
22
- username: db_config[:username],
23
- password: db_config[:password],
24
- database: db_config[:database]
25
- )
19
+ ActiveRecord::Base.establish_connection(db_config[:primary])
26
20
  ActiveRecord::Base.connection.enable_query_cache!
27
21
  rescue Exception => ex
28
22
  app.logger.error ex.message
@@ -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
@@ -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