How to get the quartz getNextFiretime (Java) - quartz-scheduler

I am working on my automation project where I need trigger some functionality for every 8 hours to see if the expected web element is displayed. I am using the quartz scheduler to trigger the functionality for every 8 hours.
When I run the code, the nextfireTime is displayed for the 1st iteration. once the first iteration is completed, the code is waiting for the next iteration. But the time is not printed in the log. How can do that?
StdSchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
JobDetail Job1 = JobBuilder.newJob(myJob.class).build();
Trigger t1 = TriggerBuilder.newTrigger().withIdentity("cronTrigger1","group1").withSchedule(CronSchedulerBuilder.cronSchedule ("0/3 0 0 ? * * *)).build();
while (!elementtext.contains("***************"))
{
Date Currenttime = new Date();
Date date = scheduler.schedulejob(job1,t1);
scheduler.start();
log.info(job1.key() + will run at : +t1.getNextFiretime());
}
if (elementtext.contains("**********")){
scheduler.shutdown();
}
I expect the time to be displayed after the 1st run. But it is not displayed.

Related

Which one will suit for complete workflow design Temporal or Cadence

I wanted to design a complete end-to-end workflow orchestration engine.
It has the following requirements
Linear workflow
Parallel workflow - I wanted to execute n no of activities parallelly. After validates the results from all the activities I wanted to
proceed to the next state or will fail the workflow
Batch - say I have 30 activities to be completed but I want this to be done in a batch fashion. Like if the window size is 5 then I wanted
to execute 5 activities at a time T. After executing all the activities
and validates the results will proceed further or fail the workflow.
Loop - wanted to run an activity infinitely until some condition meets
Child Workflow
Polling
All 1-5 are supported easily in Cadence workflow. I am not sure what you mean by Polling. If you can provide more details, I will update this answer to help you.
Here is the sample to execute activities in Leaner+parallel/batch+loop:
#Override
public long calculate(long a, long b, long c) {
LOGGER.info("workflow start...");
long result = 0;
// Async.invoke takes method reference and activity parameters and returns Promise.
Promise<Long> ab = Async.function(activities::multiple, a, b);
Promise<Long> ac = Async.function(activities::multiple, a, c);
Promise<Long> bc = Async.function(activities::multiple, b, c);
// Promise#get blocks until result is ready.
this.abPlusAcPlusBc = result = ab.get() + ac.get() + bc.get();
// waiting 30s for a human input to decide the factor N for g(n), based on a*b+a*c+b*c
// the waiting timer is durable, independent of workers' liveness
final boolean received = Workflow.await(Duration.ofMinutes(2), () -> this.factorForGn > 1);
if (!received) {
this.factorForGn = 10;
}
long fi_1 = 0; // f(0)
long fi_2 = 1; // f(1)
this.currentG = 1; // current g = f(0)*f(0) + f(1)*f(1)
long i = 2;
for (; i < this.factorForGn; i++) {
// get next fibonacci number
long fi = fi_1 + fi_2;
fi_2 = fi_1;
fi_1 = fi;
this.currentG += activities.multiple(fi, fi);
}
result += this.currentG;
return result;
}
And this is the sample of using ChildWorkflow.

NextExecution time with quartz definition fails when date if the end of the month

Currently, I have a cron job scheduling for every minute but once the date is the end of the month, the nextExecution method fails to provide the proper date.
test("check execution times") {
// make sure the execution times are correct
val expression = "0 * * ? * * *" // every minute (the top of the minute)
val currentTime = "2019-12-31T00:00:00.000Z" // get current time
val expectedNextExecution = "2019-12-31T00:01:00.000Z" // get current time
val cron = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).parse(expression)
val executor = ExecutionTime.forCron(cron)
val actualNextExecution = executor.nextExecution(DateTime.parse(currentTime)).toString // call nextExecution which should give us the next top of the minute
// check if nextExecution has correct next execution time
assert(actualNextExecution == expectedNextExecution, "Wrong execution time")
}
Results :
Expected :"20[19-12-31T00:01]:00.000Z"
Wrong execution time Actual :"20[20-01-01T00:00]:00.000Z"
The answer to this was updating my cron-utils version.
Previously on:
4.1.0
Issue was fixed on:
9.0.2
Thank you

Anylogic Variable Not Updating

I an using a discrete event simulator in AnyLogic. I am having an issue with some code which updates a variable in my simulation. I store both the datetime at which the agent leaves the source block and the datetime at which it enters the sink block. I am trying to record the number of "rule breaks" for all agents. The rule break is defined below (two ways to break):
1) If the agent is received before a certain time (called SDC) and the agent is not completed by 5pm the same day, then the agent has broken the rule
2) If the agent is not completed by the next day at a certain time (called NDC), then the agent has broken the rule
I record a zero or a one for each agent if they break either rule in the variable called RuleBreak. However, in my simulation runs, the variable does not update at all. I hope I am just missing something small. Would appreciate any help! (code below)
Calendar received = Calendar.getInstance();
received.setTime(ReceivedDate);
Calendar completion = Calendar.getInstance();
completion.setTime(Completion);
Calendar SD_at_5 = Calendar.getInstance();
SD_at_5.setTime(ReceivedDate);
SD_at_5.set(Calendar.HOUR_OF_DAY,17);
SD_at_5.set(Calendar.MINUTE, 0);
SD_at_5.set(Calendar.SECOND, 0);
Calendar Tomorrow_at_NDC = Calendar.getInstance();
Tomorrow_at_NDC.setTime(ReceivedDate);
if(Tomorrow_at_NDC.get(Calendar.DAY_OF_WEEK) == 6)
Tomorrow_at_NDC.add(Calendar.DATE, 3);
else
Tomorrow_at_NDC.add(Calendar.DATE, 1);
Tomorrow_at_NDC.add(Calendar.DATE, 1);
Tomorrow_at_NDC.set(Calendar.HOUR_OF_DAY,NDC);
Tomorrow_at_NDC.set(Calendar.MINUTE, 0);
Tomorrow_at_NDC.set(Calendar.SECOND, 0);
int Either_rule_break = 0;
double time_diff_SDC = differenceInCalendarUnits(TimeUnits.SECOND,completion.getTime(),SD_at_5.getTime());
double time_diff_NDC = differenceInCalendarUnits(TimeUnits.SECOND,completion.getTime(),Tomorrow_at_NDC.getTime());
if((received.get(Calendar.HOUR_OF_DAY) < SDC) && (time_diff_SDC <= 0))
Either_rule_break = Either_rule_break + 1;
else
Either_rule_break = Either_rule_break + 0;
if((received.get(Calendar.HOUR_OF_DAY) >= SDC) && (time_diff_NDC <= 0))
Either_rule_break = Either_rule_break + 1;
else
Either_rule_break = Either_rule_break + 0;
if((Either_rule_break >= 1))
RuleBreak = RuleBreak + 1;
else
RuleBreak = RuleBreak + 0;
You haven't really explained where this code is used and what it receives. I assume the code is in a function, called in the sink's on-enter action, where ReceivedDate and Completion are Date instances stored per agent (source exit time and sink entry time, as dates, captured via AnyLogic's date() function).
And looks like your SDC hour-of-day is stored in SDC and your NDC hour-of-day in NDC (with RuleBreak being a variable in Main or similar storing the total number of rule-breaks).
Your calculations look OK except that the Tomorrow_at_NDC Calendar calculation seems wrong: you add 1 day twice (if not Saturday) or 3 days plus 1 day (if Saturday; in a Java Calendar, day-of-week 1 is Monday).
(Your Java is also very 'inefficient' with unnecessary extra local variables and performing logic when you don't need to; e.g., no point doing all the calendar preparation and check for your type 1 rule-break if the receive time is after the SDC hour.)
But are you sure there are any rule-breaks; how have you set up your model to ensure that there are (to test it)? Plus is RuleBreak definitely a variable outside of the agents that flow through your DES (i.e., in Main or similar)? Plus are Completion and ReceivedDate definitely stored per agent so, for example, if your function was called checkForRuleBreaks you would be doing something like the below in your sink on-exit action:
agent.Completion = date(); // Agent received date set earlier in Source action
checkForRuleBreaks(agent.ReceivedDate, agent.Completion);
(In fact, you don't need to store the completion date in the agent at all since that will always be the current sim-date inside your function and so you can just calculate it there.)

How to create a countdown timer for a Readme.md

I got this project that I'm collaborating on with other collaborators, the project is divided into stages, and each stage has it's time frame. I wanna create a countdown timer that should always show on the README.md file on github so that whenever a collaborator visits the github repo, he/she see the time remaining for that very stage to be finished.
Something like this:
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
window.onload = function () {
var fiveMinutes = 60 * 5,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
<body>
<div>Stage one ends in <span id="time">05:00</span> minutes!</div>
</body>
But I will not want it to trigger the next stage automatically after the first stage is done, I will love to be the one to trigger the countdown timer again for the next stage.
NOTE: I am asking on how to implement this on a README.md file for github

DHTMLX Scheduler - Calendar view - set focus to config.mark_now

When loading the calendar, I have divided the hours into intervals of 30 mins each.
This is my initial configuration.
scheduler.locale.labels.unit_tab = "Resources";
scheduler.config.hour_date = "%h:%i %A";
scheduler.config.hour_size_px = 88;
scheduler.config.mark_now = true;
scheduler.locale.labels.section_custom = "Assigned to";
scheduler.config.separate_short_events = true;
scheduler.config.drag_move = false;
scheduler.config.drag_resize = false;
Due to the 30 mins, my calendar has a scroll bar. The default calendar shows only about 6.5 hrs. So if the current time is 3 PM, the mark_now line is off the view. How do I set focus to the current time and have the current time or mark_now be in the horizontal center of the display?
I am learning dhtmlx and may not be able to answer all queries so would appreciate any guidance. Thanks in advance!
You can add something like next
scheduler.config.scroll_hour = (new Date).getHours();
It will configure scheduler to scroll day or week view to the current hour.