AnsweredAssumed Answered

How to Schedule a Custom Action?

Question asked by drphoton on May 2, 2011
Latest reply on May 31, 2011 by drphoton
Hi,

I have a custom action defined which works well through the user interface. The action in question is the antivirus action found here http://wiki.alfresco.com/wiki/Antivirus.

I'm now trying to schedule this action to execute every week, but without any luck. The scheduler seems to run, but the action doesn't.

This is my scheduled-action-services-context.xml:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   
    <!–
    Define the model factory used to generate object models suitable for use with freemarker templates.
    –>
    <bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>
   
    <!–
    An action template that scans files for virus.   
    –>
    <bean id="antivirusScan" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>antivirus-action</value>
        </property>
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="dictionaryService">
            <ref bean="DictionaryService"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
    </bean>
   
    <!–
    Define a job for scanning the files for virus.
    –>
    <bean id="antivirusScanEveryWeek" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
        <property name="transactionMode">
            <value>ISOLATED_TRANSACTIONS</value>
        </property>
        <property name="compensatingActionMode">
            <value>IGNORE</value>
        </property>
        <property name="searchService">
            <ref bean="SearchService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
        <property name="queryLanguage">
            <value>lucene</value>
        </property>
        <property name="stores">
            <list>
                <value>workspace://SpacesStore</value>
            </list>
        </property>
        <!– Find all nodes under 'Company Home' –>
        <property name="queryTemplate">
            <value>+PATH:"/app:company_home/*//*" +EXACTTYPE:"cm:content"</value>
        </property>
        <!– Execute every Sunday at 8:00 –>
        <property name="cronExpression">
             <value>0 0 8 ? * SUN</value>
        </property>
        <property name="jobName">
            <value>jobA</value>
        </property>
        <property name="jobGroup">
            <value>jobGroup</value>
        </property>
        <property name="triggerName">
            <value>triggerA</value>
        </property>
        <property name="triggerGroup">
            <value>triggerGroup</value>
        </property>
        <property name="scheduler">
            <ref bean="schedulerFactory"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="templateActionDefinition">
            <ref bean="antivirusScan"/>
        </property>
        <property name="transactionService">
            <ref bean="TransactionService"/>
        </property>
        <property name="runAsUser">
            <value>admin</value>
        </property>
    </bean>
   
</beans>
and this is an extract of my log:

17:50:21,833 INFO  [org.springframework.extensions.webscripts.AbstractRuntimeContainer] Initialised Spring Surf Container Web Script Container (in 6492.7983ms)
17:50:21,911 INFO  [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor freemarker for extension ftl
17:50:22,051 INFO  [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor javascript for extension js
17:50:22,457 INFO  [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor freemarker for extension ftl
17:50:22,457 INFO  [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor javascript for extension js
17:50:22,862 INFO  [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor freemarker for extension ftl
17:50:22,862 INFO  [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor javascript for extension js
17:55:00,124 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
17:55:00,124 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction
18:00:00,047 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
18:00:00,047 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction
18:05:00,031 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
18:05:00,031 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction
18:10:00,048 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
18:10:00,048 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction
18:15:00,042 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
18:15:00,042 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction
18:20:00,060 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Found 56
18:20:00,060 DEBUG [org.alfresco.repo.action.scheduled.AbstractScheduledAction] Executing in individual transaction

As you can see the scheduler runs and finds 56 node on which to execute the action, but the action is not executed. Any ideas what may be going wrong?

Outcomes