-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
41 lines (27 loc) · 1.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
after_commit
============
After_commit enables you to add after_commit methods to ActiveRecord models, which are called once the transaction has been committed to the database.
Typically one needs this in asynchronous processing where you pass on IDs of new records to another thread or post them to a message queue. Using the stock after_XXX
callbacks you cannot be sure that the other thread/process is already seeing the new record (at least if the database is ACID compliant).
Usage:
======
class Blog < ActiveRecord::Base
include AfterCommit::ActiveRecord
def after_commit_on_create
# do something
end
def after_commit_on_update
# do something
end
def after_commit_on_destroy
# do something
end
end
You have to include AfterCommit::ActiveRecord to add the new callbacks. They aren't automatically added to ActiveRecord::Base as tracking the committed
records takes a little overhead and I thought it's better to be able to manually select which models should get that feature.
You have to explicitely define the methods like in the example above, something like after_commit_on_create :do_what_ever doesn't work.
Credits:
========
I've taken existing code and made it threadsafe (well hopefully, so it should be safe when running config.threadsafe!). Original sources:
http://github.com/GUI/after_commit/tree/master
http://github.com/freelancing-god/thinking-sphinx