无法从CPF操作模块中创建MarkLogic计划的任务 [英] Unable to create MarkLogic scheduled tasks from within CPF action module

查看:61
本文介绍了无法从CPF操作模块中创建MarkLogic计划的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MarkLogic数据库,其中安装了内容处理框架(CPF)和CPF管道是这样的:

I have a MarkLogic database with Content Processing Framework (CPF) installed and the CPF pipeline is such that:

  1. 无论何时插入文档,它都会从文档中获取执行日期的值并安排该时间的任务.
  1. Whenever a document is inserted then it grabs the value of execution-date from the document and schedule a task for that time.

示例:

示例文档:

<sample>
  <execution-date>2014-10-20T12:29:10</execution-date>
</sample>

插入时触发CPF操作模块,该模块读取执行日期字段的值并创建计划的任务,该任务将在从 execution-date 字段读取的时间执行.

when inserted triggers the CPF action module which reads the value of execution-date field and creates a scheduled task to be executed on the time read from execution-date field.

以下是CPF操作模块中的XQuery代码段,该代码段创建了计划任务:

Following is the XQuery code snippet from the CPF action module that creates the scheduled task:

let $doc := fn:doc( $cpf:document-uri )
let $releasedon := xs:string($doc/sample/execution-date/text())

let $config := admin:get-configuration()
let $group := admin:group-get-id($config, "Default")

let $new-task :=
     admin:group-one-time-scheduled-task(
        "/tasks/task.xqy",
        "/",
        xs:dateTime($releasedon),
        xdmp:database("SampleDB"),
        xdmp:database("Modules"),
        xdmp:user("admin"), 
        (),
        "normal")

let $addTask := admin:group-add-scheduled-task($config,$group, $new-task)

return

    admin:save-configuration($addTask),
    xdmp:log(fn:concat("Task for document Uri: ", $cpf:document-uri, " created"))

现在,当我插入单个文档时,一切都会按预期工作,即:

Now, when I insert single document then everything works as expected, that is:

  1. 文档插入成功
  2. CPF操作模块已成功触发
  3. 计划任务已成功创建.

但是,当我尝试使用以下方法插入多个文档时:

But, when I try to insert multiple documents using:

xdmp:document-insert("/1.xml", 
    <sample>
      <execution-date>2014-10-21T10:00:00</execution-date>
    </sample>, 
    xdmp:default-permissions(),
    ("documents"))
,
xdmp:document-insert("/2.xml", 
    <sample>
      <execution-date>2014-10-20T11:00:00</execution-date>
    </sample>, 
    xdmp:default-permissions(),
    ("documents"))

CPF操作模块已成功触发(日志消息可以在日志中看到) 创建一个计划任务.

CPF action module gets triggered successfully (log message can be seen in logs) BUT ONLY one scheduled task gets created.

在MarkLogic管理界面中查看时,我只能找到一个计划在 2014-10-20T11:00:00

When looking in MarkLogic Admin Interface I can only find a single scheduled task which is scheduled to run at 2014-10-20T11:00:00

请让我知道我在做什么错或缺少任何配置. 欢迎任何建议.

Please let me know what am I doing wrong or is there any configuration I am missing. Any suggestions are welcomed.

谢谢!

推荐答案

此处的根本问题是管理员配置操作API 不是受事务保护的操作,因此当您同时并行运行两个时,查看配置文件的初始状态,然后写入其位以添加计划的任务,然后将其保存,只有其中一个获胜.您可以通过强制某些URI锁定来强制此行为以受事务保护的方式运行.它甚至不必在数据库中.只要这样做的所有操作都锁定在同一URI上,就可以了. xdmp:lock-for-update("my.example.uri")将执行此操作.

The fundamental issue here is that the admin configuration manipulation APIs are not transactionally protected operations, so when you run two in parallel each one sees the initial state of the configuration files, then writes their bit to add the scheduled task, and then saves it, and only one of them wins. You can force this to behave in a transactionally protected way by forcing a lock on some URI It doesn't matter what it is. It doesn't even have to be in the database. As long as everything that is doing this is locking on the same URI you are fine. xdmp:lock-for-update("my.example.uri") will do this.

这篇关于无法从CPF操作模块中创建MarkLogic计划的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