Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. When running code in a thread ActiveRecord uses a separate database connection, which can't see the results of any queries run by the main thread until they're committed. But Rails doesn't commit transactions in the test environment, making this difficult to test.
  2.  
  3. The fix for this was in two parts, either of which should be enough to solve the problem on their own.
  4.  
  5. 1. Load the ActiveRecord objects before entering the thread, as the database connection that we'll be using inside the thread may not be able to access the (freshly created) database records yet.
  6.  
  7. 2. Commit the transaction that wraps the creation of the database records before publishing the `:message_created` message (that triggers the thread to run). This ought to mean that code with a separate database connection will be able to load the subscribers anyway.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement