Job Scheduler¶
Meaning of Job Scheduler¶
Job scheduler is a functionality that automatically executes a process unit which is called as “job”; by defining the execution schedule in advance.It is used when a single task is to be periodically performed for multiple times orfor the overnight execution of the business process that requires significant amount of time to fetch bulk data.In order to implement such requirements, job scheduler of |common_base_product provides functionality thatauto-executes the business processes, monitors its execution status and manages the execution results at a defined timing which are organized byServerSide JavaScript and ServerSide JavaScript on server.
Specifications¶
Refer job scheduler specification document for the specifications of job scheduler.
Sample Program¶
Sample Contents¶
Interlink the parameter value which is set to the “message” key with a fixed string “Hello” and output it.
Program Source¶
package jp.co.intra_mart.example.job; import jp.co.intra_mart.foundation.context.Contexts; import jp.co.intra_mart.foundation.context.model.AccountContext; import jp.co.intra_mart.foundation.job_scheduler.Job; import jp.co.intra_mart.foundation.job_scheduler.JobResult; import jp.co.intra_mart.foundation.job_scheduler.JobSchedulerContext; import jp.co.intra_mart.foundation.job_scheduler.annotation.Parameter; import jp.co.intra_mart.foundation.job_scheduler.annotation.Parameters; import jp.co.intra_mart.foundation.job_scheduler.exception.JobExecuteException; public class HelloJob implements Job { public HelloJob() { } @Override @Parameters(@Parameter(key = "message", value = "world!")) public JobResult execute() throws JobExecuteException { try { // Account context final AccountContext accountContext = Contexts.get(AccountContext.class); System.out.println("Account context : " + accountContext.toString()); // Job scheduler context final JobSchedulerContext jobSchedulerContext = Contexts.get(JobSchedulerContext.class); System.out.println("Job scheduler context : " + jobSchedulerContext.toString()); // Acquire parameter final String message = jobSchedulerContext.getParameter("message"); if (null == message) { // Process result: Abnormal return JobResult.error("Message does not exist in parameter."); } else if (message.trim().isEmpty()) { // Process result: Warning return JobResult.waring("Void message."); } // Message display System.err.println("Hello. " + message); // Process result: Normal return JobResult.success("Job is executed successfully."); } catch (Exception e) { // Process result: Abnormal (Return the process result due to exception) throw new JobExecuteException("Unexpected error occurred.", e); } } }Job program of Java creates implementation class of jp.co.intra_mart.foundation.job_scheduler.Job.In this interface, execute method is defined to describe the execution process of job.Job developer writes a program to be executed in the job process by this execute method.
Note
Account context and job scheduler context can be acquired in job process.
Mention any business process by using these 2 contexts.
Account Context
The account information that shows items executed from the job scheduler is stored in account context.
Job Scheduler Context
Definition information of job, jobnet, trigger and the execution information like
execution date and time, etc. is stored in the job scheduler context.