Skip to content

Allow logger to be lazy and converted on first use - #14

Open
mhenrixon wants to merge 4 commits into
mainfrom
allow-logger-to-be-a-proc
Open

Allow logger to be lazy and converted on first use#14
mhenrixon wants to merge 4 commits into
mainfrom
allow-logger-to-be-a-proc

Conversation

@mhenrixon

Copy link
Copy Markdown
Collaborator

The problem otherwise is that there is a load order problem in unique jobs. At least this way I can assign the logger regardless of how files are loaded.

@mhenrixon mhenrixon added the WIP Work in Progress label Oct 13, 2019
@mhenrixon
mhenrixon requested a review from mberlanda October 13, 2019 20:54
@mhenrixon mhenrixon self-assigned this Oct 13, 2019
mberlanda
mberlanda previously approved these changes Oct 14, 2019

@mberlanda mberlanda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I trust you 😄
Would it be possible to add a test and/or an example of configuration with and without proc? This would make the change more documented

@mhenrixon

Copy link
Copy Markdown
Collaborator Author

If you have a look at the labels there is a wip label meaning this is work in progress. When I'm ready to have it reviewed I'll change that label to ready for review.

Usually, I change it when I've added tests and in some way or form verified that the code does what I expect it to do.

@mberlanda
mberlanda dismissed their stale review October 15, 2019 10:13

still wip

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Brpoplpush::RedisScript::Config to support lazy logger assignment (via a Proc) and to evaluate/convert that proc into a real Logger on first use, addressing load-order issues when configuring unique jobs.

Changes:

  • Replace the attr_reader :logger with a logger method that evaluates a stored Proc on first call.
  • Allow logger= to accept either a Logger instance or a Proc producing one.
  • Update validation/error messaging around logger assignment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +52
def logger
# Convert to a regular logger on first call
@logger = @logger.call if @logger.is_a?(Proc)
@logger
end
Comment on lines 59 to 61
# @raise [ArgumentError] when given argument isn't a Logger
#
# @return [Logger]
#
def logger=(obj)
raise ArgumentError, "#{obj} should be a Logger" unless obj.is_a?(Logger)
raise ArgumentError, "#{obj} should be a Logger or a proc" unless obj.is_a?(Logger) || obj.is_a?(Proc)
Comment on lines +48 to +50
def logger
# Convert to a regular logger on first call
@logger = @logger.call if @logger.is_a?(Proc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Work in Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants