lib/ruote/exp/ro_persist.rb in ruote-2.2.0 vs lib/ruote/exp/ro_persist.rb in ruote-2.3.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2012, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -32,42 +32,50 @@
#--
# PERSISTENCE
#++
+ # Outputs ids like "0_2!d218c1b", no wfid, only <expid>!<subid>[0, 7]
+ #
+ def debug_id
+
+ "#{h.fei['expid']}!#{h.fei['subid'][0, 7]}"
+ end
+
# Persists and fetches the _rev identifier from the storage.
#
# Only used by the worker when creating the expression.
#
def initial_persist
r = @context.storage.put(@h, :update_rev => true)
#t = Thread.current.object_id.to_s[-3..-1]
- #puts "+ per #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
+ #puts "+ per #{debug_id} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
#Ruote.p_caller('+ per')
raise_or_return('initial_persist failed', r)
end
def try_persist
r = @context.storage.put(@h)
#t = Thread.current.object_id.to_s[-3..-1]
- #puts "+ per #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
+ #puts "+ per #{debug_id} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
+ #p self.h.children.collect { |i| Ruote.sid(i) }
#Ruote.p_caller('+ per')
r
end
def try_unpersist
r = @context.storage.delete(@h)
#t = Thread.current.object_id.to_s[-3..-1]
- #puts "- unp #{h.fei['expid']} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
+ #puts "- unp #{debug_id} #{tree[0]} r#{h._rev} t#{t} -> #{r.class}"
#Ruote.p_caller('- unp')
return r if r
#if h.has_error
@@ -91,15 +99,19 @@
end
alias persist persist_or_raise
alias unpersist unpersist_or_raise
+ # Make sure to persist (retry if necessary).
+ #
def do_persist
do_p(true)
end
+ # Make sure to unpersist (retry if necessary).
+ #
def do_unpersist
do_p(false)
end
@@ -129,12 +141,12 @@
r = pers ? try_persist : try_unpersist
raise_or_return(pers, r)
end
- # Does persist or unpersist, if successful then return true. If the
- # expression is gone, return false.
- # If there is a 'fresher' version of the expression, re-attempt and return
+ # Does persist or unpersist, if successful then returns true. If the
+ # expression is gone, returns false.
+ # If there is a 'fresher' version of the expression, re-attempt and returns
# false.
#
def do_p(pers)
case r = pers ? try_persist : try_unpersist