Announcement Announcement Module
Collapse
No announcement yet.
How to intercept last cron execution ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to intercept last cron execution ?

    Hello guys,

    I am facing a problem that I think it is not so uncommon but it is being hard to find out the solution, so let's go.

    First I have configured an inbound-channel-adapter that defines a poller that basically is a cron that is running perfectly, as you can see below:

    Code:
    <inbound-channel-adapter id="cronAdapter" ref="messageGenerator" method="generateMessage" channel="jobInstanceRecieverChannel">
            <poller cron="0 0/1 19-22 ? * MON-FRI" />
        </inbound-channel-adapter>
    Now, the problem is: I would like to execute a validation on the last cron execution, is it possible ? Is there any kind of interceptor or something like this, that I can use for this purpose ?

    Many thanks,

    Regards.

  • #2
    Hello

    As I understand you say that your cron-trigger will stop scheduling once.
    So, you can inherite from org.springframework.scheduling.support.CronTrigger and overwrite his method nextExecutionTime and inject this trigger bean into <poller>'s ref attribute.
    Trigger stops scheduling when nextExecutionTime returns null

    But what do you mean about validation ? What are you going to validate?

    Artem

    Comment


    • #3
      Originally posted by Cleric View Post
      Hello

      As I understand you say that your cron-trigger will stop scheduling once.
      So, you can inherite from org.springframework.scheduling.support.CronTrigger and overwrite his method nextExecutionTime and inject this trigger bean into <poller>'s ref attribute.
      Trigger stops scheduling when nextExecutionTime returns null

      But what do you mean about validation ? What are you going to validate?

      Artem
      I will validate whether all the data that I need to process is available on the database. That's why I need to validate it on the last cron's execution. If the data is not available until the last execution, I need to send an email report.

      So, basically I will replace
      Code:
      <poller cron="0 0/1 19-22 ? * MON-FRI" />
      by
      Code:
      <poller ref="myCron" /> 
      <bean id="myCron" class="..."><constructor-arg value="0 0/1 19-22 ? * MON-FRI" /></bean>
      That's right ?

      I will try it and then let you know the result, thanks in advance.

      Comment


      • #4
        I will try it and then let you know the result
        Well, than it will be enough to publish some event from your custom trigger, when nextExecutionTime is null, to initiate your validation process.
        A question from me: is there only one point based on cron time, when you're understanding you data is full?
        I propose investigate a pattern for similar tasks - aggregator. In this case this solution https://jira.springsource.org/browse/INT-2595 would be for you

        Comment


        • #5
          Originally posted by Cleric View Post
          A question from me: is there only one point based on cron time, when you're understanding you data is full?
          In fact, during the cron's execution time, I check whether the data is available, in affirmative case, I process the data and then send a message to my "shutdownChannel" that will finish the application's execution, I don't even execute the validation on the cron's last execution time. That's why I think the first solution proposed fits perfectly.

          Comment

          Working...
          X