Search in sources :

Example 31 with JobExecutionContext

use of org.quartz.JobExecutionContext in project candlepin by candlepin.

the class RegenEntitlementCertsJobTest method execute.

@Test
public void execute() throws Exception {
    // prep
    CandlepinPoolManager pm = mock(CandlepinPoolManager.class);
    JobExecutionContext jec = mock(JobExecutionContext.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    JobDetail detail = mock(JobDetail.class);
    JobDataMap jdm = mock(JobDataMap.class);
    String ownerId = "foo_owner";
    String prodId = "bar_prod";
    boolean lazyRegen = true;
    Owner owner = new Owner(ownerId);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Arrays.asList(owner));
    when(oc.listAll()).thenReturn(cqmock);
    when(jdm.getString(eq(RegenProductEntitlementCertsJob.PROD_ID))).thenReturn(prodId);
    when(jdm.getBoolean(eq(RegenProductEntitlementCertsJob.LAZY_REGEN))).thenReturn(lazyRegen);
    when(detail.getJobDataMap()).thenReturn(jdm);
    when(jec.getJobDetail()).thenReturn(detail);
    // test
    RegenProductEntitlementCertsJob recj = new RegenProductEntitlementCertsJob(pm, oc);
    injector.injectMembers(recj);
    recj.execute(jec);
    // verification
    verify(pm).regenerateCertificatesOf(eq(owner), eq(prodId), eq(lazyRegen));
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) JobExecutionContext(org.quartz.JobExecutionContext) CandlepinQuery(org.candlepin.model.CandlepinQuery) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 32 with JobExecutionContext

use of org.quartz.JobExecutionContext in project BRFS by zhangnianli.

the class DefaultBaseSchedulers method pauseAllTask.

@Override
public boolean pauseAllTask() {
    try {
        // 不在正常运行时,不进行任何操作
        if (!isNormal()) {
            return false;
        }
        Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
        if (!scheduler.isShutdown()) {
            // 1.停止触发器
            scheduler.pauseAll();
            JobKey currentJob;
            // 2.中断所有执行的任务
            for (JobExecutionContext jobExecut : scheduler.getCurrentlyExecutingJobs()) {
                currentJob = jobExecut.getJobDetail().getKey();
                scheduler.interrupt(currentJob);
            }
        }
        return true;
    } catch (UnableToInterruptJobException e) {
        LOG.error("{}", e);
    } catch (SchedulerException e) {
        LOG.error("{}", e);
    }
    return false;
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobExecutionContext(org.quartz.JobExecutionContext)

Example 33 with JobExecutionContext

use of org.quartz.JobExecutionContext in project searchcode-server by boyter.

the class EnqueueFileRepositoryJob method execute.

public void execute(JobExecutionContext context) {
    if (this.indexService.shouldPause(IIndexService.JobType.REPO_ADDER)) {
        return;
    }
    try {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
        UniqueRepoQueue repoQueue = Singleton.getUniqueFileRepoQueue();
        // Filter out those queued to be deleted and not file repositories
        List<RepoResult> repoResultList = this.helpers.filterRunningAndDeletedRepoJobs(Singleton.getRepo().getAllRepo()).stream().filter(x -> x.getScm().equals(Values.FILE)).collect(Collectors.toList());
        this.logger.info(String.format("4f37a297::adding %d file repositories to be indexed", repoResultList.size()));
        for (RepoResult rr : repoResultList) {
            if (Singleton.getEnqueueFileRepositoryJobFirstRun()) {
                rr.getData().jobRunTime = Instant.parse("1800-01-01T00:00:00.000Z");
                this.repo.saveRepo(rr);
                this.logger.info(String.format("40cd7595::resetting job run time due to firstRun %b repoName %s", Singleton.getEnqueueFileRepositoryJobFirstRun(), rr.getName()));
            }
            switch(rr.getScm().toLowerCase()) {
                case Values.FILE:
                    this.logger.info(String.format("18310da9::adding to file queue reponame %s", rr.getName()));
                    repoQueue.add(rr);
                    break;
                default:
                    break;
            }
        }
        Singleton.setEnqueueFileRepositoryJob(false);
    } catch (Exception ex) {
        this.logger.severe(String.format("056c9f75::error in class %s exception %s", ex.getClass(), ex.getMessage()));
        Singleton.setEnqueueFileRepositoryJob(false);
    }
}
Also used : Helpers(com.searchcode.app.util.Helpers) JobExecutionContext(org.quartz.JobExecutionContext) Singleton(com.searchcode.app.service.Singleton) RepoResult(com.searchcode.app.model.RepoResult) IIndexService(com.searchcode.app.service.index.IIndexService) IRepo(com.searchcode.app.dao.IRepo) Job(org.quartz.Job) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) Values(com.searchcode.app.config.Values) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) List(java.util.List) DisallowConcurrentExecution(org.quartz.DisallowConcurrentExecution) PersistJobDataAfterExecution(org.quartz.PersistJobDataAfterExecution) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 34 with JobExecutionContext

