AnsweredAssumed Answered

Run scheduled action on only one Cluster member?

Question asked by jasonreid on Sep 23, 2010
Hi

I am currently running a scheduled action based on the sample. The job is working OK, but what i want to do is only the run the job on one cluster member, and if that cluster member is down, the other server will pick up the slack and run the jobe instead. Is this possible?

At the moment the job goes out to a shared network drive and ingests into the repository any documents it finds there. This works well enough, except as we have 2 servers in the cluster, they both try and run the cron scheduled script at the same time, and fight over the same files. I can think of some ways to get around this outside of Alfresco, but i have seen some stuff about setting the alfresco.cluster.name for the LDAP synch jobs and thought that might be something i could leverage somehow?

This is one of the jobs:

<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>
<bean id="runIngestionLowJob" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
        <property name="transactionMode">
            <value>UNTIL_FIRST_FAILURE</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>
        <property name="queryTemplate">
            <value>PATH:"/app:company_home"</value>
        </property>

        <property name="cronExpression">
            <value>0 0/30 * * * ?</value>
        </property>
        <property name="jobName">
            <value>runIngestionLow</value>
        </property>
        <property name="jobGroup">
            <value>runIngestionGroup</value>
        </property>
        <property name="triggerName">

            <value>runIngestionLowTrigger</value>
        </property>
        <property name="triggerGroup">

            <value>runIngestionTriggerGroup</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="runIngestionLow"/>
        </property>
        <property name="transactionService">
            <ref bean="TransactionService"/>
        </property>
        <property name="runAsUser">
            <value>System</value>
        </property>
    </bean>

<!–
    Execute the script /Company Home/Data Dictionary/Scripts/Utilities/Ingestion/generic_ingestion_cron_low.js
  –>
    <bean id="runIngestionLow" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>script</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>script-ref</value>
                    </key>
                    <value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:Utilities/cm:Ingestion/cm:generic_ingestion_cron_low.js"' )}</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>

Outcomes