Search in sources :

Example 1 with JobException

use of com.vip.saturn.job.exception.JobException in project Saturn by vipshop.

the class SaturnWorker method initTrigger.

private void initTrigger(Trigger trigger) {
    if (trigger == null) {
        return;
    }
    if (!(trigger instanceof OperableTrigger)) {
        throw new JobException("the trigger should be the instance of OperableTrigger");
    }
    this.triggerObj = (OperableTrigger) trigger;
    Date ft = this.triggerObj.computeFirstFireTime(null);
    if (ft == null) {
        LogUtils.warn(log, LogEvents.ExecutorEvent.COMMON, "Based on configured schedule, the given trigger {} will never fire.", trigger.getKey(), job.getJobName());
    }
}
Also used : JobException(com.vip.saturn.job.exception.JobException) OperableTrigger(org.quartz.spi.OperableTrigger) Date(java.util.Date)

Example 2 with JobException

use of com.vip.saturn.job.exception.JobException in project Saturn by vipshop.

the class JobNodeStorage method executeInLeader.

/**
 * 在主节点执行操作.
 *
 * @param latchNode 分布式锁使用的作业节点名称
 * @param callback 执行操作的回调
 */
public void executeInLeader(final String latchNode, final LeaderExecutionCallback callback) {
    try (LeaderLatch latch = new LeaderLatch(getClient(), JobNodePath.getNodeFullPath(jobConfiguration.getJobName(), latchNode))) {
        latch.start();
        latch.await();
        callback.execute();
    // CHECKSTYLE:OFF
    } catch (final Exception e) {
        LogUtils.error(log, jobName, e.getMessage(), e);
        // CHECKSTYLE:ON
        if (e instanceof InterruptedException) {
            // NOSONAR
            Thread.currentThread().interrupt();
        } else {
            throw new JobException(e);
        }
    }
}
Also used : JobException(com.vip.saturn.job.exception.JobException) LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) JobException(com.vip.saturn.job.exception.JobException)

Example 3 with JobException

use of com.vip.saturn.job.exception.JobException in project Saturn by vipshop.

the class AbstractElasticJob method init.

protected void init() {
    Class<? extends Trigger> triggerClass = configService.getJobType().getTriggerClass();
    Trigger trigger = null;
    try {
        trigger = triggerClass.newInstance();
        trigger.init(this);
    } catch (Exception e) {
        LogUtils.error(log, jobName, "Trigger init failed", e);
        throw new JobException(e);
    }
    scheduler = new SaturnScheduler(this, trigger);
    scheduler.start();
    getExecutorService();
}
Also used : JobException(com.vip.saturn.job.exception.JobException) SaturnScheduler(com.vip.saturn.job.trigger.SaturnScheduler) Trigger(com.vip.saturn.job.trigger.Trigger) JobException(com.vip.saturn.job.exception.JobException)

Example 4 with JobException

use of com.vip.saturn.job.exception.JobException in project Saturn by vipshop.

the class JobExecutionMultipleShardingContext method createJobExecutionSingleShardingContext.

/**
 * 根据分片项获取单分片作业运行时上下文.
 *
 * @param item 分片项
 * @return 单分片作业运行时上下文
 */
public JobExecutionSingleShardingContext createJobExecutionSingleShardingContext(final int item) {
    JobExecutionSingleShardingContext result = new JobExecutionSingleShardingContext();
    try {
        BeanUtils.copyProperties(result, this);
    } catch (final IllegalAccessException | InvocationTargetException ex) {
        throw new JobException(ex);
    }
    result.setShardingItem(item);
    result.setShardingItemParameter(shardingItemParameters.get(item));
    result.setOffset(offsets.get(item));
    return result;
}
Also used : JobException(com.vip.saturn.job.exception.JobException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with JobException

use of com.vip.saturn.job.exception.JobException in project Saturn by vipshop.

the class JobScheduler method createJob.

private void createJob() {
    try {
        job = JobTypeManager.get(currentConf.getJobType()).getHandlerClass().newInstance();
    } catch (Exception e) {
        LogUtils.error(log, jobName, "unexpected error", e);
        throw new JobException(e);
    }
    job.setJobScheduler(this);
    job.setConfigService(configService);
    job.setShardingService(shardingService);
    job.setExecutionContextService(executionContextService);
    job.setExecutionService(executionService);
    job.setFailoverService(failoverService);
    job.setServerService(serverService);
    job.setExecutorName(executorName);
    job.setReportService(reportService);
    job.setJobName(jobName);
    job.setNamespace(coordinatorRegistryCenter.getNamespace());
    job.setSaturnExecutorService(saturnExecutorService);
    job.init();
}
Also used : JobException(com.vip.saturn.job.exception.JobException) JobException(com.vip.saturn.job.exception.JobException)

Aggregations

JobException (com.vip.saturn.job.exception.JobException)5 SaturnScheduler (com.vip.saturn.job.trigger.SaturnScheduler)1 Trigger (com.vip.saturn.job.trigger.Trigger)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 LeaderLatch (org.apache.curator.framework.recipes.leader.LeaderLatch)1 OperableTrigger (org.quartz.spi.OperableTrigger)1