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().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()));
@Test(timeout=2000) public void testScriptReplace() { JobSpec aJob = getTestScript("Doug Lea", dao); String strFormat = "YYYYMMdd"; DateTimeFormatter format = QueryReplaceUtil.makeDateTimeFormat(strFormat); DateTime now = Utils.getCurrentTime(); String command = String.format("echo '${%s-1D} ${%s}' >&2; exit 1;", strFormat, strFormat); String error = String.format("%s %s", format.print(now.minusDays(1)), format.print(now)); aJob.setCode(command); dao.createJob(aJob); runRunnable(agentDriver); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals(false, actual.isSuccess()); assertEquals(true, actual.isFailed()); String expected = CallableScript.genErrorMessage(aJob, error+"\n"); assertEquals(expected, actual.getExceptionMessage().get()); }
@Test public void testScriptRun() { JobSpec aJob = getTestScript("Chenoweth", dao); aJob.setCode("echo 'hi'; echo 'bye';"); dao.createJob(aJob); runRunnable(agentDriver); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals("", actual.getExceptionMessage().get()); assertEquals(true, actual.isSuccess()); }
@Test(timeout=2000) public void testScriptRunFail() { JobSpec aJob = getTestScript("Chenoweth", dao); String error = "error"; aJob.setCode(String.format("echo '%s' >&2; exit 1;", error)); dao.createJob(aJob); runRunnable(agentDriver); runRunnable(consumer); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals(false, actual.isSuccess()); assertEquals(true, actual.isFailed()); String expected = CallableScript.genErrorMessage(aJob, error+"\n"); assertEquals(expected, actual.getExceptionMessage().get()); }