Allow library users to check if Que is running via CLI or lib#382
Allow library users to check if Que is running via CLI or lib#382ZimbiX merged 1 commit intoque-rb:masterfrom
Conversation
|
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. |
Hey @ZimbiX - just checking in if the description is more useful now? |
ZimbiX
left a comment
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
I haven't seen defined? before - I've always used Kernel.const_defined?("MyClass"). Handy!
This follows the sidekiq pattern (i.e.
Sidekiq.server? == truewhen running as a worker)Useful for code to understand if it's running in the
bundle exec queworker context or not.Why?
We'd like to be able to determine within the rails code base (i.e.
config/environment.rbonwards) if the code is running in the context of the thequeCLI, 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: