Hi all,

I have a query that is intended to delete outdated databases. This has been working but I recently found that if a database is locked the process stops with an error such as:

[db:lock] Database 'name' cannot be updated, it is opened by another process.

As a result, the process is stopped by any database being in a locked state. I would have thought that the try / catch around db:drop would catch the error and allow the process to skip over any locked databases. 

declare variable $age external := 'PT1M'; (: age 1 minute for testing :)

let $cutoff := current-dateTime() - xs:dayTimeDuration($age)
let $databases := db:list-details()[xs:dateTime(@modified-date) lt $cutoff]
return (
  admin:write-log('cleanup delete items older than ' || $cutoff),
  for $db in $databases return (
    admin:write-log('cleanup deleting database ' || $db),
    try {
      db:drop($db)
    } catch * {
      admin:write-log('cleanup error deleting ' || $db || ': ' || $err:description, 'ERROR')
    }
  )


I tried replacing catch * with catch db:open to catch the specific error, but that hasn't helped. 

Why is the error not caught, and is there a better way to write this query to avoid this problem?

Thanks,
Vincent

______________________________________________

Vincent M. Lizzi

Head of Information Standards | Taylor & Francis Group

E-Mail: vincent.lizzi@taylorandfrancis.com

Web: www.tandfonline.com

Time zone: US Eastern

 

Taylor & Francis is a trading name of Informa UK Limited,

registered in England under no. 1072954

 

"Everything should be made as simple as possible, but not simpler."