tobox 0.1.0 → 0.1.2

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: 20f2b2ccbeacc67bb55403fa085c7d02bbe38e7f49263a5c006958bb35d987f2
4
- data.tar.gz: 0e69f560de1959cf87acc8b245ae02dfdf7b8beff693023a6a2651a29cb9b43d
3
+ metadata.gz: 32db59415c539b35643e125b75ea7794e4a50b9aec3bfe746d37ad36e97fadec
4
+ data.tar.gz: cbf3672ee2854cc6d6f1d835509e29480dc4e52a5370f6e6b2432ef6cde03a18
5
5
  SHA512:
6
- metadata.gz: d3588443eaf61c20ce1eebcf8b3a291ff959bc9861a5ffb157210b9790106e7ed5fe9818362539c5943d1531afbe93d8e9c84f8dd545b8d3a22d9fcede7d0a43
7
- data.tar.gz: 1d19aa8d047754f107043fcab8c6ea2835007fb1dfe206bedb2831561f5cf4616e03befe46310ac4463cbd8adf7abe532d736acc7e6790dde792c7a2ccb80972
6
+ metadata.gz: 0c1ccce590926c2ef0e9a540f949a3e4f98bfc21a157fa28d8232ecfc9b162c7a6f4d53185f851a1cc9f4c65a9b6ff0bdd8c6b038167a5eaeaa93021deca54cc
7
+ data.tar.gz: 6b5ab4017d5b04c2bd4effea9d71db04e92434efbeed8f7b5e379963439f780b0386885b8917df81169025ca5f7912f53db84c4f62d94f28fe27df5089472858
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2002-09-14
4
+
5
+ ### Bugfixes
6
+
7
+ Actual fix for foregoing json parsing.
8
+
9
+ ## [0.1.1] - 2002-09-14
10
+
11
+ ### Chore
12
+
13
+ Improved default logger, by logging the thread name, as well as providing the worker id in the lifecycle event logs.
14
+
15
+ ### Bugfixes
16
+
17
+ Do not try to json parse already parsed json columns (this happens if the DB object already has `:pg_json` extension loaded).
18
+
3
19
  ## [0.1.0] - 2022-09-05
4
20
 
5
21
  - Initial release.
data/lib/tobox/cli.rb CHANGED
@@ -17,13 +17,13 @@ module Tobox
17
17
 
18
18
  def run
19
19
  options = @options
20
- logger = Logger.new($stderr)
21
20
 
22
21
  config = Configuration.new do |c|
23
- c.logger(logger)
24
22
  c.instance_eval(File.read(options.fetch(:config_file)), options.fetch(:config_file), 1)
25
23
  end
26
24
 
25
+ logger = config.default_logger
26
+
27
27
  # boot
28
28
  options.fetch(:require).each(&method(:require))
29
29
 
@@ -25,6 +25,14 @@ module Tobox
25
25
  worker: :thread
26
26
  }.freeze
27
27
 
28
+ LOG_FORMAT_PATTERN = "%s, [%s #%d (th: %s)] %5s -- %s: %s\n"
29
+ DEFAULT_LOG_FORMATTER = Class.new(Logger::Formatter) do
30
+ def call(severity, time, progname, msg)
31
+ format(LOG_FORMAT_PATTERN, severity[0, 1], format_datetime(time), Process.pid,
32
+ Thread.current.name || Thread.current.object_id, severity, progname, msg2str(msg))
33
+ end
34
+ end.new
35
+
28
36
  def initialize(name = nil, &block)
29
37
  @name = name
30
38
  @config = DEFAULT_CONFIGURATION.dup
@@ -46,7 +54,7 @@ module Tobox
46
54
  end
47
55
 
48
56
  env = @config[:environment]
49
- @default_logger = @config[:logger] || Logger.new(STDERR) # rubocop:disable Style/GlobalStdStream
57
+ @default_logger = @config[:logger] || Logger.new(STDERR, formatter: DEFAULT_LOG_FORMATTER) # rubocop:disable Style/GlobalStdStream
50
58
  @default_logger.level = @config[:log_level] || (env == "production" ? Logger::INFO : Logger::DEBUG)
51
59
 
52
60
  freeze
data/lib/tobox/fetcher.rb CHANGED
@@ -4,7 +4,8 @@ require "json"
4
4
 
5
5
  module Tobox
6
6
  class Fetcher
7
- def initialize(configuration)
7
+ def initialize(label, configuration)
8
+ @label = label
8
9
  @configuration = configuration
9
10
 
10
11
  @logger = @configuration.default_logger
@@ -56,7 +57,7 @@ module Tobox
56
57
  num_events = events.size
57
58
 
58
59
  events.each do |ev|
59
- ev[:metadata] = JSON.parse(ev[:metadata].to_s) if ev[:metadata]
60
+ ev[:metadata] = try_json_parse(ev[:metadata])
60
61
  handle_before_event(ev)
