Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix execution #329

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* #L%
*/



import com.condation.cms.api.scheduler.CronJob;
import com.condation.cms.api.scheduler.CronJobContext;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
Expand All @@ -36,25 +36,20 @@
*
* @author t.marx
*/
@DisallowConcurrentExecution
public class SingleCronJobRunner implements Job {

public static final String DATA_CRONJOB = "cronjob";
public static final String DATA_CONTEXT = "context";

private static final Lock lock = new ReentrantLock(true);


@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (context.getJobDetail().getJobDataMap().get(DATA_CRONJOB) != null) {
CronJobContext jobContext = (CronJobContext) context.getJobDetail().getJobDataMap().get(DATA_CONTEXT);

lock.lock();
try {
((CronJob)context.getJobDetail().getJobDataMap().get(DATA_CRONJOB)).accept(jobContext);
} finally {
lock.unlock();
}
CronJobContext jobContext = (CronJobContext) context.getJobDetail().getJobDataMap().get(DATA_CONTEXT);
CronJob cronJob = (CronJob) context.getJobDetail().getJobDataMap().get(DATA_CRONJOB);

if (cronJob != null && jobContext != null) {
cronJob.accept(jobContext);
}
}

}