Quartz schedule except specific time - quartz-scheduler

Is it possible to create a CronExpression with: "fire every 5 min but not run at 00:05 and 00:10"?
org.quartz.CronScheduleBuilder.cronSchedule("0 0/5 * * * ?")

You will have to use two expressions:
0 15/5 0 * * ?
0 0/5 1-23 * * ?
The first expression is specific to 12 AM, the second is for the rest of the time.

Related

How do i format time into seconds in lua?

So basically I'm confused on how I'd make it so that I can convert DD:HH:MM:SS to only seconds while taking into account the amount of numbers there are. (Sorry if I make 0 sense, you should definitely know what I mean by the example below.)
print("05:00":FormatToSeconds()) -- 5 minutes and 0 seconds
-- 300
print("10:30:15":FormatToSeconds()) -- 10 hours, 30 minutes and 15 seconds
-- 37815
print("1:00:00:00":FormatToSeconds()) -- 1 day
-- 86400
print("10:00:00:30":FormatToSeconds()) -- 10 days, 30 seconds
-- 864030
So on and so forth. I think that maybe using gmatch would work but still idk. Help would be greatly appreciated.
Edit:
So I've tried doing it with gmatch, but I don't know if this is the most fastest way of doing this (which it probably isn't), so any help would still be appreciated.
(My code)
function ConvertTimeToSeconds(Time)
local Thingy = {}
local TimeInSeconds = 0
for v in string.gmatch(Time, "%d+") do
if tonumber(string.sub(v, 1, 1)) == 0 then
table.insert(Thingy, tonumber(string.sub(v, 2, 2)))
else
table.insert(Thingy, tonumber(v))
end
end
if #Thingy == 1 then
TimeInSeconds = TimeInSeconds + Thingy[1]
elseif #Thingy == 2 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 60) + Thingy[2]
elseif #Thingy == 3 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 60 * 60) + (Thingy[2] * 60) + Thingy[3]
elseif #Thingy == 4 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 24 * 60 * 60) + (Thingy[2] * 60 * 60) + (Thingy[3] * 60) + Thingy[4]
end
return TimeInSeconds
end
print(ConvertTimeToSeconds("1:00:00:00"))
Don't worry about execution speed before doing any actual measurements unless you're designing a time-critical program. In any extreme situation you'd probably want to offload risky parts to a C module.
Your approach is just fine. There are parts you can clean up: you can just return the results of calculations as TimeInSeconds doesn't actually act as accumulator in your case; tonumber handles '00' just fine and it can ensure decimal integers with an argument (since 5.3).
I'd go the other way and describe factors in a table:
local Factors = {1, 60, 60 * 60, 60 * 60 * 24}
local
function ConvertTimeToSeconds(Time)
local Components = {}
for v in string.gmatch(Time, "%d+") do
table.insert(Components, 1, tonumber(v, 10))
end
if #Components > #Factors then
error("unexpected time component")
end
local TimeInSeconds = 0
for i, v in ipairs(Components) do
TimeInSeconds = TimeInSeconds + v * Factors[i]
end
return TimeInSeconds
end
Of course, both implementations have problem with pattern being naïve as it would match e.g., '00 what 10 ever 10'. To fix that, you could go another route of using string.match with e.g., '(%d+):(%d+):(%d+):(%d+)' and enforcing strict format, or matching each possible variant.
Otherwise you can go all in and use LPeg to parse the duration.
Another way would be to not use strings internally, but instead convert them into a table like {secs=10, mins=1, hours=10, days=1} and then use these tables instead - getting seconds from that representation would be straight-forward.

how to reduce wait time in perl

I have script that queries a database a variable number of times per second.
For example, to achieve 36,000 queries per hour we input 600 queries per minute into our script. 600 x 60 = 36,000
This is the output we get you can see the delay between each query
{1} [2019-11-06 21:38:01.313]
{1} [2019-11-06 21:38:01.413]
{1} [2019-11-06 21:38:01.513]
{1} [2019-11-06 21:38:01.613]
{1} [2019-11-06 21:38:01.713]
{1} [2019-11-06 21:38:01.813]
My problem is we are missing out on that 0.0100 because we have a wait time inplace.
rates per minute = varies we can change this to a max of 960 queries per min but we would want fourmla that is flexible for 0-960.
my $wait_time = (1 / $rpm) * 60 * 1(connection); (max of 4 connections) wait time increases based on number of connections
Does anyone know how to reduce the wait time in between queries ?
thanks
This is the code line
my $wait_time = (1 / $rpm) * 60 * 1;
So when i enter in 600 queries per min
This code line calcuates the wait time based on number of connection we have
my $wait_time = (1 / 600) * 60 * 1;
1/600 * 60 * 1 = WAIT: 0.1
Well, your processing of the query needs time. A fragile solution, if i interpret your problem right, is to measure the time the current processing takes and substract that from the next sleep time. Of course that would break if the processing time equals or exceeds the sleep time.
A clean solution would be to have a dedicated main loop that does nothing but sleeping and firing off queries in separate threads.
I'm not sure if this will help because I have a very hard time understanding your question. I think you are concerned that you aren't making queries at the rate you desire.
It could be because you think of the wait time as being static. It's not the wait time that's static —that's dependent on how long the previous query took— it's the interval that's static.
use Time::HiRes qw( time sleep ); # Add support for fractional times.
my $interval = (1 / $qpm) * 60 * 1; # In (fractional) seconds.
my $next_run = time;
while (1) {
my $wait = $next_run - time;
sleep($wait) if $wait > 0;
$next_run += $interval;
... do work ...
}

Jenkins- how to schedule a build to run every 2 hours from 7 AM to 10PM on Monday through Friday

I'm looking for a way to run a Jenkins build every 2 hours, Monday through Friday only from 7 AM to 10PM. I got 7AM to 10PM and every 2 hours part down but how would I go about adding Monday through Friday to it?
Here is the schedule right now: H 07-22/2 * * *
If I add 1-5 to the above (1 for Monday and 5 for Friday), it gives me an error
" Invalid input: "H 07-22/2 * * * 1-5": line 1:16: expecting EOF,
found ' ' "
Please help me out.
Thanks.
You have too much element in your cron expression.
0 07-22/2 * * 1-5 instead of 0 07-22/2 * * * 1-5

Multiple 'nth' weekday of month in a single quartz cron expression

I'm trying to write a cron expression for quartz that runs hourly everyday except every second Saturday of the month.
So, by using the '#' notation, I was trying to write the expression like:
0 0 * ? * SUN-FRI,SAT#1,SAT#3,SAT#4,SAT#5
This expression is not working properly. Also, quartz is not complaining about the cron format (quartz usually complains about cron expressions when they are wrong).
So I did some other experiments today. So, today is the third Thursday of the month, I was playing around with THU#N notation, and that's what I've found so far (I changed my expression to minute to make it easier for experimenting):
0 * * ? * SUN-FRI,SAT#1,SAT#3,SAT#4,SAT#5: not triggered
0 * * ? * THU#3: triggered
0 * * ? * THU#3,THU#4: not triggered
0 * * ? * THU#2,THU#3: triggered
I know I can simply split this into 4 additional expression but in my real scenario I have tons of expressions to change and this would increase my expression list to something 5 times longer.
In a brief: Does anyone knows how to condense these:
0 0 * ? * SUN-FRI / 0 0 * ? * SAT#1 / 0 0 * ? * SAT#3 / 0 0 * ? * SAT#4 / 0 0 * ? * SAT#5
...into a single cron expression?
Note: I'm using quartz scheduler 1.5 (I know, I know... pretty outdated)

Cronexpression to exclude hours of a specific day

Is it possible to create a CronExpression with:
"fire every day every 20min but not on Saturday between 10:00 and 14:00"?
Something like "0 0/20 * ? * MON-SAT" is clear, but it is not the same...
You will have to use two expressions; One for saturdays, one for all other days:
0 0/20 * * * SUN-FRI command
0 0/20 0-9,14-23 * * SAT command