Go to primary content
Oracle® Retail Job Orchestration and Scheduler Oracle® Retail Job Orchestration and Scheduler
Release 16.0.027
E94822-01
  Go To Table Of Contents
Contents

Previous
Previous
 
Next
Next
 

6 Use Cases

This chapter provides details about the following use cases.

Creating Job Admin Batch Jobs

The following steps outline the procedure for creating a batch job in Job Admin.

  1. Download JosJobAdmin16.0.0ForAll16.x.xApps_eng_ga.zip and unzip the file.

  2. Create job XML files using Java batch specification. See the following Job XMLsample.

  3. Copy job XML files to jos-job-home/setup-data/META-INF/batch-jobs folder.

  4. Copy jar file that contains code related to jobs in jos-job-home/lib folder.

  5. Run the deployer script in jos-job-home/bin folder.

Sample Job XML

Here is sample Job XML that runs the ls shell command.

Surrounding text describes smpjobxml.png.

Passing Job Parameters

Job parameters can be passed to a shell script from the job using the following syntax in the job.

Surrounding text describes passjobparam.png.

If the following parameters are entered in the Job Admin UI during the launching of the above job, the following command will be run by the job.

Job Parameters: param1=-a,param2=-l

Command executed: ls -a -l

Passing System Options

System options can be passed to a shell script from the job using the following syntax in the job.

Surrounding text describes passsysopt.png.

If the following system option is set in the Job Admin UI, the following command will be run by the job.

System Option: dir=/home/batch

Command executed in the working directory /home/batch.

Passing System Properties

Java system properties can be passed to a shell script from the job using the following syntax in the job.

Surrounding text describes passsysprp.png.

If the following system property is set in the JVM for Job Admin, the following command will be run by the job.

System Property: -DbatchDir=/home/batch

Command executed in the working directory /home/batch.

Chaining Multiple Jobs

For running multiple jobs that must run in sequence (single flow), create a DSL to chain the jobs.

Sample Process Flow

The following process flow runs two jobs, jobA and jobB in sequence.The activity AbcActivty starts jobA by calling a REST endpoint in Job Admin. The activity AbcStatusActivity calls a REST endpoint in Job Admin to check the status of the jobA. It waits until the job is complete or failed. This is a standard pattern for running a batch job. After jobA is complete, the process flow engine runs the jobB.

process {
name "AbcProcess"
var ([a:"b", c:"d", e: 5])
    
begin{
    action{
        println "$activityName Load variables"
        println "Access externalVariables=$externalVariables"
        return "okay"
    }
    on "okay" moveTo "AbcActivity"
}
    
activity{
    name "AbcActivity"
    action{        
startOrRestartJob(externalVariables["jobAdminUrl"],"JobA", externalVariables["jobAdminUrlUserAlias"])
        "okay"
    }
    on "okay" moveTo "AbcStatusActivity"
on "error" moveTo "ErrorActivity"
}
    
activity{
    name "AbcStatusActivity"
 action{
waitForJobCompletedOrFailed("AbcActivity",externalVariables["jobAdminUrl"] + "/resources/batch/jobs/JobA/" + processVariables["jobExecutionId"], externalVariables["jobAdminUrlUserAlias"])
        "okay"
    }
    on "okay" moveTo "DefActivity"
}
    
activity{
   name "DefActivity"
    Action{
startOrRestartJob(externalVariables["jobAdminBaseUrl"],"JobB", externalVariables["jobAdminUrlUserAlias"])
"okay"
    }
    on "okay" moveTo "DefStatusActivity"
}
    
activity{
    name "DefStatusActivity"
    action{
waitForJobCompletedOrFailed("DefActivity",externalVariables["jobAdminUrl"] + "/resources/batch/jobs/JobB/" + processVariables["jobExecutionId"], externalVariables["jobAdminUrlUserAlias"])
"okay"
    }
    on "okay" moveTo "end"
}
 activity{
    name "ErrorActivity"
    action{
        println "$activityName This is error activity"
        return "okay"
    }
    on "okay" moveTo "end"
}
    
end{
    action{
        println "Got to end"
        return "COMPLETED"
    }
}  
}

