Example #1
0
 public Map<String, String> getStandardJobParams(ScheduledJobs scheduledJobs) {
   Map<String, String> mapParams = new HashMap<String, String>();
   mapParams.put("JobId", scheduledJobs.getId().toString());
   mapParams.put("JobName", scheduledJobs.getJobName());
   mapParams.put("JobDescription", scheduledJobs.getJobName());
   return mapParams;
 }
Example #2
0
  public void jobWasExecuted(JobExecutionContext context, JobExecutionException arg1) {
    SchedulerMailUtil mailUtil = new SchedulerMailUtil();
    ALNTLogger.info(this.getClass().getName(), "jobWasExecuted()", "Begin");
    try {
      ISchedulerConfigService schedulerConfigService =
          (ISchedulerConfigService) ServiceLocator.findService("schedulerConfigService");
      Job job = context.getJobInstance();
      if (job instanceof IJobsWithResult) {
        IJobsWithResult jobWithResult = (IJobsWithResult) job;
        JobResultWriter writer = jobWithResult.getResultWriter();
        if (writer != null) {
          writer.getLogWriter().flush();
          writer.getLogWriter().close();
          writer.getResultWriter().flush();
          writer.getResultWriter().close();
        }
      }
      Object jobId = context.getJobDetail().getJobDataMap().get("JOB_ID");
      Object id = context.getJobDetail().getJobDataMap().get("JobStatus_ID");
      String jobPgmName = (String) context.getJobDetail().getJobDataMap().get("JOB_NAME");
      ScheduledJobs scheduledJobs =
          schedulerConfigService.loadScheduledJob(new Long(jobId.toString()));
      ALNTLogger.info(getName(), "Got NotificationDetail object from ScheduledJobs");

      // Getting notification object to send the notification email to user
      scheduledNotificationDetail = scheduledJobs.getScheduledNotificationDetail();

      JobStatus jobStatus =
          schedulerConfigService.loadJobStatus(new Long(jobId.toString()), new Long(id.toString()));
      if (CommonConstants.SCHEDULE_IMMEDIATE.equalsIgnoreCase(scheduledJobs.getInterval())) {
        scheduledJobs.setActiveStatus(false);
      } else if (CommonConstants.SCHEDULE_ONCE.equalsIgnoreCase(scheduledJobs.getInterval())) {
        scheduledJobs.setActiveStatus(false);
      } else if (scheduledJobs.getInterval().startsWith(CommonConstants.SCHEDULE_PERIODICALLY)) {
        if (null == context.getNextFireTime()) {
          scheduledJobs.setActiveStatus(false);
        }
      }

      if (CommonConstants.JOB_STATUS_CANCELING.equalsIgnoreCase(jobStatus.getJobStatus())) {
        scheduledJobs.setActiveStatus(false);
        jobStatus.setJobStatus(CommonConstants.JOB_STATUS_CANCELED);

      } else {
        jobStatus.setJobStatus(CommonConstants.JOB_STATUS_COMPLETED);
        if (arg1 != null) {
          jobStatus.setJobStatus(CommonConstants.JOB_STATUS_FAILED);
        } else if (context
            .getJobDetail()
            .getJobDataMap()
            .containsKey(CommonConstants.JOB_STATUS_SKIPPED)) {
          jobStatus.setJobStatus(CommonConstants.JOB_STATUS_SKIPPED);
          context.getJobDetail().getJobDataMap().remove(CommonConstants.JOB_STATUS_SKIPPED);
        }
        if (context.getJobDetail() != null
            && context.getJobDetail().getJobDataMap() != null
            && context
                .getJobDetail()
                .getJobDataMap()
                .containsKey(CommonConstants.NO_VALID_FEED_FILE_EXISTS)) {
          jobStatus.setJobStatus(
              CommonConstants.JOB_STATUS_FAILED + "- " + CommonConstants.NO_VALID_FEED_FILE_EXISTS);
          context.getJobDetail().getJobDataMap().remove(CommonConstants.NO_VALID_FEED_FILE_EXISTS);
        }
        // completionTime=context.getFireTime();

        JobStage jobStage =
            schedulerConfigService.loadJobStage(
                jobStatus.getOriginalFailedId() == null
                    ? jobStatus.getId()
                    : jobStatus.getOriginalFailedId());
        if (jobStage != null) {
          jobStatus.setLastKnowStage(jobStage.getJobStage());
        }
      }

      // Sending notification email to user with status of current job with defined parameters or
      // with standard parameters
      // If the notification has not been configured for current running job then
      // scheduledNotificationDetail object will be null
      // so we are checking for that the notification has been configured for this or not
      if (scheduledNotificationDetail != null) {
        if (job instanceof IJobWithExtendedMailSubstVar) {
          Map<String, String> mapParams =
              ((IJobWithExtendedMailSubstVar) job).getMailSubstVarValues();
          mapParams.putAll(this.getStandardJobParams(scheduledJobs));
          mailUtil.sendMail(scheduledNotificationDetail, jobStatus.getJobStatus(), mapParams);
        } else {
          mailUtil.sendMail(
              scheduledNotificationDetail,
              jobStatus.getJobStatus(),
              this.getStandardJobParams(scheduledJobs));
        }
      }

      jobStatus.setCompleteTime(new Date());
      jobStatus.setJobName(jobPgmName);

      schedulerConfigService.saveScheduledJobWithoutScheduleJob(scheduledJobs);
      schedulerConfigService.saveJobStatus(jobStatus);

      ALNTLogger.info(this.getClass().getName(), "jobWasExecuted()", "End");
    } catch (ALNTSystemException e) {
      ALNTLogger.error(this.getClass().getName(), "jobWasExecuted()", "Error ::" + e.getMessage());
    } catch (ALNTApplicationException e) {
      ALNTLogger.error(this.getClass().getName(), "jobWasExecuted()", ":Error ::" + e.getMessage());
    }
  }