tobox 0.4.0 → 0.4.1

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: f162a3a57381f1e5e15ddb1034e82bdd7fcddc720f6fa38264351c6e04407aa9
4
- data.tar.gz: 7b4ca98af244fff5ee76eb38141047b1c97ee40dd79c942cdb0e82480b8f8439
3
+ metadata.gz: 4960d6151461ab6e051605687d99cc69089e498aaea66d97416b92158e48cc4e
4
+ data.tar.gz: e3f2e0a6408696ff1852a484101ca6fa95e5e5e713d1ccb0b829040bb0a748ad
5
5
  SHA512:
6
- metadata.gz: 673ead552e6419b25e876e13134fc4b9b04f9505544f04f572570c2bc8d7495f8e5e511047d4545c4bd6ff03a3b0e472c65ec69b8a40ffe355931e3bdb907a4d
7
- data.tar.gz: 52ba20bddfaaafb13555fc4e72860feea2bb9377480191dcce5be291d136831559f3579467fc44f032cd94ac833094938264a193af558a334b51d2b6550801bd
6
+ metadata.gz: ac5d961bc737299d4cd1e3d353955f97b12d984e4b3378b56dbeaf84c5d969ed3b6c02902c70b7ed0fd14230696d44992012d35053565988349b13405f6144ef
7
+ data.tar.gz: 3a921e5ca3f42fa47f8485a0a9bf44c42c31f0f767cfafc81ef1af6d6e43ac83966baffcb20ff28df9c90abb8a4c16e6829c4e9aa9e86ca009ab4fde38a92bd1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] - 2023-05-24
4
+
5
+ ### Features
6
+
7
+ #### `on_database_connect`
8
+
9
+ this adds an extension point for internal sequel database objects, in cases where some tweaks are required (such as in the case of, when using database SSL proxies, setting connection validators).
10
+
11
+ ```ruby
12
+ # tobox.rb
13
+ on_database_connect do |db|
14
+ db.extension(:connection_validator)
15
+ end
16
+ ```
17
+
3
18
  ## [0.4.0] - 2023-05-19
4
19
 
5
20
  ### Features
data/README.md CHANGED
@@ -268,6 +268,20 @@ callback executed when an exception was raised in the worker, before processing
268
268
  on_error_worker { |exception| Sentry.capture_exception(exception) }
269
269
  ```
270
270
 
271
+ ### `on_database_connect { |db| }`
272
+
273
+ Callback executed right after initializing the `sequel` database object. This can be used, for example, to load database-level extensions and plugins, and set parameters (such as connection pool tweaks). This callback will also be used by plugins which instantiate its own separate database objects (such as in the case of the [stats](#stats) plugin).
274
+
275
+ This callback won't be executed if the database object is created outside of `tobox` configuration parameters.
276
+
277
+
278
+ ```ruby
279
+ on_database_connect do |db|
280
+ db.extension(:connection_validator)
281
+ db.pool.connection_validation_timeout = -1
282
+ end
283
+ ```
284
+
271
285
  ### `message_to_arguments { |event| }`
272
286
 
273
287
  if exposing raw data to the `on` handlers is not what you'd want, you can always override the behaviour by providing an alternative "before/after fetcher" implementation.
@@ -63,7 +63,9 @@ module Tobox
63
63
  @database = if @config[:database_uri]
64
64
  database_opts = {}
65
65
  database_opts[:max_connections] = @config[:concurrency] if @config[:worker] == :thread
66
- Sequel.connect(@config[:database_uri].to_s, database_opts)
66
+ db = Sequel.connect(@config[:database_uri].to_s, database_opts)
67
+ Array(@lifecycle_events[:database_connect]).each { |cb| cb.call(db) }
68
+ db
67
69
  else
68
70
  Sequel::DATABASES.first
69
71
  end
@@ -116,6 +118,11 @@ module Tobox
116
118
  self
117
119
  end
118
120
 
121
+ def on_database_connect(&callback)
122
+ (@lifecycle_events[:database_connect] ||= []) << callback
123
+ self
124
+ end
125
+
119
126
  def message_to_arguments(&callback)
120
127
  @arguments_handler = callback
121
128
  self
@@ -35,6 +35,8 @@ module Tobox
35
35
  @max_attempts = config[:max_attempts]
36
36
 
37
37
  @db = Sequel.connect(config.database.opts.merge(single_threaded: true))
38
+ Array(config.lifecycle_events[:database_connect]).each { |cb| cb.call(@db) }
39
+
38
40
  @outbox_table = config[:table]
39
41
  @outbox_ds = @db[@outbox_table]
40
42
 
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.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - HoneyryderChuck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-19 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel