示例#1
0
 public void init() {
   LOG.info("Configuring cpromo job scheduler");
   for (Map.Entry<String, PortalJob> entry : schedulerMap.entrySet()) {
     String cronExpression = dbSystemProperties.getProperty(entry.getKey() + "_SCHEDULE");
     if (cronExpression != null) {
       LOG.info(
           "scheduling the job {} to run according to the cron expression: {}",
           entry.getValue().getClass(),
           cronExpression);
       try {
         entry.getValue().init();
         taskScheduler.schedule(entry.getValue(), new CronTrigger(cronExpression));
       } catch (RuntimeException e) {
         jobExecutionLogger.errorInit(entry.getKey(), e.getLocalizedMessage());
         continue;
       }
       jobExecutionLogger.successInit(entry.getKey());
     } else {
       jobExecutionLogger.errorInit(
           entry.getKey(),
           "not found cron-expression entry in the system_property table for the job "
               + entry.getKey());
     }
   }
 }
  /**
   * Make sure we can kill the job init task on job finished event for the job.
   *
   * @throws GenieException on error
   */
  @Test
  public void canStopJobTask() throws GenieException {
    final String jobId = UUID.randomUUID().toString();
    final ScheduledFuture task = Mockito.mock(ScheduledFuture.class);
    final JobFinishedEvent jobFinishedEvent =
        new JobFinishedEvent(jobId, JobFinishedReason.FAILED_TO_INIT, "something", this);
    Mockito.when(task.isDone()).thenReturn(true).thenReturn(false).thenReturn(false);
    Mockito.when(task.cancel(true)).thenReturn(true).thenReturn(false);
    Mockito.when(scheduler.schedule(Mockito.any(), Mockito.any(Date.class))).thenReturn(task);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(0));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(0));
    coordinator.init(jobId);
    coordinator.schedule(jobId, null, null, null, null, 1024);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(1));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(1024));
    this.coordinator.onJobFinished(jobFinishedEvent);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(0));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(0));
    coordinator.init(jobId);
    coordinator.schedule(jobId, null, null, null, null, 1024);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(1));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(1024));
    this.coordinator.onJobFinished(jobFinishedEvent);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(0));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(0));
    coordinator.init(jobId);
    coordinator.schedule(jobId, null, null, null, null, 1024);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(1));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(1024));
    this.coordinator.onJobFinished(jobFinishedEvent);
    Assert.assertThat(this.coordinator.getNumActiveJobs(), Matchers.is(0));
    Assert.assertThat(this.coordinator.getUsedMemory(), Matchers.is(0));

    Mockito.verify(this.unableToCancel, Mockito.times(1)).increment();
  }
 protected void schedule(Task task, Pair<String, Trigger> triggerAndExpression) {
   if (triggerAndExpression == null) {
     throw new IllegalArgumentException("Must specify a Trigger and its expression");
   }
   LOGGER.info(
       "Scheduling task [{}] with trigger expression [{}]",
       task.id,
       triggerAndExpression.getFirst());
   task.execution = taskScheduler.schedule(task.runnable, triggerAndExpression.getSecond());
   task.executingTriggerExpression = triggerAndExpression.getFirst();
   task.executingTrigger = triggerAndExpression.getSecond();
 }
  private void scheduleRequestLogCleanupTask() {
    String cronExpression = settings.getRequestLogCleanupCronExpression();
    LOGGER.info("Scheduling request log cleanup task with cron '{}'", cronExpression);

    scheduler.schedule(
        new Runnable() {
          @Override
          public void run() {
            cleanupRequestLogTable();
          }
        },
        new CronTrigger(cronExpression));
  }
 @Override
 protected void doStart() {
   synchronized (this.monitor) {
     if (this.running.get()) {
       // already running
       return;
     }
     this.running.set(true);
     StreamReadingTask task = new StreamReadingTask();
     TaskScheduler scheduler = getTaskScheduler();
     if (scheduler != null) {
       scheduler.schedule(task, new Date());
     } else {
       Executor executor = Executors.newSingleThreadExecutor();
       executor.execute(task);
     }
   }
 }
  /** Starts session validation by creating a spring PeriodicTrigger. */
  public void enableSessionValidation() {

    enabled = true;

    if (log.isDebugEnabled()) {
      log.debug(
          "Scheduling session validation job using Spring Scheduler with "
              + "session validation interval of ["
              + sessionValidationInterval
              + "]ms...");
    }

    try {

      PeriodicTrigger trigger =
          new PeriodicTrigger(sessionValidationInterval, TimeUnit.MILLISECONDS);
      trigger.setInitialDelay(sessionValidationInterval);

      scheduler.schedule(
          new Runnable() {
            @Override
            public void run() {
              if (enabled) {
                sessionManager.validateSessions();
              }
            }
          },
          trigger);

      this.enabled = true;

      if (log.isDebugEnabled()) {
        log.debug("Session validation job successfully scheduled with Spring Scheduler.");
      }

    } catch (Exception e) {
      if (log.isErrorEnabled()) {
        log.error(
            "Error starting the Spring Scheduler session validation job.  Session validation may not occur.",
            e);
      }
    }
  }
示例#7
0
  public void rebuildFullWallInformations(final Wall wall) {
    taskScheduler.schedule(
        new Runnable() {
          @Override
          public void run() {
            // TODO prevent wall hiding (exception causing wall not added to wall list) if software
            // not found
            rebuildConnectionPluginsInSoftwareAccess(wall);
            for (SoftwareAccess softwareAccess : wall.getSoftwareAccesses()) {
              if (softwareAccess.getConnection() instanceof BuildCapability) {
                Runnable task = getDiscoverBuildProjectsRunner(wall, softwareAccess);
                task.run();
                // TODO skip first immediate schedule run as called by hand upper
                @SuppressWarnings("unchecked")
                ScheduledFuture<Object> futur =
                    taskScheduler.scheduleWithFixedDelay(
                        task, softwareAccess.getProjectFinderDelaySecond() * 1000);
                softwareAccess.setProjectFinderTask(futur);
              }
            }

            // here as task war run ones without schedule, projects exists, we need that for first
            // run
            // to add other software without waiting for the second project discover
            for (SoftwareAccess softwareAccess : wall.getSoftwareAccesses()) {
              if (!(softwareAccess.getConnection() instanceof BuildCapability)) {
                Runnable task = getDiscoverOtherProjectsRunner(wall, softwareAccess);
                task.run();
                // TODO skip first immediate schedule run as called by hand upper
                @SuppressWarnings("unchecked")
                ScheduledFuture<Object> futur =
                    taskScheduler.scheduleWithFixedDelay(
                        task, softwareAccess.getProjectFinderDelaySecond() * 1000);
                softwareAccess.setProjectFinderTask(futur);
              }
            }
          }
        },
        new Date());
  }