Creating Split Flows

The main flow must fork other flows. Use the POST method to start a process flow from another process flow.

Figure 6-1 Split Flows

Surrounding text describes Figure 6-1 .

Sample Split Flow

In this sample flow, the activity GhiProcessActivity posts a request to the process flow application to start a new process flow GhiProcess and the main flow continues with rest of the activities. The sub-flow runs independently of the main flow.

Main Flow

process {   
name "DefProcess"
        
begin{
    action{
    }
    on "okay" moveTo "GhiProcessActivity"
} 
 
activity{
    name "GhiProcessActivity"            
    action {
(POST[externalVariables.processFlowAdminBaseUrl + "/resources/batch/processes/operator/ProcessGhi"] ]^externalVariables.processFlowAdminBaseUrlUserAlias)
           "okay"
    }
    on "okay" moveTo "DefActivity"
}
 
activity{
    name "DefActivity"
    action{
"okay"
    
    on "okay" moveTo "end"
}
 
end{
    action{
        return "COMPLETED"
    }
}
}

Sub Flow

process {
name "GhiProcess"
        
begin{
    action{                      
    }
    on "okay" moveTo "GhiActivity"
}
 
activity{
    name "GhiActivity"
    
    action{
//do something here
    }
    on "okay" moveTo "end"
}    
    
end{
    action{
        return "COMPLETED"
    }
}  
}

Creating Split and Join Flows

Process flow Abc starts process flow Def and Xyz. Process flow Abc must wait until Def and Xyz process flows are complete. The activity AbcActivity waits until DefProcess and XyzProcess are complete. Use waitForProcessInstancesToReachStatus method to wait for other flows to complete.

Figure 6-2 Split and Join Flows

Surrounding text describes Figure 6-2 .

Sample Split and Join Flow

process {
name "AbcProcess"
        
begin{
    action{
"okay"
    }
    on "okay" moveTo "DefAndXyzActivity"
} 

activity{    
    name "DefAndXyzActivity"          
    action {
def defExecution = ((POST[externalVariables.processFlowAdminBaseUrl + "/resources/batch/processes/operator/ProcessDef"] ]^externalVariables.processFlowAdminBaseUrlUserAlias) as ProcessExecutionIdsVo.ProcessExecutionIdVo)
processVariables[’processDefExecution'] = defExecution.executionId
def xyzExecution = ((POST[externalVariables.processFlowAdminBaseUrl + "/resources/batch/processes/operator/ProcessXyz"] ]^externalVariables.processFlowAdminBaseUrlUserAlias) as ProcessExecutionIdsVo.ProcessExecutionIdVo)
processVariables[’processXyzExecution'] = xyzExecution.executionId
           "okay"
    }
    on "okay" moveTo "AbcActivity"
}
 
activity{
    name "AbcActivity"
    Action{
waitForProcessInstancesToReachStatus([processVariables[’processDefExecution'],       processVariables[’processXyzExecution']], PROCESS_COMPLETED, LOGICAL_AND)
"okay"
    }
    on "okay" moveTo "end"
}
    
end{
    action{
        println "Got to end"
        return "COMPLETED"
    }
}
}

DefProcess Flow

process{
name "DefProcess"
        
begin{
    action{

    }
        on "okay" moveTo "defActivity"
}
    
activity{
    name "defActivity"
    action{
//do something here
}
                              on "okay" moveTo "end"
}
    
end{
    action{
                                "COMPLETE”
    }
}
}

XyzProcess Flow

process{
name "XyzProcess"
        
begin{
    action{

    }
        on "okay" moveTo "xyzActivity"
}
    
activity{
    name "xyzActivity"
    action{
    //do something here 
}on "okay" moveTo "end"
}
    
end{
    action{
        "COMPLETE”
    }
}
}

Creating a Join Flow with Other Flows

Process flow Def and Process flow Xyz run independently. Process flow Abc has to wait until process Def and Xyz are complete. Use waitForProcessNamesToReachStatus to wait for other processes to complete.

Figure 6-3 Join Flows with Other Flows

Surrounding text describes Figure 6-3 .

