Best Cerberus-source code snippet using org.cerberus.crud.factory.impl.FactoryScheduledExecution.create
Source: ScheduledJob.java
...84 String convertDateFireTime = simpleDateFormat.format(scheduleFireTime);85 Timestamp factice = new Timestamp(System.currentTimeMillis());86 LOG.info("Job " + schedulerId + " for '" + scheduleName + "' campaign is starting.");87 try {88 ScheduledExecution scheduledExecutionObject = factoryScheduledExecution.create(1, schedulerId, scheduleName, "TOLAUNCH", "Job is created", user, "", scheduledDate, scheduleFireTime, factice, factice);89 //if execution have type campaign90 if (type.equalsIgnoreCase("CAMPAIGN")) {91 try {92 long createScx;93 createScx = scheduledExecutionService.create(scheduledExecutionObject);94 if (createScx > 0) {95 scheduledExecutionObject.setID(createScx);96 try {97 CloseableHttpClient httpclient = null;98 HttpClientBuilder httpclientBuilder;99 httpclientBuilder = HttpClientBuilder.create();100 httpclient = httpclientBuilder.build();101 String request = new String();102 String encodeName = URLEncoder.encode(scheduleName, "UTF-8");103 request = parameterService.getParameterStringByKey("cerberus_url", "", "") + SERVLET_ADDTOEXECUTION + "?campaign=" + encodeName + "&outputformat=json";104 HttpGet requesthttp = new HttpGet(request);105 requesthttp.setHeader("apikey", apiKeyService.getServiceAccountAPIKey());106 HttpResponse responsehttp = httpclient.execute(requesthttp);107 int statusCode = responsehttp.getStatusLine().getStatusCode();108 LOG.info("Url called to trigger Campaign : '" + request + "' status code : " + statusCode);109 if (statusCode == 200 || statusCode == 201) {110 HttpEntity entity = responsehttp.getEntity();111 if (entity != null) {112 scheduledExecutionObject.setStatus(ScheduledExecution.STATUS_TRIGGERED);113 String json_string = EntityUtils.toString(entity);114 try {115 JSONObject temp1 = new JSONObject(json_string);116 StringBuilder message = new StringBuilder();117 message.append(temp1.getString("message"));118 if (!StringUtil.isNullOrEmpty(temp1.getString("tag"))) {119 message.append(" Tag Execution : ");120 message.append(temp1.getString("tag"));121 }122 if (!StringUtil.isNullOrEmpty(message.toString())) {123 scheduledExecutionObject.setComment(message.toString());124 } else {125 scheduledExecutionObject.setComment("Campaign triggered but result got no message output");126 }127 } catch (JSONException e) {128 LOG.error("Failed to parse JSON from URL call. " + request);129 scheduledExecutionObject.setStatus(ScheduledExecution.STATUS_ERROR);130 scheduledExecutionObject.setComment("Campaign triggered but result was not in json format");131 }132 } else {133 scheduledExecutionObject.setStatus(ScheduledExecution.STATUS_TRIGGERED);134 scheduledExecutionObject.setComment("Campaign triggered but empty result from Service " + SERVLET_ADDTOEXECUTION);135 }136 try {137 Answer updateScx = new Answer();138 updateScx = scheduledExecutionService.update(scheduledExecutionObject);139 scheduleEntryService.updateLastExecution(scheduledExecutionObject.getSchedulerId(), scheduledExecutionObject.getScheduledDate());140 } catch (Exception e) {141 LOG.error("Failed to update scheduledExecution", e);142 }143 } else {144 // Http code <> 200 and <> 201145 LOG.error("Request " + request + " return http" + statusCode);146 scheduledExecutionObject.setStatus(ScheduledExecution.STATUS_ERROR);147 scheduledExecutionObject.setComment("Failed to trigger Campaign. Return code : " + statusCode + " From Request : " + request);148 Answer updateScx = scheduledExecutionService.update(scheduledExecutionObject);149 }150 } catch (Exception e) {151 LOG.error("Failed to call " + SERVLET_ADDTOEXECUTION + ", catch exception", e);152 scheduledExecutionObject.setStatus(ScheduledExecution.STATUS_ERROR);153 scheduledExecutionObject.setComment("Failed to trigger Campaign. Error : '" + e.getMessage());154 Answer updateScx = scheduledExecutionService.update(scheduledExecutionObject);155 }156 } else {157 LOG.info("No execution inserted for JobId " + schedulerId + " Campaign '" + scheduleName + " FireTime '" + scheduleFireTime + "' in database (Potentialy another instance of Cerberus already triggered the job).");158 }159 } catch (Exception e) {160 LOG.info("Cannot insert execution for JobId " + schedulerId + " Campaign '" + scheduleName + " FireTime '" + scheduleFireTime + "' in database (Potentialy another instance of Cerberus already triggered the job).");161 }162 }163 } catch (Exception e) {164 //Log if executionScheduled is already insert in base165 LOG.error("Cannot create object, catch exception :" + e);166 }167 } catch (Exception e) {168 LOG.error("Exception catch on Job Execution :" + e);169 }170 }171}...
Check out the latest blogs from LambdaTest on this topic:
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!