cancel
Showing results for 
Search instead for 
Did you mean: 

Scheduled Job - Multi-Tenancy

rafaelscg
Champ on-the-rise
Champ on-the-rise
Hi Everyone,

Im tryng to execute custom Scheduled Jobs for all Tenants that i have. But unfortunately i cant do what i need, because only default tenant (user:admin) was affected. I dont know if i need to change System user on "runAsUser" property. My "scheduled-action-services-context.xml" is:

<blockcode>
<?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>

   <!–Execute the script /Company Home/Data Dictionary/Script/exampleScript.js –>
   <bean id="runScriptAction" 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>
               <!– Note that as of Alfresco 4.0, due to a Spring upgrade, the FreeMarker ${foo} entries must be escaped –>

               <value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:datavalidadescheduled.js"' )\}</value>
               

               <!– This value tag is for Alfresco 3.x, because the escape of FreeMarker entries will fail otherwise –>

               <!–<value>#{"${"}selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:exampleScript.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>

   <!– Script execution config –>
   <bean id="runScript" 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>
   <!–Cron script execution every 10 minutes–>
   <property name="cronExpression">
   <value>0 0/1 * * * ?</value>
   </property>
   <property name="jobName">
   <value>jobD</value>
   </property>
   <property name="jobGroup">
   <value>jobGroup</value>
   </property>
   <property name="triggerName">
   <value>triggerD</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="runScriptAction"/> <!– This is name of the action (bean) that gets run –>
   </property>
   <property name="transactionService">
   <ref bean="TransactionService"/>
   </property>
   <property name="runAsUser">
   <value>System</value>
   </property>
   </bean>

</beans>
</blockcode>

Please, if anyone can help me, i really appreciate, because this is fundamental action for out project.
3 REPLIES 3

rafaelscg
Champ on-the-rise
Champ on-the-rise
Found old post (2011) about this problem, but without any response:
http://forums.alfresco.com/forum/developer-discussions/repository-services/using-querybased-crons-mu...

mrogers
Star Contributor
Star Contributor
This is a long shot …  But you may be able to change the run as from system to system@tennant.

Failing that you may want one job to iterate through all tenants.   You can do that sort of thing with the java api,  not sure if there's a simple script.    

rafaelscg
Champ on-the-rise
Champ on-the-rise
Thanks mrogers for quickly response. I will try to do some Java Class to get all tenant and do what i need. I just have asked about this because i think maybe is any bug of my environment.