Question

Set fme scheduler to run on last day of the month

  • 24 January 2019
  • 3 replies
  • 18 views

Badge

Hello,

 

what is the best way to set scheduler to run on last day of each month? Cron would be good here but what if we would like to run this job on last day of the month but every X monts for example every 3 months?

 

In Cron there is a limitation that once we get to the next year it will break.

 

If I would not use CRON but standard interval how FME would behave if I would set it to run on January 31st with interval set to 1 month? When it would be executed next time?


3 replies

Badge +2

Hi @witos

 

 

What version of FME Server are you using?

 

 

Because the month interval period uses an average month time, there's no guarantee that it would always fall on the last day of the month. A rough calculation for me shows that the average month is 30.3 days, so if you start it running on the 31st of January, there's a chance the next time the schedule would run could be the 1st or 2nd of March.

 

 

I did a quick look online and it seems for most cron solutions it's a lot easier to set up a cron expression to run on the 1st of every month - I don't know whether this is acceptable for you?

 

 

A less elegant solution could be to incorporate some logic into the workspace (possibly python if the datetime functions allow it) to see when the next last day of the month is, and use the FME Server REST API to update the schedule so that it will run on the last day of the month.
Badge +3

@witos

You can run the script and have it start with some datetimecalculations.

Then create attributes to test.

Like

"first day of month"

[clock format [clock scan "today"] -format %d]==1

and then a tester tot test "first day of month"

 

[expr [clock format [clock scan "today"] -format %d] -1]==1 would be end of prior month.

 

"quarter begin"

(@fmod([expr [clock format [clock scan "today"] -format %m]-1],3)==0)&&([clock format [clock scan "today"] -format %e]==1)

and again testing the attributevalue.

 

For instance i have this one running; "1st sunday of Quarter"

(@fmod([expr [clock format [clock scan "today"] -format %m]-1],3)==0)&&([clock format [clock scan "today"] -format %w]==0)&&

 

([clock format [expr [clock scan "today"] - 604800] -format %m]!=[clock format [clock scan "today"] -format %m])

 

The workbench runs and if "1st sunday of Quarter" is true it will execute workbench or else quit.

(These are tcl, of course you can go snake if you would insist)

 

Pretty elegant me thinks.

 

Userlevel 1
Badge +21

With the date time functions available now, it's possible to get the last day of the month just within an attribute creator (Get the current date, convert to date only, add 1 month, convert to first day of that month and take away one day)

@DateTimeAdd(@Left(@DateTimeFormat(@DateTimeAdd(@DateTimeNow(),P1M),%Y%m%d),6)01,-P1D)

Reply