Search in sources :

Example 1 with JobConfigurationException

use of com.dangdang.ddframe.job.exception.JobConfigurationException in project elastic-job by dangdangdotcom.

the class JobScheduler method createJobDetail.

private JobDetail createJobDetail(final String jobClass) {
    JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(jobName).build();
    result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
    Optional<ElasticJob> elasticJobInstance = createElasticJobInstance();
    if (elasticJobInstance.isPresent()) {
        result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJobInstance.get());
    } else if (!jobClass.equals(ScriptJob.class.getCanonicalName())) {
        try {
            result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, Class.forName(jobClass).newInstance());
        } catch (final ReflectiveOperationException ex) {
            throw new JobConfigurationException("Elastic-Job: Job class '%s' can not initialize.", jobClass);
        }
    }
    return result;
}
Also used : JobDetail(org.quartz.JobDetail) ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) JobConfigurationException(com.dangdang.ddframe.job.exception.JobConfigurationException)

Example 2 with JobConfigurationException

use of com.dangdang.ddframe.job.exception.JobConfigurationException in project elastic-job by dangdangdotcom.

the class ScriptJobExecutor method executeScript.

private void executeScript(final ShardingContext shardingContext, final String scriptCommandLine) {
    CommandLine commandLine = CommandLine.parse(scriptCommandLine);
    commandLine.addArgument(GsonFactory.getGson().toJson(shardingContext), false);
    try {
        new DefaultExecutor().execute(commandLine);
    } catch (final IOException ex) {
        throw new JobConfigurationException("Execute script failure.", ex);
    }
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) JobConfigurationException(com.dangdang.ddframe.job.exception.JobConfigurationException) IOException(java.io.IOException)

Aggregations

JobConfigurationException (com.dangdang.ddframe.job.exception.JobConfigurationException)2 ElasticJob (com.dangdang.ddframe.job.api.ElasticJob)1 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 IOException (java.io.IOException)1 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 JobDetail (org.quartz.JobDetail)1