console_buddy 0.1.10 → 0.1.12
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 +4 -4
- data/lib/console_buddy/augment.rb +1 -0
- data/lib/console_buddy/helpers.rb +1 -0
- data/lib/console_buddy/jobs/sidekiq.rb +37 -1
- data/lib/console_buddy/railtie.rb +12 -0
- data/lib/console_buddy/version.rb +1 -1
- data/lib/console_buddy.rb +42 -14
- data/spec/console_buddy/jobs/sidekiq_spec.rb +23 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0504ca9ff8240411ff068b75153cebe7f89cbaa4be44bf8726be62b831cbfea9
|
|
4
|
+
data.tar.gz: 18bdb410d8ac32ebc4c2c8ec1687706830ab66d51ec6afa61d54d8bd9a437485
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c1fa8bb7b7b3f399ddad25140108758627bfb78e0b2d569ce41221d4a4a906653c9f24ac0b42656518cc8ecc7595867b16c0d0482a8c9a7d10a1633e145ef73
|
|
7
|
+
data.tar.gz: 651591c77cf11cf9595df8cb8d4b7e1eca7cbbc15958f1f492452528d92f5ffe9cf03ffe466961b457a54f4d630b58d2be7a138e52ed5d15020528e6cdd30dc2
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
require_relative "../one_off_job"
|
|
4
4
|
|
|
5
5
|
# Example Usage: ConsoleBuddy::Jobs::Sidekiq.perform_later("foo", "bar")
|
|
6
|
-
#
|
|
6
|
+
#
|
|
7
7
|
# This class is used to integrate the ConsoleBuddy::OneOffJob with Sidekiq.
|
|
8
|
+
# Set ConsoleBuddy.one_off_job_sidekiq_queue in .console_buddy/config.rb when your
|
|
9
|
+
# app forbids the default queue (e.g. queue governance / Sidekiq Pro).
|
|
8
10
|
module ConsoleBuddy
|
|
9
11
|
module Jobs
|
|
10
12
|
class Sidekiq
|
|
@@ -13,6 +15,40 @@ module ConsoleBuddy
|
|
|
13
15
|
def perform(*args)
|
|
14
16
|
::ConsoleBuddy::OneOffJob.perform(*args)
|
|
15
17
|
end
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
def perform_async(*args)
|
|
21
|
+
q = configured_sidekiq_queue
|
|
22
|
+
if q.present?
|
|
23
|
+
if respond_to?(:set)
|
|
24
|
+
set(queue: q).perform_async(*args)
|
|
25
|
+
else
|
|
26
|
+
push_with_queue(args, q)
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def configured_sidekiq_queue
|
|
36
|
+
return unless defined?(::ConsoleBuddy) && ::ConsoleBuddy.respond_to?(:one_off_job_sidekiq_queue)
|
|
37
|
+
|
|
38
|
+
q = ::ConsoleBuddy.one_off_job_sidekiq_queue
|
|
39
|
+
return if q.nil? || (q.respond_to?(:empty?) && q.empty?)
|
|
40
|
+
|
|
41
|
+
q.respond_to?(:to_sym) ? q.to_sym : q
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def push_with_queue(args, queue)
|
|
45
|
+
::Sidekiq::Client.push(
|
|
46
|
+
"class" => name,
|
|
47
|
+
"args" => args,
|
|
48
|
+
"queue" => queue.to_s
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
16
52
|
end
|
|
17
53
|
end
|
|
18
54
|
end
|
|
@@ -5,6 +5,18 @@ require 'rails/railtie'
|
|
|
5
5
|
# Load console buddy when the Rails console is started
|
|
6
6
|
module ConsoleBuddy
|
|
7
7
|
class Railtie < ::Rails::Railtie
|
|
8
|
+
# Queue linters and Sidekiq boot load worker classes without running `rails console`, so
|
|
9
|
+
# `.console_buddy/config.rb` never runs. Set CONSOLE_BUDDY_SIDEKIQ_QUEUE to an allowed queue name
|
|
10
|
+
# (e.g. in .env or your process manager) so ConsoleBuddy::Jobs::Sidekiq is not registered on `default`.
|
|
11
|
+
initializer "console_buddy.sidekiq_queue_from_env" do
|
|
12
|
+
next unless defined?(::ConsoleBuddy::Jobs::Sidekiq)
|
|
13
|
+
|
|
14
|
+
queue = ENV["CONSOLE_BUDDY_SIDEKIQ_QUEUE"].to_s.strip
|
|
15
|
+
next if queue.empty?
|
|
16
|
+
|
|
17
|
+
::ConsoleBuddy::Jobs::Sidekiq.sidekiq_options queue: queue.to_sym
|
|
18
|
+
end
|
|
19
|
+
|
|
8
20
|
console do
|
|
9
21
|
::ConsoleBuddy.start!
|
|
10
22
|
end
|
data/lib/console_buddy.rb
CHANGED
|
@@ -2,16 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require 'pathname'
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
console_buddy_path = Pathname.new(File.join(Dir.pwd, '.console_buddy'))
|
|
8
|
-
console_buddy_path.exist? && console_buddy_path.directory?
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
if !console_buddy_directory_exists?
|
|
12
|
-
return
|
|
13
|
-
end
|
|
14
|
-
|
|
5
|
+
# Always load the module; .console_buddy existence is checked in start! when Rails.root is set
|
|
6
|
+
# (Rails 7.2 / Spring can require gems before Rails.root is available)
|
|
15
7
|
require 'active_support'
|
|
16
8
|
require 'active_support/all'
|
|
17
9
|
|
|
@@ -59,7 +51,8 @@ end
|
|
|
59
51
|
|
|
60
52
|
module ConsoleBuddy
|
|
61
53
|
class << self
|
|
62
|
-
attr_accessor :verbose_console, :allowed_envs, :use_in_debuggers, :ignore_startup_errors, :use_in_tests, :one_off_job_service_type
|
|
54
|
+
attr_accessor :verbose_console, :allowed_envs, :use_in_debuggers, :ignore_startup_errors, :use_in_tests, :one_off_job_service_type,
|
|
55
|
+
:one_off_job_sidekiq_queue
|
|
63
56
|
|
|
64
57
|
def store
|
|
65
58
|
@store ||= ::ConsoleBuddy::MethodStore.new
|
|
@@ -68,8 +61,11 @@ module ConsoleBuddy
|
|
|
68
61
|
def start!
|
|
69
62
|
# Initialize the default values
|
|
70
63
|
set_config_defaults
|
|
64
|
+
# Require .console_buddy to exist (check here when Rails.root is set; avoids Rails 7.2 / Spring load-order issues)
|
|
65
|
+
return unless console_buddy_directory_exists?
|
|
71
66
|
# Check if there is a .console_buddy/config file
|
|
72
67
|
load_console_buddy_config
|
|
68
|
+
apply_sidekiq_queue_to_worker
|
|
73
69
|
|
|
74
70
|
# Only start the buddy in the allowed environments. e.g. development, test
|
|
75
71
|
return if !allowed_env?
|
|
@@ -106,6 +102,7 @@ module ConsoleBuddy
|
|
|
106
102
|
@ignore_startup_errors = false
|
|
107
103
|
@allowed_envs = %w[development test]
|
|
108
104
|
@one_off_job_service_type = :inline
|
|
105
|
+
@one_off_job_sidekiq_queue = nil
|
|
109
106
|
end
|
|
110
107
|
|
|
111
108
|
# Only start the buddy in the allowed environments
|
|
@@ -129,9 +126,22 @@ module ConsoleBuddy
|
|
|
129
126
|
ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
|
130
127
|
end
|
|
131
128
|
|
|
129
|
+
# App root so .console_buddy is found under Rails (e.g. with Spring) or Dir.pwd
|
|
130
|
+
def console_buddy_root
|
|
131
|
+
if defined?(Rails) && Rails.respond_to?(:root) && Rails.root.present?
|
|
132
|
+
Pathname.new(Rails.root.to_s)
|
|
133
|
+
else
|
|
134
|
+
Pathname.new(Dir.pwd)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def console_buddy_directory_exists?
|
|
139
|
+
console_buddy_root.join('.console_buddy').exist? && console_buddy_root.join('.console_buddy').directory?
|
|
140
|
+
end
|
|
141
|
+
|
|
132
142
|
# Loads the .console_buddy/config file if present
|
|
133
143
|
def load_console_buddy_config
|
|
134
|
-
config_path =
|
|
144
|
+
config_path = console_buddy_root.join('.console_buddy', 'config.rb')
|
|
135
145
|
if config_path.exist? && config_path.file?
|
|
136
146
|
require config_path.to_s
|
|
137
147
|
else
|
|
@@ -139,10 +149,20 @@ module ConsoleBuddy
|
|
|
139
149
|
end
|
|
140
150
|
end
|
|
141
151
|
|
|
152
|
+
# Sync Sidekiq worker metadata so queue auditors and Sidekiq see a real queue (not the default queue).
|
|
153
|
+
def apply_sidekiq_queue_to_worker
|
|
154
|
+
return unless defined?(::ConsoleBuddy::Jobs::Sidekiq)
|
|
155
|
+
|
|
156
|
+
q = ConsoleBuddy.one_off_job_sidekiq_queue
|
|
157
|
+
return if q.blank?
|
|
158
|
+
|
|
159
|
+
::ConsoleBuddy::Jobs::Sidekiq.sidekiq_options queue: q.to_sym
|
|
160
|
+
end
|
|
161
|
+
|
|
142
162
|
# Loads all the files in the .console_buddy folder
|
|
143
163
|
# .console_buddy folder should be in the root of the project
|
|
144
164
|
def load_console_buddy_files
|
|
145
|
-
console_buddy_path =
|
|
165
|
+
console_buddy_path = console_buddy_root.join('.console_buddy')
|
|
146
166
|
if console_buddy_path.exist? && console_buddy_path.directory?
|
|
147
167
|
console_buddy_path.find do |path|
|
|
148
168
|
next unless path.file?
|
|
@@ -188,6 +208,8 @@ module ConsoleBuddy
|
|
|
188
208
|
end
|
|
189
209
|
end
|
|
190
210
|
|
|
211
|
+
public :augment_classes, :augment_console
|
|
212
|
+
|
|
191
213
|
# This will add the buddy methods to the IRB session
|
|
192
214
|
# So that they can be called without instantiating the `ConsoleBuddy::Base` class
|
|
193
215
|
def start_buddy_in_irb
|
|
@@ -204,6 +226,12 @@ module ConsoleBuddy
|
|
|
204
226
|
Rails::ConsoleMethods.include(ConsoleBuddy::IRB)
|
|
205
227
|
load_progress_bar
|
|
206
228
|
end
|
|
229
|
+
# Pry: ensure console methods are on the session's main object (before_session gets output, binding, pry)
|
|
230
|
+
if defined?(Pry)
|
|
231
|
+
Pry.config.hooks.add_hook(:before_session, :console_buddy) do |_output, binding, _pry|
|
|
232
|
+
binding.receiver.extend(ConsoleBuddy::IRB)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
207
235
|
end
|
|
208
236
|
|
|
209
237
|
def load_progress_bar
|
|
@@ -247,4 +275,4 @@ require_relative "console_buddy/initializers/rails"
|
|
|
247
275
|
|
|
248
276
|
if rspec_present
|
|
249
277
|
require_relative "console_buddy/initializers/rspec"
|
|
250
|
-
end
|
|
278
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "sidekiq"
|
|
5
|
+
require_relative "../../../lib/console_buddy/jobs/sidekiq"
|
|
6
|
+
|
|
7
|
+
RSpec.describe ConsoleBuddy::Jobs::Sidekiq do
|
|
8
|
+
describe ".perform_async" do
|
|
9
|
+
after { ConsoleBuddy.one_off_job_sidekiq_queue = nil }
|
|
10
|
+
|
|
11
|
+
context "when ConsoleBuddy.one_off_job_sidekiq_queue is set" do
|
|
12
|
+
before { ConsoleBuddy.one_off_job_sidekiq_queue = :general_2m }
|
|
13
|
+
|
|
14
|
+
it "uses Sidekiq set(queue:) when available" do
|
|
15
|
+
setter = double("sidekiq_setter")
|
|
16
|
+
expect(described_class).to receive(:set).with(queue: :general_2m).and_return(setter)
|
|
17
|
+
expect(setter).to receive(:perform_async).with("a", 1)
|
|
18
|
+
described_class.perform_async("a", 1)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: console_buddy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Bowie
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-04-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -201,6 +201,7 @@ files:
|
|
|
201
201
|
- spec/console_buddy/http_request_spec.rb
|
|
202
202
|
- spec/console_buddy/irb_spec.rb
|
|
203
203
|
- spec/console_buddy/job_spec.rb
|
|
204
|
+
- spec/console_buddy/jobs/sidekiq_spec.rb
|
|
204
205
|
- spec/console_buddy/method_store_spec.rb
|
|
205
206
|
- spec/console_buddy/report_spec.rb
|
|
206
207
|
- spec/spec_helper.rb
|
|
@@ -208,8 +209,8 @@ homepage:
|
|
|
208
209
|
licenses: []
|
|
209
210
|
metadata:
|
|
210
211
|
bug_tracker_uri: https://github.com/GoodForNothingTech/console_buddy/issues
|
|
211
|
-
changelog_uri: https://github.com/GoodForNothingTech/console_buddy/CHANGELOG.md
|
|
212
|
-
documentation_uri: https://github.com/GoodForNothingTech/console_buddy
|
|
212
|
+
changelog_uri: https://github.com/GoodForNothingTech/console_buddy/blob/main/CHANGELOG.md
|
|
213
|
+
documentation_uri: https://github.com/GoodForNothingTech/console_buddy/blob/main/README.md
|
|
213
214
|
source_code_uri: https://github.com/GoodForNothingTech/console_buddy
|
|
214
215
|
post_install_message:
|
|
215
216
|
rdoc_options: []
|
|
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
226
227
|
- !ruby/object:Gem::Version
|
|
227
228
|
version: '0'
|
|
228
229
|
requirements: []
|
|
229
|
-
rubygems_version: 3.4.
|
|
230
|
+
rubygems_version: 3.4.19
|
|
230
231
|
signing_key:
|
|
231
232
|
specification_version: 4
|
|
232
233
|
summary: Have you ever had debugging tricks, aliases, or shortcuts that don't make
|