Marklogic CPF strategy

╄→гoц情女王★ 提交于 2019-12-11 17:22:31

问题


For an insert/update operation on a document in a collection, I have CPF turned on. I want to make sure in my CPF, if I modify another document, I donot want it to get added the CPF queue. How can I achieve this ?

For eg: say in my CPF queue I have followwing documents

d1,d2,d3,d4,d5

Say in my CPF task ford1, I had to update document d4. What CPF state do I need to set so that d4 will not be added to the end of CPF queue.. but d4 if already present in the queue, should continue with regular CPF process.

Can this be done ? if so what would be a good strategy to follow.


回答1:


CPF will always automatically trigger on d4 if it is updated and it is in the scope of the domain, but the framework includes code to make sure that it is only working on a document in one state at a time. So it picks up d4 and starts working on it, and then another d4 trigger fires, that trigger will end up doing nothing. I think the way to frame this is: once d4 is processed, how can I mark it so it doesn't get processed again? If it is in-process, you don't need to worry about it. If it is in completed process, you need to put it in a terminal state (i.e. a state that has no transition in any relevant pipeline).

If you try to update d4 in a way that it shouldn't be triggered, all that means is you set up a race condition on the work done on the first triggering of d4, and I would not recommend trying to do that. It is really hard to puzzle out all the race conditions.




回答2:


You can do some tricks with collections, if you're defining your CPF domains via those.

For example, let's say you have a bunch of documents in a collection called "blue" and you want to apply a CPF pipeline to those. But based on your requirements, it needs to be conditional. So instead of having a CPF domain with a collection of "blue", make it on "green" instead. Then use a pre-commit trigger for create/modify on the "blue" collection to add the document to "green" as well, thus triggering the CPF pipeline (which can also remove the document from "green"). But the pre-commit trigger can say - if the document is already in "red", then I won't add it to "green".

To use that, your CPF pipeline can then add d4 to "red", telling the pre-commit trigger not to also add d4 to "green". If d4 is already in green, that's fine - the CPF pipeline will still run, as you want.



来源:https://stackoverflow.com/questions/52543949/marklogic-cpf-strategy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!