Sujith Babu
Sujith Babu

Reputation: 359

WSO2 task to run exactly once at startup

I need a task to be run exactly once at the wso2 startup. How do we ensure this. The following did not work in the scheduled task

    <trigger once="true"/>

Upvotes: 0

Views: 823

Answers (5)

Sujith Babu
Sujith Babu

Reputation: 359

Just for the record, the version that I was using was 4.8.1. I did not solve this issue, instead worked-around it and moved the feature that we had to do an exactly once. I moved that from the WSO2 startup to our web layer and thus saved ourselves the trouble of fighting with various WSO2 version upgrades in the future.

I know that this issue happened in early 2016 and it looks odd for me to answer it in March 2019. But this issue seems to be happening on the newer version of WSO2 as well and fellow architects have been referring/commenting to this post even in Jan 2019. Therefore, it would be appropriate for me to comment on what I finally did.

Upvotes: 0

Petteri Pertola
Petteri Pertola

Reputation: 281

There seems to be a bug that is still present in the latest ESB (Integrator v. 6.4.0).

The only way a trigger will launch on startup and/or deployment of CAR archive, is if you set the interval to any number higher than 1000. I set it to 1001 and it ran straight away both on deployment as well as on restart. Example config below:

<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="TSK_Logoff" xmlns="http://ws.apache.org/ns/synapse">
<trigger interval="1001" count="1" />
<property name="sequenceName" value="SEQ_Logoff" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="injectTo" value="sequence" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
    <logoff/>
</property>

Upvotes: 0

Dohnomis
Dohnomis

Reputation: 25

I also had the same problem (using ESB4.9). After trying lots of options I found a working config to be:

<trigger once="true" count="1" interval="1"/>

Upvotes: 0

Randika
Randika

Reputation: 31

I am using the ESB 4.8.1. For me both configurations are worked fine. Followings are the sample schedule tasks which I have tested in each case.

1.Configuration 1 -<trigger once="true"/>

<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse" name="MyTask" class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz">
<trigger once="true"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<name xmlns="">The message will be displayed once</name>
</property>
</task>

2.Configuration -<trigger count="1" interval="1"/>

<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse" name="MyTask" class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz">
<trigger count="1" interval="1"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<name xmlns="">The message will be displayed once</name>
</property>
</task>

However, in the ESB documentation recommended to use <trigger once="true"/> to execute tasks only once after the esb starts.

Upvotes: 1

Jean-Michel
Jean-Michel

Reputation: 5946

Try with

 <trigger count="1" interval="1"/>

Upvotes: 1

Related Questions