How to schedule an automation-chain

Hi :) I want to schedule an automation chain . I have created the operation which deletes the trash .Then i used the following extension to set up a scheduler to be executed every 1 minute but nothing happens.This is the extension:

  point="schedule">
<schedule id="trashDelete">
  <eventId>DeleteTrash</eventId>
  <cronExpression>0 1 0 * * ?</cronExpression>
</schedule>

0 votes

1 answers

2489 views

ANSWER



You need to setup an event handler that will catch the event you created (DeleteTrash) and call your automation chain (DeleteTrashOperation)

<extension target="org.nuxeo.ecm.core.operation.OperationServiceComponent" point="event-handlers">
<handler chainId="DeleteTrashOperation" postCommit="true">
  <event>DeleteTrash</event>
</handler>
...
0 votes



I dont understand this
10/20/2017

Now it recognises the Scheduler..It turned out that the problem was Cron Expression..But now i have another problem.It throws an exception saying :Cannot find any valid path in operation chain-no method found for operation "DeleteTrash" and for first input type "void". I dont get it..The automation chain is allright
10/20/2017

Can you show us your custom operation DeleteTrashOperation ?
10/20/2017

@Operation(id = DeleteTrash.ID, category = Constants.CAT_DOCUMENT, label = "DeleteTrash", description = "") public class DeleteTrash {

public static final String ID = &quot;DeleteTrash&quot;;
private static final Log log = LogFactory.getLog(DeleteTrash.class);

@Context
protected CoreSession session;

@OperationMethod(collector = DocumentModelCollector.class)
public DocumentModel run(DocumentModel input) {
    log.warn(&quot;#######################&quot;);
    DocumentModelList documentModelList = session
            .query(&quot;SELECT * FROM Document WHERE ecm:currentLifeCycleState=&apos;deleted&apos;&quot;);
    Iterator&lt;DocumentModel&gt; iterator = documentModelList.iterator();
    while (iterator.hasNext()) {
        DocumentModel document = iterator.next();
        log.warn(document.getTitle()+&quot; WAS REMOVED FROM TRASH&quot;);
        session.removeDocument(document.getRef());
    }
    session.save();
    return null;

}

}

10/20/2017

I test it with a user Action so the code is fine..i dont understand why it doesnt work with the scheduler
10/20/2017

Not sure if OP's problem was solved. If not, the reason why it wasn't working was because CoreSession is not injected when using Schedulers as mentioned in here: https://doc.nuxeo.com/nxdoc/scheduling-periodic-events/#automation

The solution is to use Login As operation as first operation

07/24/2019