0

I am trying to run my job every end of month but i am getting an error every time i add cron expression :

from("timer://ratingTimer?cron=0+52+12+++") this is i am trying to run my job for specific time. Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: timer://ratingTimer?cron=0+52+12+%3F++* due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{cron=0 52 12 ? * *}]

  • Possible Duplicate of https://stackoverflow.com/questions/6139189/cron-job-to-run-on-the-last-day-of-the-month – prem30488 Oct 16 '20 at 11:05
  • from("quartz://myGroup/ratingTimer?cron=0+0+3+L+*+?")..., change myGroup as per your code. see more here - https://camel.apache.org/components/latest/quartz-component.html – prem30488 Oct 16 '20 at 11:50
  • `from("cron://ratingTimer?schedule=0+0+3+L+*+?")`..... should also work. – prem30488 Oct 16 '20 at 11:52

1 Answers1

0

We will schedule cron on 28,28,29 and 31’st of each month. Now find if today is the last day of the month. To find it check if the next day is 01’st of next day and then only execute any command.

Below command will return the date of the next day.

date +%d -d tomorrow

Now check if tomorrow is 01.

[ "$(date +%d -d tomorrow)" = "01" ] && echo "True"

If the next day is 01 then above command will print “True” on screen. Here you can use the above script in crontab and change echo with your command.

59 23 28-31 * * [ “$(date +%d -d tomorrow)” = “01” ] && /root/script.sh

Check more in below url.

CRON job to run on the last day of the month

AND

quartz scheduler: run on last day of the month

from("cron://ratingTimer?schedule=0+0+3+L+*+?")

prem30488
  • 2,828
  • 2
  • 25
  • 57
  • This seems to be in the shell script , but can I incorporate the changes in Java as I have read about patterns and timer of camel context. – user3489632 Oct 16 '20 at 11:15
  • And mine is not purely a cron job but the route that has been added to run service. – user3489632 Oct 16 '20 at 11:16
  • Use 0 0 3 L * ? . – prem30488 Oct 16 '20 at 11:21
  • See this ->https://stackoverflow.com/questions/4962011/quartz-scheduler-run-on-last-day-of-the-month – prem30488 Oct 16 '20 at 11:22
  • Thanks but I am still not getting how to map it with the route timer. from("timer://someTimer?cron=0+52+12+*+*+*").setBody().simple("running the service now").to("bean:ServiceImpl?method=someMethod"); – user3489632 Oct 16 '20 at 11:28
  • L character is allowed only for the day-of-month and day-of-week fields. It means “last”, for example, L in the day-of-month field means “the last day of the month” – prem30488 Oct 16 '20 at 11:32
  • Try this - `from("timer://ratingTimer?cron=0+0+3+L+*+?")`. Also give error stack trace in question. – prem30488 Oct 16 '20 at 11:43
  • At 03:00:00am, on the last day of the month, every month this expression meant to fire. – prem30488 Oct 16 '20 at 11:46
  • use quartz instead of timer in from method – prem30488 Oct 16 '20 at 11:50
  • Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: timer://ratingTimer?cron=0+0+3+L+*+%3F due to: Failed to resolve endpoint: timer://ratingTimer?cron=0+0+3+L+*+%3F due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{cron=0 0 3 L * ?}] at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:753) at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) – user3489632 Oct 16 '20 at 11:51
  • from("timer://ratingTimer?fixedRate=true&period="+timer) It works fine with this when specify timer as 1000ms – user3489632 Oct 16 '20 at 11:53
  • from("cron://ratingTimer?schedule=0+0+3+L+*+?") – prem30488 Oct 16 '20 at 11:54
  • Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cron://ratingTimer?schedule=0+0+3+L+*+%3F due to: No component found with scheme: cron – user3489632 Oct 18 '20 at 19:58
  • provide `pom.xml` code. Did you add depenency? Use latest dependency in `pom.xml`. – prem30488 Oct 20 '20 at 09:58