2

I've seen several examples and all of them just trigger one job at a specific time, I have right now: 0 */5 * ? * * and it triggers at mins 0,5,10, and on. But, I need the trigger to run at +5 of the moment that the trigger was enabled.

So, if service becomes enable at 12:07 pm I need it to run then at 12:12 pm and on. Is there a way to accomplish this?

  • have you tried looking at this https://stackoverflow.com/a/16094616/6568402... you can have offsets specific to your trigger time. For example : You can add an offset of 7 or 12 depending on however u want to set up crons. – arjnt Oct 01 '20 at 22:41
  • Thanks @arjithn i've seen several of them, but not what I'm looking, the thing is that I don't know which would be the offset cause the idea is to trigger or the timer start counting 5 minutes after cloudwatch-eventbridge is enabled. – Juan Sebastian Montoya Contrer Oct 01 '20 at 22:47
  • Got it! I have posted an answer based on my understanding. let me know if it actually addresses your question. – arjnt Oct 01 '20 at 23:04

2 Answers2

3

Like you mentioned offsets are part of the solution to your problem.

0 */5+your_offset * ? * *

Now coming to what could be your offset:

Let's say cloudwatch-event bridge is enabled at some 12:07, (You can get that info from event details timestamp.)

your_offset = 7 + 5
// so your cron becomes :  0 */5+12 * ? * *

Or in general your

offset = the minute part of timestamp + 5 
// for your to schedule 5 mins after service is enabled
arjnt
  • 723
  • 1
  • 5
  • 20
  • 1
    So, basically i'll have to change everytime the cron expression my eventbrinds-cloudwatch rule? Because they are strict and will not allow me (as far as I know) to modify with variables its behavior, so I would have to (probably) delete and create back the rule with the desired offset. It may work but probably not what my boss expects (:P) – Juan Sebastian Montoya Contrer Oct 01 '20 at 23:12
  • 1
    Yeah.. sort of! Anyways I'd advise you to check one more time, cos there might be some APIs available that can be called from sdk or cli to modify the rule. I'm not sure. But hey if it is there... then it solves your problem! Cheers mate! – arjnt Oct 01 '20 at 23:16
  • You were right, after reading a bit more the documentation and being a bit more fresher than yesterday, I found the method that might help, thanks pal :) gonna use docs + yours, hope my boss doesn't kill me :D – Juan Sebastian Montoya Contrer Oct 02 '20 at 16:07
0

Solution is simple:

Before create the rule check the minute time at that moment

time_minutes_now */5 * ? * *