-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback to ActiveRecord::Base.connection #96
Comments
This is a good issue. I have been thinking about how we could pass connections to QC. Is there an easy way to get an instance of |
It seems that |
The following seems to work in my Rails app in
Am happy to send a pull request based on this, let me know. |
Realised that it's easier to just send a PR, rather than ask if I should send a PR :). Feel free to reject if it's the wrong approach. |
Not sure which approach works better here now having see @malclocke's version - however, knowing how hard it was to get the AR connection in the right way (in terms of figuring it out) I feel that falling back to a predicted connection location might be better. |
…ction Allow setting of QC::Conn.connection (closes #96)
I don't think this is the right approach. I have the same problem, but for me it doesn't work because if I assign the connection in an initializer it might already be teared down/not pointing to the current connecton, when you try to access it. I think a better approach would be to be able to specify a block that is yielded inside QC::Conn.connect to aquire the connection. For now I'm solving this problem by overriding module QC
module Conn
def connect
conn = ActiveRecord::Base.connection.raw_connection
if conn.status != PGconn::CONNECTION_OK
log(:level => :error, :message => conn.error)
end
conn
end
end
end |
@fbuenemann but with your approach, queue_classic must know about ActiveRecord. Can you not delay the handoff of the active_record connection to queue_classic until you are sure that you have the right connection? |
Well, my idea was to specify a block that is yielded inside QC, so the content of this block don't matter, as long a it yields a proper connection object. Setting the connection object at a later point instead of in a initializer would probably work as well. One thing I don't like about both cases, is that in case of an exception QC tears down the connection it didn't establish itself, which might be bad. For now I patched the disconnect method so it just resets |
@felixbuenemann I've just hit the problem you are describing above where we have a reconnect happening after fork in our production set-up. I think the idea of setting a connection proc is a good one, e.g. something like:
... and that proc will be used by Would be worth integrating this with #134 too I think. I don't see any other way around this with our current production setup (unicorn), other than using |
I think there's a lot of duplication around connection handling already. There's We would still need to tackle the disconnection problem though, because QC shouldn't be allowed to teardown a passed in connection. I'm not sure what's the best way to handle that. |
FWIW, I use sequel and activerecord and queue_classic in the same application. I would love to be able to share the same pg connection for everything. I'd gladly pay someone to make this work! :) |
This is the only thing missing for #134. I've had a lot of stuff to do lately but I hope to get it done in the upcoming days. |
Ah okay, good to know! Thanks |
I just ran into PG::Error: connection is closed in my integration tests. I fixed it with @felixbuenemann's patch. Establishing my own connection didn't seem to help (gave a different error), although setting |
@ericboehs using the AR connection is not supported yet. QC currently does not establish a new connection once it gets closed so you will eventually run into exactly the error you are describing. There are some internal changes happening and using the AR-connection by default in a Rails application is still on my todo list. I recommend setting |
Thanks for the recommendation. I wrapped my monkey patch with My app seems to be working in production as I'm using Heroku which sets DATABASE_URL by default. |
My workaround was to simply use the |
I saw that. Oddly it caused my integration tests to indefinitely stall. ¯_(ツ)_/¯ A team member suggested we just do ENV['DATABASE_URL'] ||= "postgresql://localhost/OUR_APP_NAME_#{Rails.env}" Which works fine since |
I have an instance where I cannot set the database_url env vars (TDDium insists on using sockets). Would it be feasible for QC to fallback to use the ActiveRecord::Base.connection if there is one if the db_url won't resolve?
The only issue I can see at the moment is that the execute method will need changing to suit the different APIs
The text was updated successfully, but these errors were encountered: