debounced 3.0.0 → 4.0.0

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: 545ffc360ed1f13cb95fbec250c45bed7744f932cb8865890019594c3ec30be3
4
- data.tar.gz: 7a2e349b770b02a29c108af1c6fed682901971afebf9fac5b272dab4570eccbf
3
+ metadata.gz: daa35f9312614c9334ddcb04cd3b569fe070e952b544ceee739b2400a49eefca
4
+ data.tar.gz: 50c4d30cc47754c0370f984fad5f74626199ab43394160d1c538f1b651db0dfe
5
5
  SHA512:
6
- metadata.gz: c64730cb742be03954ca2caaf8b3145c4c7a2e016b9f65d5a737dfda3e8d51d49f98aad35d213abf2aacb360ff9b5e83f29a5cf4cdcb98154a60c40c31a40698
7
- data.tar.gz: 4fe5b3d2563d3cadd547c9e7beac16811ff421716151eb4bdb184b2c7c39a7527729c44b0d269a03ef37db08ca91505445bd6446e07bb43b007c1357d8b6840c
6
+ metadata.gz: 1373f6bf67a372eab97c5f932452cb5f244fd015aece067800c1146f1121686c681e3ab7318c050e75cd4a5b28df911dade2965fd3a1a57c9cb9b4a3a5da66f0
7
+ data.tar.gz: ade42af6dc1f0ec81473cdd19ed33e6a3eba213273ebf7dc7478b2018f1b9db31b4e124e7ab81af00cd2374009d4151ef0a5897e4da041bee6982fa739cf3e1c
data/CHANGELOG.md CHANGED
@@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [3.0.0] - Unreleased
8
+ ## [4.0.0] - 2026-12-02
9
+
10
+ ### Added
11
+
12
+ - `debounced-server` executable, which starts the server without booting the host application; `--config FILE` loads
13
+ a Ruby file that calls `Debounced.configure`.
14
+ - The previous `debounced:server` rake task booted the whole host application (every gem in its bundle, plus its app
15
+ code) only to read the socket path, so the server used as much memory as the app. The executable loads only the gem
16
+ and the config file, so the server uses about as much memory as the gem alone.
17
+
18
+ ### Changed
19
+
20
+ - The default logger writes to stdout instead of `debounced_proxy.log`
21
+
22
+ ### Removed
23
+
24
+ - The `debounced:server` rake task and the Railtie that loaded it; start the server with `debounced-server` instead
25
+
26
+ ## [3.0.0] - 2026-11-12
9
27
 
10
28
  ### Changed
11
29
 
data/README.md CHANGED
@@ -25,28 +25,40 @@ $ gem install debounced
25
25
 
26
26
  ## Usage
27
27
 
28
+ Debounced runs as two processes that talk over a Unix socket:
29
+
30
+ - **The server** keeps one timer per activity. It is a standalone executable that loads only the gem and a
31
+ config file.
32
+ - **Your application** sends activity to the server through `Debounced::ServiceProxy`, and runs the callbacks the
33
+ server sends back when timers expire.
34
+
35
+ Both load the same config file, so they agree on the socket.
36
+
28
37
  ### Configuration
29
38
 
30
39
  ```ruby
31
- # config/initializers/debounced.rb
40
+ # config/debounced.rb
32
41
  Debounced.configure do |config|
33
42
  config.socket_descriptor = '/tmp/my_app.debounceEvents'
34
43
  config.wait_timeout = 3 # idle timeout in seconds for a given activity descriptor
35
44
  end
36
45
  ```
37
46
 
38
- ### Starting the server
47
+ By default the gem logs to stdout through `semantic_logger`. Set `config.logger` to use another logger.
39
48
 
40
- Start the debounce server with:
49
+ ### Starting the server
41
50
 
42
51
  ```bash
43
- $ bundle exec rake debounced:server
52
+ $ bundle exec debounced-server --config config/debounced.rb
44
53
  ```
45
54
 
46
- In your Ruby application code:
55
+ ### Debouncing activity in your application
56
+
57
+ Load the same config file, then create a proxy:
47
58
 
48
59
  ```ruby
49
60
  require 'debounced'
61
+ require_relative 'config/debounced'
50
62
 
51
63
  # Start a background thread to receive notification that events are ready to be handled after debounce wait is complete
52
64
  proxy = Debounced::ServiceProxy.new
@@ -89,6 +101,22 @@ proxy.debounce_activity("my-event-123", 5, event.debounce_callback)
89
101
  # > Publishing event: #<MyEvent:0x00007f9b1b8b3b40 @test_id="Hello World">
90
102
  ```
