Module: Atig::Db::Transaction

Includes:
Util
Included in:
Followings, Lists, Statuses
Defined in:
lib/atig/db/transaction.rb

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Instance Method Details

#debug(s) ⇒ Object



40
41
42
43
44
# File 'lib/atig/db/transaction.rb', line 40

def debug(s)
  if respond_to? :log
    log :debug, s
  end
end

#initObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/atig/db/transaction.rb', line 10

def init
  return if @queue

  debug "transaction thread start"
  @queue = SizedQueue.new 10
  daemon do
    f,src = @queue.pop
    debug "transaction is poped at #{src}"

    if respond_to?(:timeout_interval) && timeout_interval > 0 then
      begin
        timeout(timeout_interval){ f.call self }
      rescue TimeoutError
        debug "transaction is timeout at #{src}"
      end
    else
      f.call self
    end

    debug "transaction is finished at #{src}"
  end
end

#transaction(&f) ⇒ Object



33
34
35
36
37
38
# File 'lib/atig/db/transaction.rb', line 33

def transaction(&f)
  init

  debug "transaction is registered"
  @queue.push [ f, caller.first ]
end