61
62
  yield(to_message(ev))
62
63
  rescue StandardError => e
@@ -90,6 +91,10 @@ module Tobox
90
91
 
91
92
  private
92
93
 
94
+ def log_message(msg)
95
+ "(worker: #{@label}) -> #{msg}"
96
+ end
97
+
93
98
  def mark_as_error(event, error)
94
99
  @ds.where(id: event[:id]).returning.update(
95
100
  attempts: Sequel[@table][:attempts] + 1,
@@ -105,21 +110,31 @@ module Tobox
105
110
  {
106
111
  id: event[:id],
107
112
  type: event[:type],
108
- before: (JSON.parse(event[:data_before].to_s) if event[:data_before]),
109
- after: (JSON.parse(event[:data_after].to_s) if event[:data_after]),
113
+ before: try_json_parse(event[:data_before]),
114
+ after: try_json_parse(event[:data_after]),
110
115
  at: event[:created_at]
111
116
  }
112
117
  end
113
118
 
119
+ def try_json_parse(data)
120
+ return unless data
121
+
122
+ data = JSON.parse(data.to_s) unless data.respond_to?(:to_hash)
123
+
124
+ data
125
+ end
126
+
114
127
  def handle_before_event(event)
115
- @logger.debug { "outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) starting..." }
128
+ @logger.debug do
129
+ log_message("outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) starting...")
130
+ end
116
131
  @before_event_handlers.each do |hd|
117
132
  hd.call(event)
118
133
  end
119
134
  end
120
135
 
121
136
  def handle_after_event(event)
122
- @logger.debug { "outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) completed" }
137
+ @logger.debug { log_message("outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) completed") }
123
138
  @after_event_handlers.each do |hd|
124
139
  hd.call(event)
125
140
  end
@@ -127,9 +142,9 @@ module Tobox
127
142
 
128
143
  def handle_error_event(event, error)
129
144
  @logger.error do
130
- "outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) failed with error\n" \
131
- "#{error.class}: #{error.message}\n" \
132
- "#{error.backtrace.join("\n")}"
145
+ log_message("outbox event (type: \"#{event[:type]}\", attempts: #{event[:attempts]}) failed with error\n" \
146
+ "#{error.class}: #{error.message}\n" \
147
+ "#{error.backtrace.join("\n")}")
133
148
  end
134
149
  @error_event_handlers.each do |hd|
135
150
  hd.call(event, error)
@@ -9,17 +9,17 @@ module Datadog
9
9
  module Configuration
10
10
  class Settings < Contrib::Configuration::Settings
11
11
  option :enabled do |o|
12
- o.default { env_to_bool("DD_TRACE_SIDEKIQ_ENABLED", true) }
12
+ o.default { env_to_bool("DD_TOBOX_SIDEKIQ_ENABLED", true) }
13
13
  o.lazy
14
14
  end
15
15
 
16
16
  option :analytics_enabled do |o|
17
- o.default { env_to_bool("DD_TRACE_SIDEKIQ_ANALYTICS_ENABLED", false) }
17
+ o.default { env_to_bool("DD_TOBOX_SIDEKIQ_ANALYTICS_ENABLED", false) }
18
18
  o.lazy
19
19
  end
20
20
 
21
21
  option :analytics_sample_rate do |o|
22
- o.default { env_to_float("DD_TRACE_SIDEKIQ_ANALYTICS_SAMPLE_RATE", 1.0) }
22
+ o.default { env_to_float("DD_TRACE_TOBOX_ANALYTICS_SAMPLE_RATE", 1.0) }
23
23
  o.lazy
24
24
  end
25
25
 
data/lib/tobox/pool.rb CHANGED
@@ -5,7 +5,9 @@ module Tobox
5
5
  def initialize(configuration)
6
6
  @configuration = configuration
7
7
  @num_workers = configuration[:concurrency]
8
- @workers = Array.new(@num_workers) { Worker.new(configuration) }
8
+ @workers = Array.new(@num_workers) do |idx|
9
+ Worker.new("tobox-worker-#{idx}", configuration)
10
+ end
9
11
  start
10
12
  end
11
13
 
data/lib/tobox/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tobox
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/tobox/worker.rb CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Tobox
4
4
  class Worker
5
- def initialize(configuration)
5
+ def initialize(label, configuration)
6
6
  @wait_for_events_delay = configuration[:wait_for_events_delay]
7
7
  @handlers = configuration.handlers || {}
8
- @fetcher = Fetcher.new(configuration)
8
+ @fetcher = Fetcher.new(label, configuration)
9
9
  @finished = false
10
10
 
11
11
  return unless (message_to_arguments = configuration.arguments_handler)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tobox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - HoneyryderChuck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel