cron icon indicating copy to clipboard operation
cron copied to clipboard

[Feature Request] Add parse.Prev() to get past scheduled events

Open toni-moreno opened this issue 4 years ago • 1 comments

Hello.

I would like if there is an easy way to get parse.Prev(anytime) and if not, could be interesting to add , as a solution to get previous scheduled events.

Of course this new feature has no sense on an job scheduling system. ( in the future)

USE CASE

We work with cron to define "flexible periodical time windows" as mask for compute SLA's

this could be done with SLOTS of cron based activated/deactivated windows

SLOT1: 
* Activate "45 07 * * *"  
* Deactivate "45 08 * * *"
SLOT2: 
* Activate "05 12 * * * " 
* Deactivate "10 12 * * *" 

TimeWindow = SLOT1 && SLOT2

image

The previous state ( before 7am) depends on the closest event (could be 0 or 1 ) but I need something like that.

parser1.Parse("45 07 * * *" )
prev_active=parse1.Prev(7am) 
parser2.Parse("45 08 * * *" )
prev_deact=parse2.Prev(7am) 

if prev_active > prev_deact {
   past_state=1
} else {
   past_state = 0
}

In this case was 0 because closest event from deactivate schedule

Any Idea on how to do this work with this great cron tool?

Thank you very much!

toni-moreno avatar Jun 18 '20 16:06 toni-moreno

I've added this PR to do this: https://github.com/robfig/cron/pull/437

juliev0 avatar Feb 01 '22 20:02 juliev0