active-record-transactioner 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "active-record-transactioner"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -21,6 +21,7 @@ class ActiveRecordTransactioner
21
21
  @count = 0
22
22
  @lock = Monitor.new
23
23
  @lock_threads = Monitor.new
24
+ @lock_models = {}
24
25
 
25
26
  if block_given?
26
27
  begin
@@ -35,6 +36,8 @@ class ActiveRecordTransactioner
35
36
  def queue(model)
36
37
  @lock.synchronize do
37
38
  klass = model.class
39
+
40
+ @lock_models[klass] = Mutex.new if !@lock_models.key?(klass)
38
41
  @models[klass] = [] if !@models.key?(klass)
39
42
  @models[klass] << model
40
43
  @count += 1
@@ -53,19 +56,24 @@ class ActiveRecordTransactioner
53
56
  models = val
54
57
  @models[klass] = []
55
58
  @count -= models.length
59
+ thread = nil
56
60
 
57
- thread = Thread.new do
58
- begin
59
- klass.__send__(@args[:transaction_method]) do
60
- models.each do |model|
61
- model.__send__(@args[:call_method], *@args[:call_args])
61
+ @lock_models[klass].synchronize do
62
+ thread = Thread.new do
63
+ begin
64
+ @lock_models[klass].synchronize do
65
+ klass.__send__(@args[:transaction_method]) do
66
+ models.each do |model|
67
+ model.__send__(@args[:call_method], *@args[:call_args])
68
+ end
69
+ end
62
70
  end
71
+ rescue => e
72
+ puts e.inspect
73
+ puts e.backtrace
74
+ ensure
75
+ @threads.delete(Thread.current)
63
76
  end
64
- rescue => e
65
- puts e.inspect
66
- puts e.backtrace
67
- ensure
68
- @threads.delete(Thread.current)
69
77
  end
70
78
  end
71
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-record-transactioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: -2428606338728267940
115
+ hash: 1711089571951927244
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements: