コード例 #1
0
ファイル: DataCountTask.java プロジェクト: coffeehb/jyy
 public void execute(JobExecutionContext context) throws JobExecutionException {
   String taskName = context.getTrigger().getKey().getName();
   logger.info(
       "任务[ " + taskName + " ]启动于 " + DateToString(context.getFireTime(), "yyyy-MM-dd HH:mm:ss"));
   try {
     doTask();
   } catch (Exception e) {
     throw new JobExecutionException(e);
   } finally {
     logger.info(
         "任务[ "
             + taskName
             + " ]下次将于"
             + DateToString(context.getNextFireTime(), "yyyy-MM-dd HH:mm:ss")
             + " 启动");
   }
 }
コード例 #2
0
ファイル: JdbcJobExecutions.java プロジェクト: olagache/glass
  @Override
  public void jobEnds(JobExecution execution, JobExecutionContext context) {
    String sql =
        "update "
            + getTableName()
            + " set endDate = :endDate, ended = :ended, result = :result where id = :id";

    SqlParameterSource params =
        new MapSqlParameterSource()
            .addValue(
                "endDate",
                new DateTime(context.getFireTime())
                    .plusMillis((int) context.getJobRunTime())
                    .toDate())
            .addValue("ended", true)
            .addValue("result", execution.getResult().name())
            .addValue("id", execution.getId());

    jdbcTemplate.update(sql, params);
  }
コード例 #3
0
  @Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    try {

      log.info(
          "Execute: Details : "
              + " at : "
              + new Date()
              + " : Previous Fire time : "
              + context.getPreviousFireTime()
              + " : Next Fire time : "
              + context.getNextFireTime()
              + " : Scheduled Fire time : "
              + context.getScheduledFireTime()
              + " : Fire Instance ID : "
              + context.getFireInstanceId()
              + " : Job Run Time : "
              + context.getJobRunTime()
              + " : Refire Count : "
              + context.getRefireCount()
              + " : Fire Time : "
              + context.getFireTime());

      String fileName = context.getTrigger().getKey().getName();
      File file = new File(fileName + ".txt");

      // if file doesnt exists, then create it
      if (!file.exists()) {
        file.createNewFile();
      }

      // true = append file
      FileWriter fileWritter = new FileWriter(file.getName(), true);
      BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
      bufferWritter.write(new Date().toString() + "\n");
      bufferWritter.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #4
0
ファイル: App.java プロジェクト: greatyan/TEST
 public void execute(JobExecutionContext context) throws JobExecutionException {
   System.out.println(context.getFireTime() + context.getFireInstanceId());
   System.out.println("Test Job executed");
 }
コード例 #5
0
ファイル: MonitorJob.java プロジェクト: josecerejo/flamingo
  public void execute(JobExecutionContext jec) throws JobExecutionException {

    try {
      Stripersist.requestInit();
      EntityManager em = Stripersist.getEntityManager();

      StringBuilder monitoringFailures = new StringBuilder();

      int online = 0, offline = 0;

      // TODO: where monitoringEnabled = true...
      for (GeoService gs : (List<GeoService>) em.createQuery("from GeoService").getResultList()) {

        String debugMsg =
            String.format(
                "%s service %s (#%d) with URL: %s",
                gs.getProtocol(), gs.getName(), gs.getId(), gs.getUrl());
        try {

          if (isInterrupted()) {
            log.info("Interrupted, ending monitoring job");
            return;
          }

          gs.checkOnline();
          online++;
          gs.setMonitoringStatusOK(true);
          log.debug("ONLINE: " + debugMsg);
        } catch (Exception e) {
          gs.setMonitoringStatusOK(false);
          offline++;
          log.debug("OFFLINE: " + debugMsg);
          if (log.isTraceEnabled()) {
            log.trace("Exception", e);
          }
          String message = e.toString();
          Throwable cause = e.getCause();
          while (cause != null) {
            message += "; " + cause.toString();
            cause = cause.getCause();
          }
          monitoringFailures.append(
              String.format(
                  "%s service %s (#%d)\nURL: %s\nFout: %s\n\n",
                  gs.getProtocol(), gs.getName(), gs.getId(), gs.getUrl(), message));
        }
      }

      em.getTransaction().commit();

      log.info(
          String.format(
              "Total services %d, online: %d, offline: %d, runtime: %d s",
              online + offline, online, offline, jec.getJobRunTime() / 1000));

      if (offline > 0) {

        Set emails = new HashSet();
        for (User admin :
            (List<User>)
                em.createQuery(
                        "select u from User u "
                            + "join u.groups g "
                            + "where g.name = '"
                            + Group.SERVICE_ADMIN
                            + "' ")
                    .getResultList()) {
          emails.add(admin.getDetails().get(User.DETAIL_EMAIL));
        }
        emails.remove(null);

        if (!emails.isEmpty()) {
          StringBuilder mail = new StringBuilder();

          SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyy HH:mm:ss");
          mail.append(
              String.format(
                  "Bij een controle op %s zijn in het gegevensregister %d services gevonden waarbij fouten zijn geconstateerd.\n"
                      + "\nDe volgende controle zal worden uitgevoerd op %s.\nHieronder staat de lijst met probleemservices:\n\n",
                  f.format(jec.getFireTime()), offline, f.format(jec.getNextFireTime())));
          mail.append(monitoringFailures);

          mail(jec, emails, offline + " services zijn offline bij controle", mail.toString());
        }
      }
    } catch (Exception e) {
      log.error("Error", e);
    } finally {
      Stripersist.requestComplete();
    }
  }