Results 1 to 5 of 5

Thread: How to intercept last cron execution ?

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Question 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. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    735

    Default

    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

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    Default

    Quote 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.

  4. #4
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    735

    Default

    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

  5. #5
    Join Date
    Jun 2012
    Posts
    3

    Default

    Quote 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •