[ 
https://issues.apache.org/jira/browse/SLING-3699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14043568#comment-14043568
 ] 

Anshika Agarwal commented on SLING-3699:
----------------------------------------

As a workaround, I am unscheduling the job just before returning the JobResult 
and after it is executed, using following piece of code snippet:

Collection<ScheduledJobInfo> scheduledJobs = jobManager.getScheduledJobs();
                for (ScheduledJobInfo eachJob : scheduledJobs) {
                        Map<String, Object> eachJobProps = 
eachJob.getJobProperties();
                        if 
(eachJob.getJobTopic().equals(AssetUpdateListener.REPLICATION_EVENT_TOPIC) && 
                                        
eachJobProps.get(AssetUpdateListener.PROPERTY_FORM_PATH).equals(formPath) &&    
                                        
eachJobProps.get(AssetUpdateListener.PROPERTY_REPLICATION_ATTRIBUTE).equals(replicationAtribute))
 {
                                eachJob.unschedule();
                        }
                }

Should I go forward with this approach? Would this approach create a problem 
once this issue is fixed in sling?

> [Job Scheduling] A job scheduled using JobBuilder does not get removed if the 
> JobConsumer returns JobResult.OK
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: SLING-3699
>                 URL: https://issues.apache.org/jira/browse/SLING-3699
>             Project: Sling
>          Issue Type: Bug
>          Components: API
>            Reporter: Anshika Agarwal
>            Priority: Critical
>              Labels: scheduler, scheduling
>
> Behavior:
> If we schedule a job to be executed at a specific time for a topic using:
> JobBuilder jobBuilder = jobManager.createJob(EVENT_TOPIC);    
> jobBuilder.properties(props).schedule().at(activationTime).add();
> It first creates a node of type "slingevent:TimedEvent" in crx repository 
> under "/var/eventing/scheduled-jobs" and when the exact time arrives (in this 
> case activationTime), a node of type "slingevent:Job" gets created under 
> assigned jobs and posts an event to the JobConsumer.
> Issue:
> When the JobConsumer returns JobResult.OK the node of type 
> "slingevent:TimedEvent" (scheduled job) does not get removed from the list.
> Due to this issue, when the server restarts, all the jobs that were earlier 
> scheduled and had finished with their execution, get executed again to become 
> nodes of type "slingevent:Job" and again post an event to the JobConsumer. 
> This happens for all the jobs scheduled for a time that is before the current 
> time (when the server restarts)
> Desired:
> Although, we wish to have the scheduled jobs to persist even after the server 
> restarts, but only the jobs that have not yet been executed should be 
> executed after restart. This implies that all the jobs that are executed 
> should be removed from the list of scheduled jobs once the JobConsumer 
> returns JobResult.OK



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to