@Test public void testBuildParameter_正常() { jobData.getData().put(JobData.JOBDATA_DATA_PARAMETER, "a%3D1%26b%3D2"); HttpJobUtils.buildParameter(jobData.getData()); Assert.assertEquals("1", jobData.getData().get("a")); Assert.assertEquals("2", jobData.getData().get("b")); }
@Before public void setUp() { jobData = new JobData(); jobData.setJobId(JOBID); jobData.setJobGroup(JOBGROUP); jobData.setJobName(JOBNAME); jobData.setJobType(JobData.JOBTYPE_HTTPJOB); Long signTime = (System.currentTimeMillis() / 1000); jobData.setSignTime(signTime.toString()); jobData.setToken(TokenUtils.generateToken(signTime.toString())); }
/** * 同步执行一个任务 * * @param jobData * @param executor * @return */ private JobResult executeJob(JobData jobData, JobExecutor executor) throws Exception { JobResult result = null; int clientRetries = HttpJobUtils.getJobClientRetries(jobData.getData().get(JobData.JOBDATA_DATA_CLIENTRETRIES)); for (int i = 1; i <= clientRetries + 1; i++) { result = executor.execute(jobData); if (result.isSuccess()) { if (i > 1) { result.getData().put(JobResult.JOBRESULT_DATA_CLIENTRETRYCOUNT, String.valueOf(i)); } break; } try { Thread.sleep(5000); } catch (InterruptedException e1) { } if (i > 1 && i == clientRetries + 1) { result.getData().put(JobResult.JOBRESULT_DATA_CLIENTRETRYCOUNT, String.valueOf(i)); } } return result; }
/** * 执行一个http任务 * * @param request * @param executor * @return */ public JobResult execute(JobData jobData, JobExecutor executor) { JobResult result = HttpJobUtils.checkJobData(jobData); if (!result.isSuccess()) { return result; } try { logger.info( "start|jobId:" + jobData.getJobId() + "|jobGroup:" + jobData.getJobGroup() + "|jobName:" + jobData.getJobName()); if (jobData.isSync()) { result = executeJob(jobData, executor); } else { result = executeAsyncJob(jobData, executor); } if (result.isSuccess()) { logger.info( "end|jobId:" + jobData.getJobId() + "|jobGroup:" + jobData.getJobGroup() + "|jobName:" + jobData.getJobName() + "|success:" + result.isSuccess() + "|resultCode:" + result.getResultCode() + "|resultMsg:" + result.getResultMsg(), new Object[] { jobData.getJobId(), jobData.getJobGroup(), jobData.getJobName(), result.isSuccess(), result.getResultCode(), result.getResultMsg() }); } else { logger.info( "fail|jobId:" + jobData.getJobId() + "|jobGroup:" + jobData.getJobGroup() + "|jobName:" + jobData.getJobName() + "|success:" + result.isSuccess() + "|resultCode:" + result.getResultCode() + "|resultMsg:" + result.getResultMsg(), new Object[] { jobData.getJobId(), jobData.getJobGroup(), jobData.getJobName(), result.isSuccess(), result.getResultCode(), result.getResultMsg() }); } } catch (Exception e) { result = JobResult.errorResult( JobResult.RESULTCODE_OTHER_ERR, "处理任务失败,errorMsg is:" + e.getMessage()); logger.info( "fail|jobId:" + jobData.getJobId() + "|jobGroup:" + jobData.getJobGroup() + "|jobName:" + jobData.getJobName() + "|success:" + result.isSuccess() + "|resultCode:" + result.getResultCode() + "|resultMsg:" + result.getResultMsg()); } result.setJobId(jobData.getJobId()); return result; }