91
103
 
104
+ ### In a Rails application
105
+
106
+ Load the config file from an initializer. The initializer is also the place for settings that only apply to your
107
+ application: Rails' logger, and an `error_handler` for callbacks that raise (callbacks run in your application, never in
108
+ the server).
109
+
110
+ ```ruby
111
+ # config/initializers/debounced.rb
112
+ require Rails.root.join('config/debounced')
113
+
114
+ Debounced.configure do |config|
115
+ config.logger = Rails.logger
116
+ config.error_handler = ->(error, callback) { Rails.error.report(error, context: { callback: callback.as_json }) }
117
+ end
118
+ ```
119
+
92
120
  ### Shutting down
93
121
 
94
122
  On SIGTERM the server stops debouncing: pending timers still fire on schedule, requests that arrive afterwards are
@@ -134,4 +162,4 @@ To measure another server, pass its command: `bin/benchmark node path/to/server.
134
162
 
135
163
  ## License
136
164
 
137
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
165
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optparse'
5
+ require 'debounced'
6
+ require 'debounced/server'
7
+
8
+ # Write each log line as it happens; Ruby buffers stdout when it isn't a terminal (e.g. on Heroku)
9
+ $stdout.sync = true
10
+
11
+ config_file = nil
12
+ OptionParser.new do |opts|
13
+ opts.banner = 'Usage: debounced-server [--config FILE]'
14
+ opts.on('--config FILE', 'Ruby file that calls Debounced.configure') { |file| config_file = file }
15
+ end.parse!
16
+
17
+ load File.expand_path(config_file) if config_file
18
+
19
+ Debounced::Server.new(Debounced.configuration.socket_descriptor).listen
@@ -1,3 +1,3 @@
1
1
  module Debounced
2
- VERSION = "3.0.0"
2
+ VERSION = "4.0.0"
3
3
  end
data/lib/debounced.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'debounced/version'
2
- require 'debounced/railtie' if defined?(Rails)
3
2
  require 'debounced/no_server_error'
4
3
  require 'debounced/socket_conflict_error'
5
4
  require 'debounced/service_proxy'
@@ -32,7 +31,7 @@ module Debounced
32
31
  def logger
33
32
  return @logger if defined? @logger
34
33
 
35
- SemanticLogger.add_appender(file_name: 'debounced_proxy.log', formatter: :color)
34
+ SemanticLogger.add_appender(io: $stdout)
36
35
  SemanticLogger.default_level = ENV.fetch('LOG_LEVEL', 'info')
37
36
  @logger = SemanticLogger['ServiceProxy']
38
37
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debounced
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -119,46 +119,26 @@ dependencies:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
121
  version: '3.0'
122
- - !ruby/object:Gem::Dependency
123
- name: debug
124
- requirement: !ruby/object:Gem::Requirement
125
- requirements:
126
- - - "~>"
127
- - !ruby/object:Gem::Version
128
- version: '1.0'
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: 1.0.0
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '1.0'
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- version: 1.0.0
142
122
  description: Debounce Ruby callbacks across processes through a lightweight Ruby timer
143
123
  server
144
124
  email:
145
125
  - gary@flytedesk.com
146
- executables: []
126
+ executables:
127
+ - debounced-server
147
128
  extensions: []
148
129
  extra_rdoc_files: []
149
130
  files:
150
131
  - CHANGELOG.md
151
132
  - README.md
133
+ - exe/debounced-server
152
134
  - lib/debounced.rb
153
135
  - lib/debounced/callback.rb
154
136
  - lib/debounced/callbackable.rb
155
137
  - lib/debounced/no_server_error.rb
156
- - lib/debounced/railtie.rb
157
138
  - lib/debounced/server.rb
158
139
  - lib/debounced/service_proxy.rb
159
140
  - lib/debounced/socket_conflict_error.rb
160
141
  - lib/debounced/version.rb
161
- - lib/tasks/debounced.rake
162
142
  homepage: https://github.com/Flytedesk/debounced-rb
163
143
  licenses:
164
144
  - MIT
@@ -1,9 +0,0 @@
1
- require "rails/railtie"
2
-
3
- module Debounced
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- load File.expand_path("../../tasks/debounced.rake", __FILE__)
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- namespace :debounced do
2
- desc 'Start the debounce server'
3
- task server: :environment do
4
- require 'debounced'
5
- require 'debounced/server'
6
-
7
- Debounced::Server.new(Debounced.configuration.socket_descriptor).listen
8
- end
9
- end