cancel
Showing results for 
Search instead for 
Did you mean: 

How to Schedule a Custom Action?

drphoton
Champ in-the-making
Champ in-the-making
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?
7 REPLIES 7

mikemars
Champ in-the-making
Champ in-the-making
Hi,

I seem to remember when I set up a scheduled action that the action template bean definition had to include the 'parameterTemplates' property (even if your action doesn't take a parameter).

i.e:

<bean id="antivirusScan" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>antivirus-action</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>a-parameter</value>
                    </key>
                    <value>a-value</value>
                </entry>             
            </map>
        </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>
It may be worth just putting in a dummy parameter and giving it a go.

Hope that helps.

drphoton
Champ in-the-making
Champ in-the-making
Hi,

Thank you for the suggestion, but I have already tested that and unfortunately it doesn't work.  Smiley Sad

Have any other ideas?

mikemars
Champ in-the-making
Champ in-the-making
I was able to replicate your issue.

To do this I gave the "actionName" property an invalid value.

So i'd suggest checking your following property for a typo:

<property name="actionName">
  <value>antivirus-action</value>
</property>

and make sure that "antivirus-action" exactly matches the bean id you assigned to the action you trying to execute.

mikemars
Champ in-the-making
Champ in-the-making
I can see from the wiki that the bean is named "antivirus-action".

Your config file looks fine, from the log it appears that it's unable to find the action bean. I'm not sure why that should be I'm afraid.

Sorry I couldn't be more help.

drphoton
Champ in-the-making
Champ in-the-making
After doing some more tests, it looks like the only actions that can be scheduled are the built-in actions. Can anyone confirm this? Is this the intended behavior or is it a bug? Is there a workaround to this issue?

Any help will be appreciated.

mikemars
Champ in-the-making
Champ in-the-making
You can schedule custom actions, I am running one.

The only other thing I can think of is to confirm with you that when you added the 'parameterTemplates' tag; that you also added the code to your action to accept the parameter.

e.g in your scheduled-action-services-context.xml:

<bean id="antivirusScan" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>antivirus-action</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>a-parameter</value>
                    </key>
                    <value>a-value</value>
                </entry>            
            </map>
        </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>

And in your Action class (AntivirusActionExecuter.java):

@Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      paramList.add(new ParameterDefinitionImpl("a-parameter", DataTypeDefinition.TEXT, false, getParamDisplayLabel("a-parameter")));      
   }

The fact you are doing nothing with the parameter doesn't matter, but you will need to add this to AntivirusActionExecuter.java.

drphoton
Champ in-the-making
Champ in-the-making
Thank you mikemars!

I finally found some time to try with a dummy parameter and it worked  Smiley Very Happy