@Override
 protected void runJob(BackupJob job) {
   try {
     conn.beginOrJoin();
     // we need a JPA-managed instance
     BackupJob job2 = dal.createBackupJobDao().findById(job.getId());
     log.info("Sending job to processing queue: " + job2.getId());
     String json = JsonSerializer.serialize(job2);
     mqChannel.basicPublish("", mqName, null, json.getBytes());
   } catch (IOException e) {
     // Should only happen if message queue is down
     log.fatal(e.getMessage() + " - message queue down?");
     throw new RuntimeException(e);
   } finally {
     conn.rollback();
   }
 }
Exemplo n.º 2
0
  public JobContainer(List<BackupJob> backupJobs, BackMeUpUser user) {
    this.backupJobs = new ArrayList<Job>();
    for (BackupJob j : backupJobs) {
      Date nextExecTime = j.getNextExecutionTime();
      Job job =
          new Job(
              j.getId(),
              j.getSourceProfiles(),
              j.getSinkProfile(),
              j.getStart().getTime(),
              j.getCreated().getTime(),
              j.getModified().getTime(),
              j.getJobTitle(),
              j.getDelay(),
              j.isOnHold());
      job.setLastFail(j.getLastFailed() != null ? j.getLastFailed().getTime() : null);
      job.setLastSuccessful(j.getLastSuccessful() != null ? j.getLastSuccessful().getTime() : null);
      job.setStatus(j.getStatus());
      job.setTimeExpression(j.getTimeExpression());
      JobProtocol protocol = j.lastProtocol();

      if (protocol != null) {
        job.setLastBackup(protocol.getExecutionTime().getTime());
      }

      if (nextExecTime != null && nextExecTime.getTime() > new Date().getTime()) {
        job.setNextBackup(nextExecTime.getTime());
      }

      this.backupJobs.add(job);
    }

    if (this.backupJobs.size() > 0) {
      Collections.sort(
          this.backupJobs,
          new Comparator<Job>() {
            @Override
            public int compare(Job a, Job b) {
              return (int) (a.startDate - b.startDate);
            }
          });

      Job lastJob = this.backupJobs.get(this.backupJobs.size() - 1);
      this.lastBackup = lastJob.startDate;
    }

    this.user = new UserContainer(user);
  }