Hi Geert, 

Yes, I wrote an action that deletes the document, but when my action is 
complete, the framework tries to apply a new state to that document, which 
breaks because the document has already been deleted in the same transaction!

BUT that got me thinking... so I looked at the CPF code... :)

/cpf/cpf.xqy::cpf:success() is responsible for updating the cpf:state property 
of the document, with the new state coming either from the pipeline's 
state-transition/on-success configuration, or from the 3rd parameter of the 
cpf:success() call. It turns out that if the state to be set is unchanged from 
the previous state, in order to avoid re-processing the document, it simply 
skips updating the property at all.

So, instead of setting the final state to http://marklogic.com/states/done, as 
I did previously, my pipeline config now looks like this:

<pipeline xmlns="http://marklogic.com/cpf/pipelines";>
   [...]
    <state-transition>
        <state>http://marklogic.com/states/initial</state>
        <on-success>http://pressassociation.com/states/sent</on-success>
        <on-failure>http://marklogic.com/states/error</on-failure>
        <execute>
            <action>
                <module>send.xqy</module>
            </action>
        </execute>
    </state-transition>
    <state-transition>
        <state>http://pressassociation.com/states/sent</state>
        <on-success>http://pressassociation.com/states/sent</on-success>
        <on-failure>http://marklogic.com/states/error</on-failure>
        <execute>
            <action>
                <module>delete.xqy</module>
            </action>
        </execute>
    </state-transition>
</pipeline>

i.e. after a successful send.xqy, the state of the document transitions to 
http://pressassociation.com/states/sent, this triggers the next 
state-transition, which performs the delete.xqy action 
(xdmp:document-delete($cpf:document-uri)), and then transitions to THE SAME 
STATE AGAIN. Therefore, the framework skips updating the cpf:state property, 
the XDMP-CONFLICTINGUPDATES disappears, and so, finally, does my document!

(I get a somewhat reassuring
Info: TaskServer: state is already successor so not updating for <URI>
in the log)

Probably too clever by half, but saves me having to add yet another cleanup 
task.

Ellis.


On 26 Apr 2013, at 14:05, Geert Josten <[email protected]> wrote:

> Not entirely sure, but why not just make a custom action that deletes the doc?
>  
> Kind regards,
> Geert
>  
> Van: [email protected] 
> [mailto:[email protected]] Namens Ellis Pritchard
> Verzonden: vrijdag 26 april 2013 13:46
> Aan: MarkLogic Developer Discussion
> Onderwerp: Re: [MarkLogic Dev General] CPF: deleting document at end of 
> pipeline?
>  
> Apparently not! :)
>  
> Fine, I'm already putting it in a special 'sent' state, so will follow your 
> suggestion.
>  
> Cheers!
>  
> Ellis.
>  
>  
> On 26 Apr 2013, at 12:37, Clark Richey <[email protected]> wrote:
> 
> 
> This is not a common use case. 
>  
> One easy answer is to put the document into a custom state at the end, like 
> ready-to-delete. Then write a simple xquery module that finds and deletes all 
> documents with that state. Have it run periodically as a scheduled task by 
> the MarkLogic task server. 
> 
> Clark D. Richey, Jr.
> Technical Director
> MarkLogic Corporation
> [email protected]
> Cell:  +1 240 252 7507
> www.marklogic.com
>  
> Sent from my iPhone
> 
> On Apr 26, 2013, at 5:38, "Ellis Pritchard" <[email protected]> wrote:
> 
> Hi,
> 
> I can't find how to automatically delete a document once it's been through a 
> pipeline, and was wondering if there's some kind of pre-configured state or 
> something for this?
> 
> My pipeline wants to do this:
> 
> insert doc -> forward doc via HTTP -> delete doc
> 
> My first thought was to add a pipeline stage which just does an 
> xdmp:document-delete($cpf:document-uri) but then you get 
> XDMP-CONFLICTINGUPDATES as CPF tries to also update the cpf:state property of 
> the deleted document in the same transaction, and the pipeline end up in 
> error, and the delete is rolled back.
> 
> I could xdmp:spawn() to do the job, but I'd have thought that this was a 
> common use-case, so am I missing something?
> 
> Ellis.
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>  
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to