public void updateJobRun(DateTime dt, CallableJob cj) throws BackendException { Connection conn = null; PreparedStatement stat = null; try { conn = newConnection(); stat = conn.prepareStatement( String.format("UPDATE %s SET dt = ?, callable_job = ?, name = ?, `code` = ?, status = ?, exception = ?," + " start = ?, finish = ? WHERE id = ?", jobRunTableName)); int i = 1; stat.setTimestamp(i++, new Timestamp(dt.getMillis())); stat.setString(i++, objToString(cj)); stat.setString(i++, cj.getPlannedJob().getJobSpec().getName()); stat.setString(i++, cj.getPlannedJob().getJobSpec().getCode()); stat.setInt(i++, cj.getStatus().get()); stat.setString(i++, cj.getExceptionMessage() != null ? cj.getExceptionMessage().get() : ""); stat.setTimestamp(i++, new Timestamp(cj.getStart().get())); stat.setTimestamp(i++, new Timestamp(cj.getFinish().get())); stat.setLong(i++, cj.getJobId()); int rows = stat.executeUpdate(); LOG.info(String.format("Rows updated: %d", rows)); } catch (SQLException | IOException ex) { throw new BackendException(ex); } finally { closeConnections(conn, stat); } }
stat.setString(i++, cj.getPlannedJob().getJobSpec().getName()); stat.setString(i++, cj.getPlannedJob().getJobSpec().getCode()); stat.setInt(i++, cj.getStatus().get()); stat.setString(i++, cj.getExceptionMessage() != null ? cj.getExceptionMessage().get() : ""); stat.setTimestamp(i++, new Timestamp(cj.getStart().get()));
assertEquals(1, consumer.getSuccesfulQueries(limit).size()); assertEquals(0, consumer.getFinishedJobs(limit).get(nextId).getStatus().get()); dao.execute( String.format("DROP TABLE IF EXISTS %s", tableName));
@Test public void testJobResubmitSuccessUpdateQuery() throws BackendException { JobSpec aJob = TestAgent.getTestJob("Robert Frank", dao); String tableName = "table_dne_yet"; aJob.setCode(String.format("select * from %s", tableName)); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableJob cj = new CallableQuery(pj, dao, reporting, "example.com", mailInfo, null, drivers.get(0), null, 1); consumer.submitJob(cj); TestAgent.waitForFail(consumer, 1); boolean isSuccess = cj.isSuccess(); assertEquals(false, isSuccess); Map<Long, CallableJob> expected = new HashMap<>(); expected.put(cj.getJobId(), cj); assertEquals(expected, consumer.getFailedQueries(limit)); Long nextId = cj.getJobId()+1; aJob = dao.getJob(aJob.getId()); aJob.setCode("show tables;"); dao.updateJob(aJob); TestAgent.runRunnable(consumer); doSleep(); assertEquals(0, dao.getRunningJobs().size()); assertEquals(2, consumer.getFinishedJobs(limit).size()); assertEquals(1, consumer.getSuccesfulQueries(limit).size()); assertEquals(0, consumer.getFinishedJobs(limit).get(nextId).getStatus().get()); } @Test