Skip to content

Conversation

@mnbbrown
Copy link
Contributor

@mnbbrown mnbbrown commented Sep 8, 2022

This follows the sidekiq pattern (i.e. Sidekiq.server? == true when running as a worker)
Useful for code to understand if it's running in the bundle exec que worker context or not.

Why?

We'd like to be able to determine within the rails code base (i.e. config/environment.rb onwards) if the code is running in the context of the the que CLI, or if it's running in the normal rails context. For example, we have some Rails initializers that should run under normal circumstances but not run when running in a Que worker:

# config/initializers/custom.rb

if !Que.server?
   # setup up some things
end

@ZimbiX
Copy link
Member

ZimbiX commented Sep 13, 2022

Hmm, I'm not sure I understand how this is useful - what are you planning to use it for?

@mnbbrown
Copy link
Contributor Author

Hmm, I'm not sure I understand how this is useful - what are you planning to use it for?

Yeah - the description is poor - apologies. I've updated it with a rationale.

@mnbbrown
Copy link
Contributor Author

Hmm, I'm not sure I understand how this is useful - what are you planning to use it for?

Hey @ZimbiX - just checking in if the description is more useful now?

Copy link
Member

@ZimbiX ZimbiX left a comment

Choose a reason for hiding this comment

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

Thanks for the extra info. That makes sense now.

If this is supported, I think it would be appropriate to document how to use Que that way - instantiating a locker inside another Ruby process, e.g. Rails / puma. I'll merge this, but not release just yet, I think; can you contribute quick docs for what you know in another PR? Then I can release that together.

end

def server?
defined?(Que::CommandLineInterface).nil?
Copy link
Member

Choose a reason for hiding this comment

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

I haven't seen defined? before - I've always used Kernel.const_defined?("MyClass"). Handy!

@ZimbiX ZimbiX merged commit 178c8f3 into que-rb:master Nov 7, 2022
@ZimbiX ZimbiX mentioned this pull request Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants