The timestamp is in epoch time, so you just have to do a little epoch math to
figure out how many seconds are left.
Here is an example that does that (thanks for the inspiration Mike).
xquery version "1.0-ml";
(:
The time is in epoch time, which is seconds from the start
of 1970, so this code does a little math on the values in
the lock document to figure out how many seconds are left
for the lock. Assumes a lock on /example.xml, for example
by running the following:
xquery version "1.0-ml";
declare namespace DAV="DAV:";
xdmp:lock-acquire("/example.xml",
"exclusive",
"0",
<DAV:href>http://example.com/~user</DAV:href>,
xs:unsignedLong(120))
:)
let $lock := xdmp:document-locks("/example.xml")
let $lock-duration :=
$lock/lock:lock/lock:active-locks/lock:active-lock/
lock:timeout/fn:data(.)
let $current-epoch-time :=
fn:round(
( fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00") )
div xs:dayTimeDuration('PT1S') )
let $start-time :=
$lock/lock:lock/lock:active-locks/lock:active-lock/
lock:timestamp/fn:data(.)
let $end-time := $start-time + $lock-duration
let $seconds-left := $end-time - $current-epoch-time
return
($current-epoch-time, $start-time, $seconds-left)
=>
1290137798
1290137794
116
So when I ran this, there were about 116 seconds left on the lock.
Hope that helps.
-Danny
From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Thursday, November 18, 2010 3:30 PM
To: [email protected]
Subject: [MarkLogic Dev General] How to get time remaining on document locks
>From the documentation, xdmp:document-locks function returns data that looks
>like this:
xdmp:document-locks("example.xml")
=> <lock:lock>
<lock:active-locks>
<lock:active-lock>
<lock:lock-type>write</lock:lockt-ype>
<lock:lock-scope>exclusive</lock:lock-scope>
<lock:depth>infinity</lock:depth>
<lock:owner>
http://example.com/~user
</lock:owner>
<lock:timeout>5000</lock:timeout>
<lock:lock-token>
http://marklogic.com/xdmp/locks/e71d4fae
</lock:lock-token>
<lock:timestamp>5234768</lock:timestamp>
<sec:user-id>52378234768</sec:user-id>
</lock:active-lock>
</lock:active-locks>
</lock:lock>
What I want to figure out is how much time is left for the lock. I see the
timeout duration, but I can't figure out how to use the timeout and the
timestamp to give me a time of when the lock will actually expire. That
timestamp doesn't look like a "time" stamp but rather a "query execution"
stamp. Is there some function that I can pass the "timestamp" to an get the
actual time that timestamp occurred?
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general