Sample Join Flow

process {
name "AbcProcess"
    
begin{
    action{      
    }
    on "okay" moveTo "AbcActivity"
} 

activity{
    name "AbcActivity"
    action{
waitForProcessNamesToReachStatus([’DefProcess':2, ’XyzProcess':2], now().minusDays(1), PROCESS_COMPLETED, LOGICAL_AND, LAST_EXECUTION_STATUS)
"okay"
    }
    on "okay" moveTo "end"
}
    
end{
    action{
        return "COMPLETED"
    }
}
}

Sharing Data Between Process Flows

Process flow Abc must share data with process flow Def. Use persistGlobalUserData and findGlobalUserData APIs to share information.

Sample Flow that Shares Information with Other Flows

process {
name "AbcProcess"    
begin{
    action{              
    }
    on "okay" moveTo "AbcActivity"
} 
activity{
    name "AbcActivity"
    action{
// Persist date as String
persistGlobalUserData(”workDayStart”, now().minusDays(1).toString())
"okay"
    }
    on "okay" moveTo "end"
}
end{
    action{
        return "COMPLETED"
    }
}
}
 
process {
name "DefProcess"    
begin{
    action{
    }
    on "okay" moveTo "DefActivity"
} 
activity{
    name "DefActivity"
    action{
/fetch the date from db
def workDayStartString = findGlobalUserData("workDayStart")
LocalDateTime workDayStartDateObject = LocalDateTime.parse(workDayStartString)
log.debug "WorkDayStart Global data asString(${workDayStartString}) and asLocalDateTime(${workDayStartDateObject})    "
"okay"
    }
    on "okay" moveTo "end"
}
end{
    action{
        return "COMPLETED"
    }

}

Creating Schedules in Scheduler

Complete the following steps to create a schedule in Scheduler.

  1. Download JosScheduler16.0.027ForAll16.x.xApps_eng_ga.zip and unzip the file.

  2. Set up the schedule for the above created process through seed data or the UI. See the following seed data sample.

  3. Create DSL file for action. DSL is Groovy based and Groovy or Java code can be used in Action block. See the following DSL sample.

  4. Copy DSL file to jos-scheduler-home/setup-data/dsl folder.

  5. Run the deployer script from jos-scheduler-home/bin folder.

Using Sample Seed Data to Create a Schedule

Here are important fields in seed data that must be considered for the schedule being created.

  • schedule_type - SIMPLE. if advanced scheduling is required, it must be created using Scheduler UI.

  • schedule_start_datetime - Specify the date and time when to start the schedule, for example, '2016-11-22 10:20:00'

  • schedule _frequency - Valid values are: DAILY, HOURLY, WEEKLY, MONTHLY, WEEKDAY, WEEKEND, SATURDAY, SUNDAY, FIRSTDAYOFMONTH, LASTDAYOFMONTH, ONCE

  • schedule_action_type - ASYNC (asynchronous) or SYNC (synchronous)

  • schedule_action_definition - Name of the schedule action DSL file

INSERT INTO BDI_SCHEDULE_DEFINITION (schedule_id, schedule_name, schedule_group, schedule_description, 
schedule_status, schedule_start_datetime, schedule_type, schedule_frequency, schedule_notification, 
schedule_notification_email, schedule_action_type, schedule_action_definition) VALUES (1, 'Schedule1', 
'Schedules', 'Schedule created from seed data. This schedule calls process flow: AbcProcess.', 
'ACTIVE', TIMESTAMP '2016-11-22 00:00:00', 'SIMPLE', 'DAILY', 'ON_SUCCESS,ON_ERROR', 
'admin@example.com', 'ASYNC', 'Abc.sch')

Scheduling an Action DSL

Each schedule has a corresponding schedule action DSL. This will be the action that is executed when the schedule runs.

Sample Action DSL

The following schedule action starts AbcProcess flow by sending a POST request to Process Flow.

action {
(POST[externalVariables.processFlowAdminBaseUrl + "/resources/batch/processes/operator/AbcProcess"]^externalVariables.processFlowAdminBaseUrlUserAlias) as String