Ankit Bhardwaj
Ankit Bhardwaj

Reputation: 774

cts:element-value-match does not works from scheduled tasks

I have written this code in the scheduled task XQuery -

xquery version "1.0-ml"; 
declare namespace grp = "http://marklogic.com/xdmp/group";
declare namespace c = 'http://iddn.icis.com/ns/core';
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare variable $task-file-path := "/var/tmp/Projects/update-malformed-ids-task.xqy";
declare variable $string-starting-with-new-line-pattern := "
*";
declare variable $string-starting-with-space-pattern := " *";
declare variable $LIVE-ASSET-COLLECTION := "live-collection";
declare variable $batch-size := 100;

declare function local:is-migration-needed()
{
  (
    fn:exists(cts:element-value-match(xs:QName("c:id"), $string-starting-with-space-pattern, (), cts:collection-query($LIVE-ASSET-COLLECTION))) or
      fn:exists(cts:element-value-match(xs:QName("c:id"), $string-starting-with-new-line-pattern, (), cts:collection-query($LIVE-ASSET-COLLECTION)))
  )
};
declare function local:migrate()
{
  if(local:is-migration-needed())
  then (: do task here :)
  else ()
}

local:migrate()

But this code is not working in scheduled task. The error which is logged in error logs says XDMP-ARG: cts:element-value-match(xs:QName("c:id"), " *", (), cts:collection-query("live-collection")) -- arg2 is invalid

I tried the same query on QConsole. It is working fine. I also tried using xdmp:spawn on the same file which also worked fine.

I also tried firing the simple cts:element-value-match without any pattern or wildcards. Looks like cts:element-value-match is not supported in scheduled tasks.

Is there something else need to be done to run this code from a scheduled task?

Upvotes: 0

Views: 155

Answers (1)

Ankit Bhardwaj
Ankit Bhardwaj

Reputation: 774

It seems like cts:element-value-match doesn't work in the scheduled tasks of MarkLogic. I did the desired task using cts:element-word-query instead.

Now the updated code in the task file, which worked for me, looks like -

xquery version "1.0-ml"; 
declare namespace grp = "http://marklogic.com/xdmp/group";
declare namespace c = 'http://iddn.icis.com/ns/core';
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare variable $task-file-path := "/var/tmp/Projects/update-malformed-ids-task.xqy";
declare variable $string-pattern-for-new-line-and-space as xs:string* := (" *","
*");
declare variable $LIVE-ASSET-COLLECTION := "live-collection";

declare function local:is-migration-needed()
{
    fn:count(cts:search(
      fn:collection($LIVE-ASSET-COLLECTION), 
      cts:element-word-query(
        xs:QName("c:id"), 
        $string-pattern-for-new-line-and-space, 
        ("whitespace-sensitive", "wildcarded")
      )
    ))>0
};

declare function local:migrate()
{
  if(local:is-migration-needed())
  then (: do task here :)
  else ()
}

local:migrate()

Upvotes: 0

Related Questions