Q:

Mule - How to arrange a flow which should only run once before a Quartz scheduled flow

I have a quartz scheduled flow which should only run once an initial flow has completed. The initial flow sets up data which must be present in a file for the quartz scheduled process to succeed. However, the quartz process starts and the initial process never starts. I only want the initial to run once so I don't want it to be run in the quartz flow.
     <!-- Needs to run only once -->
      <flow name="InitialJob">
       <component ....
     </flow>

    <!-- Depends on InitialJob -->
    <flow name="ScheduledProcess">
          <quartz:inbound-endpoint responseTimeout="10000" doc:name="Schd" 
            cronExpression="0 */5 * * * ?" jobName="doIt" 
            repeatInterval="0">
            <quartz:event-generator-job/>
         </quartz:inbound-endpoint>

         <!-- I don't want to put InitialJob  here, 
           I only want it to run once
              -->
        <flow-ref name="PerformJob"/>
   </flow>

Is there a way to achieve this? How can I arrange the flows to accomplish my goal? 

A:

You can create two flows, one which will be triggered periodically but disabled on start-up and one that will set-up your data and activate the periodic flow. Something like:
    <!-- Will run periodically once started -->
    <flow name="PeriodicJob" initialState="stopped">
        <quartz:inbound-endpoint jobName="PeriodicJob" cronExpression="* * * * * ?" repeatInterval="0" responseTimeout="10000" doc:name="Quartz">
            <quartz:event-generator-job/>
        </quartz:inbound-endpoint>
        <flow-ref name="PerformJob"/>
    </flow>

    <!-- Will run once on start-up and activate PeriodJob -->
    <flow name="InitialJobRunOnce">
        <quartz:inbound-endpoint jobName="InitialJobRunOnce" repeatInterval="0" repeatCount="0" startDelay="0" responseTimeout="10000" doc:name="Quartz">
            <quartz:event-generator-job/>
        </quartz:inbound-endpoint>
        <expression-component doc:name="Activate period job"><![CDATA[app.registry.PeriodicJob.start();]]></expression-component>
    </flow>

Your initial flow will run once on start-up, but this "run a flow once" approach have some limits. If your application restart, the initial flow will run again - though this can be somehow mitigated by adding some logic to your initial flow.