use of org.quartz.JobExecutionContext in project searchcode-server by boyter.

the class IndexDocumentsJobTest method testExecute.

public void testExecute() throws JobExecutionException {
    JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class);
    IndexService indexService = mock(IndexService.class);
    StatsService statsService = mock(StatsService.class);
    LoggerWrapper loggerWrapper = mock(LoggerWrapper.class);
// IndexDocumentsJob indexDocumentsJob = new IndexDocumentsJob(indexService, statsService, loggerWrapper);
// 
// indexDocumentsJob.execute(jobExecutionContext);
}
Also used : IndexService(com.searchcode.app.service.index.IndexService) StatsService(com.searchcode.app.service.StatsService) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) JobExecutionContext(org.quartz.JobExecutionContext)

Example 35 with JobExecutionContext

use of org.quartz.JobExecutionContext in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManagerUnitTest method testNotRunTaskWithExecuteDate.

@Test
public void testNotRunTaskWithExecuteDate() throws JobExecutionException {
    TestSchedulableTask mockTask = new TestSchedulableTask();
    JobExecutionContext context = new JobExecutionContext() {

        @Override
        public void setResult(Object result) {
        }

        @Override
        public void put(Object key, Object value) {
        }

        @Override
        public boolean isRecovering() {
            return false;
        }

        @Override
        public Trigger getTrigger() {
            return null;
        }

        @Override
        public Scheduler getScheduler() {
            return null;
        }

        @Override
        public Date getScheduledFireTime() {
            return null;
        }

        @Override
        public Object getResult() {
            return null;
        }

        @Override
        public int getRefireCount() {
            return 0;
        }

        @Override
        public TriggerKey getRecoveringTriggerKey() throws IllegalStateException {
            return null;
        }

        @Override
        public Date getPreviousFireTime() {
            return null;
        }

        @Override
        public Date getNextFireTime() {
            return null;
        }

        @Override
        public JobDataMap getMergedJobDataMap() {
            JobDataMap map = new JobDataMap();
            map.put(EntityEvent.EVENT_PROPERTY_EXECUTE_DATE, ZonedDateTime.now().plusHours(1).toString());
            // 
            return map;
        }

        @Override
        public long getJobRunTime() {
            return 0;
        }

        @Override
        public Job getJobInstance() {
            return null;
        }

        @Override
        public JobDetail getJobDetail() {
            return null;
        }

        @Override
        public Date getFireTime() {
            return null;
        }

        @Override
        public String getFireInstanceId() {
            return null;
        }

        @Override
        public Calendar getCalendar() {
            return null;
        }

        @Override
        public Object get(Object key) {
            return null;
        }
    };
    // mock task ends silently - execute time is in future
    // exception - failure
    mockTask.execute(context);
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

JobExecutionContext (org.quartz.JobExecutionContext)47 Test (org.junit.Test)20 JobDetail (org.quartz.JobDetail)20 JobDataMap (org.quartz.JobDataMap)13 Set (java.util.Set)10 JobExecutionException (org.quartz.JobExecutionException)10 List (java.util.List)8 SchedulerException (org.quartz.SchedulerException)8 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 Job (org.quartz.Job)6 ArrayList (java.util.ArrayList)5 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)5 Consumer (org.candlepin.model.Consumer)4 InterruptableJob (org.quartz.InterruptableJob)4 Scheduler (org.quartz.Scheduler)4 Date (java.util.Date)3 Map (java.util.Map)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2