hot_catch 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: d30ed8cb373a76a5c27b352bb56a5f0694bf4f7e
4
- data.tar.gz: 7938dab531e6cde13405ea25831f5097f1a6a75a
3
+ metadata.gz: 5e967ecad6a61c73d819ae49740dfd6a699d82bc
4
+ data.tar.gz: d52e3f714e75b020432cdcc210cab29714c9e141
5
5
  SHA512:
6
- metadata.gz: 8d70f6af9e7b6133465bcb85c9acb36639ca44f9c8522bb5fb598fc69e8a25c3f24fddf006cdf4ee064c4dde5a6e8efe51f3d604ba07cedb050d84ba4a2ec7da
7
- data.tar.gz: 6f430732e4f7432361d6c09d0ecc94d873730a3442f49bb6c312a8fcca9b377e9e6d70f876e023dee1ba2524d564251751983fed363b8dbf6ec6a71f2517049c
6
+ metadata.gz: b322d92ec1115075167542bb45c5a7f743163edf1090b9cf59d2d91e7ae066d9794580c9503ab5e5ccaf671b44ebaf5644e07ed6be8084f02742631721b6152f
7
+ data.tar.gz: 1fde06ff1e9cb835018e8af381ccd4a667167a8610894176136274b42abf189a12ea09074d2a3927094e513f389023abff934f645b838bcdbc1889c7de5797c8
data/README.md CHANGED
@@ -11,6 +11,8 @@ gem 'hot_catch'
11
11
  Для удаления: `$ rails generate hot_catch:uninstall`
12
12
  4. Изменить в `config/hot_catch_config.json` url - адрес сервера для отправки лог файлов.
13
13
  Автоматически запросы посылаются на адрес *url/main_hot_catch_logs*, но нужно указать только *url*.
14
+ 5. Запустить sidekiq
15
+ `bundle exec sidekiq`
14
16
 
15
17
  Это всё! Теперь логи автоматически посылаются на сервер.
16
18
 
@@ -7,7 +7,7 @@ module HotCatch
7
7
  # Включение всех файлов из указанной папки относительно __FILE__ (то есть текущего файла)
8
8
  source_root File.expand_path('../../../hot_catch', __FILE__)
9
9
  # include Rails::Generators::Migration
10
-
10
+
11
11
  def add_rack_logger
12
12
  copy_file "hot_catch_logger.rb", "config/hot_catch_logger.rb"
13
13
  end
@@ -37,5 +37,10 @@ module HotCatch
37
37
  "Rails.application.config.sender_logs = HotCatch::MakeHttpsRequest.new"
38
38
  end
39
39
  end
40
+
41
+ # def add_sidekiq_job
42
+ # empty_directory "app/workers"
43
+ # copy_file "hard_worker.rb", "app/workers/hard_worker.rb"
44
+ # end
40
45
  end
41
46
  end
@@ -14,8 +14,8 @@ module HotCatch
14
14
  gsub_file "config/application.rb", /require_relative 'hot_catch_logger'/, ""
15
15
  gsub_file "config/application.rb", /config.*Logger/, ""
16
16
 
17
- gsub_file "config/environments/development.rb", /.*\s.*hot_catch_buf_file'\)\)/, ""
18
- gsub_file "config/environments/production.rb", /.*\s.*hot_catch_buf_file'\)\)/, ""
17
+ gsub_file "config/environments/development.rb", /.*\s.*hot_catch_buf_file'\)\)\s*/, ""
18
+ gsub_file "config/environments/production.rb", /.*\s.*hot_catch_buf_file'\)\)\s*/, ""
19
19
  end
20
20
 
21
21
  def remove_log_files
@@ -30,5 +30,10 @@ module HotCatch
30
30
  remove_file "config/initializers/hot_catch_sender_logs.rb"
31
31
  end
32
32
 
33
+ # def remove_sidekiq_job
34
+ # remove_file "app/workers/hard_worker.rb"
35
+ # Dir.delete("app/workers")
36
+ # end
37
+
33
38
  end
34
39
  end
@@ -0,0 +1,10 @@
1
+ require 'sidekiq'
2
+ class HardWorker
3
+ include Sidekiq::Worker
4
+ sidekiq_options :retry => false
5
+ def perform(body_log, url)
6
+ sender = HotCatch::MakeHttpsRequest.new(url)
7
+ sender.send_log(body_log)
8
+ sender = nil
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module HotCatch
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
data/lib/hot_catch.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module HotCatch
2
+ require 'hot_catch/hard_worker'
3
+
2
4
  require 'hot_catch/custom_log_subscribers.rb'
3
5
  require 'uri'
4
6
  require 'net/https'
@@ -21,10 +23,12 @@ module HotCatch
21
23
  # ======================================================================
22
24
 
23
25
  class MakeHttpsRequest
24
- def initialize
25
- @url = ""
26
- File.open("config/hot_catch_config.json"){ |file| @url = JSON.parse(file.read)["url"] }
27
- @url += "/main_hot_catch_logs"
26
+ def initialize(url = nil)
27
+ @url = url
28
+ unless @url
29
+ File.open("config/hot_catch_config.json"){ |file| @url = JSON.parse(file.read)["url"] }
30
+ @url += "/main_hot_catch_logs"
31
+ end
28
32
  end
29
33
 
30
34
  def rails_g_log(log_data, status)
@@ -41,15 +45,21 @@ module HotCatch
41
45
  end
42
46
 
43
47
  def send_log(body_log)
44
- response = call(@url, body_log)
45
- # если на зпрос пришёл ответ, то пришло уведомление об ошибке, которое логируется
46
- unless response.empty?
47
- str = "\n" + (?-*20) + "\n#{Time.now}\nlogs:\n#{body_log.to_s}\nresponse\n:#{response}\n" + (?-*20) + "\n"
48
- File.open("log/hot_catch_log_response_errors", 'a'){ |file| file.write str.encode('UTF-8', {
49
- :invalid => :replace,
50
- :undef => :replace,
51
- :replace => '?'
52
- }) }
48
+ begin
49
+ response = call(@url, body_log)
50
+ # если на запрос пришёл ответ, то пришло уведомление об ошибке, которое логируется
51
+ # Кроме того данное сообщение помещается в очередь и отправляется через какое-то время
52
+ unless response.empty?
53
+ str = "\n" + (?-*20) + "\n#{Time.now}\nlogs:\n#{body_log.to_s}\nresponse\n:#{response}\n" + (?-*20) + "\n"
54
+ File.open("log/hot_catch_log_response_errors", 'a'){ |file| file.write str.encode('UTF-8', {
55
+ :invalid => :replace,
56
+ :undef => :replace,
57
+ :replace => '?'
58
+ }) }
59
+ HardWorker.perform_in(10.seconds, body_log, @url)
60
+ end
61
+ rescue
62
+ HardWorker.perform_in(10.seconds, body_log, @url)
53
63
  end
54
64
  end
55
65
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot_catch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davhot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Description of Testgem.
14
28
  email:
15
29
  - david.home@mail.ru
@@ -24,6 +38,7 @@ files:
24
38
  - lib/generators/hot_catch/uninstall_generator.rb
25
39
  - lib/hot_catch.rb
26
40
  - lib/hot_catch/custom_log_subscribers.rb
41
+ - lib/hot_catch/hard_worker.rb
27
42
  - lib/hot_catch/hot_catch_logger.rb
28
43
  - lib/hot_catch/version.rb
29
44
  - lib/tasks/hot_catch_tasks.rake