Skip to content

Commit f213213

Browse files
address comments
1 parent 5787303 commit f213213

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/closure_tree/has_closure_tree.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def has_closure_tree(options = {})
1212
:numeric_order,
1313
:touch,
1414
:with_advisory_lock,
15+
:advisory_lock_timeout_seconds,
1516
:order_belong_to
1617
)
1718

lib/closure_tree/support.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(model_class, options)
2323
:dependent => :nullify, # or :destroy or :delete_all -- see the README
2424
:name_column => 'name',
2525
:with_advisory_lock => true,
26+
:advisory_lock_timeout_seconds => nil,
2627
:numeric_order => false
2728
}.merge(options)
2829
raise ArgumentError, "name_column can't be 'path'" if options[:name_column] == 'path'
@@ -108,9 +109,10 @@ def where_eq(column_name, value)
108109
end
109110
end
110111

111-
def with_advisory_lock(&block)
112+
def with_advisory_lock!(&block)
112113
if options[:with_advisory_lock]
113-
model_class.with_advisory_lock!(advisory_lock_name, timeout_seconds: 5) do
114+
lock_options = { timeout_seconds: options[:advisory_lock_timeout_seconds] }.compact
115+
model_class.with_advisory_lock!(advisory_lock_name, lock_options) do
114116
transaction { yield }
115117
end
116118
else

0 commit comments

Comments
 (0)