public static APISubmitLongJobEvent __example__() { APISubmitLongJobEvent event = new APISubmitLongJobEvent(); LongJobInventory inv = new LongJobInventory(); inv.setUuid(uuid()); event.setInventory(inv); event.setNeedAudit(false); return event; } }
@Override public void run(MessageReply rly) { SubmitLongJobReply reply = rly.castReply(); evt.setInventory(reply.getInventory()); evt.setNeedAudit(reply.isNeedAudit()); bus.publish(evt); } });
private void validate(APISubmitLongJobMsg msg) { Class<APIMessage> apiClass = apiMsgOfLongJob.get(msg.getJobName()); if (null == apiClass) { throw new ApiMessageInterceptionException(argerr("%s is not an API", msg.getJobName())); } APIMessage jobMsg = JSONObjectUtil.toObject(msg.getJobData(), apiClass); jobMsg.setSession(msg.getSession()); try { jobMsg = apiMediator.getProcesser().process(jobMsg); // may throw ApiMessageInterceptionException } catch (StopRoutingException e) { // if got stop routing exception persist a success long job and return event success LongJobVO vo = createSuccessLongJob(msg); APISubmitLongJobEvent evt = new APISubmitLongJobEvent(msg.getId()); evt.setInventory(LongJobInventory.valueOf(vo)); evt.setNeedAudit(false); bus.publish(evt); throw e; } msg.setJobData(JSONObjectUtil.toJsonString(jobMsg)); // msg may be changed during validation }
private void handle(APISubmitLongJobMsg msg) { APISubmitLongJobEvent evt = new APISubmitLongJobEvent(msg.getId()); SubmitLongJobMsg smsg = SubmitLongJobMsg.valueOf(msg); bus.makeLocalServiceId(smsg, LongJobConstants.SERVICE_ID); bus.send(smsg, new CloudBusCallBack(msg) { @Override public void run(MessageReply rly) { SubmitLongJobReply reply = rly.castReply(); evt.setInventory(reply.getInventory()); evt.setNeedAudit(reply.isNeedAudit()); bus.publish(evt); } }); }
@Override public void after(APIEvent evt) { if (evt.isSuccess()) { String uuid = ((APISubmitLongJobEvent)evt).getInventory().getUuid(); ntfy("Submitted long job[uuid:%s] for %s", uuid, jobName) .resource(uuid, LongJobVO.class.getSimpleName()) .messageAndEvent(that, evt).done(); } } };
private void validate(APIRerunLongJobMsg msg) { LongJobVO vo = Q.New(LongJobVO.class) .eq(LongJobVO_.uuid, msg.getUuid()) .find(); LongJobState state = vo.getState(); if (state != LongJobState.Succeeded && state != LongJobState.Canceled && state != LongJobState.Failed) { throw new ApiMessageInterceptionException(argerr("rerun longjob only when it's succeeded, canceled, or failed")); } Class<APIMessage> apiClass = apiMsgOfLongJob.get(vo.getJobName()); APIMessage jobMsg = JSONObjectUtil.toObject(vo.getJobData(), apiClass); jobMsg.setSession(msg.getSession()); try { apiMediator.getProcesser().process(jobMsg); // may throw ApiMessageInterceptionException } catch (StopRoutingException e) { APISubmitLongJobEvent evt = new APISubmitLongJobEvent(msg.getId()); evt.setInventory(LongJobInventory.valueOf(vo)); evt.setNeedAudit(false); bus.publish(evt); throw e; } dbf.updateAndRefresh(vo); }