-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10 make it possible to create cron jobs with site.globals.js or module
- Loading branch information
Thorsten Marx
committed
Aug 21, 2024
1 parent
b0251d4
commit 2081f51
Showing
23 changed files
with
715 additions
and
124 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...api/src/main/java/com/github/thmarx/cms/api/feature/features/CronJobSchedulerFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.thmarx.cms.api.feature.features; | ||
|
||
/*- | ||
* #%L | ||
* cms-api | ||
* %% | ||
* Copyright (C) 2023 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import com.github.thmarx.cms.api.feature.Feature; | ||
import com.github.thmarx.cms.api.scheduler.CronJobScheduler; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public record CronJobSchedulerFeature(CronJobScheduler cronJobScheduler) implements Feature { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
cms-core/src/main/java/com/github/thmarx/cms/core/scheduler/DefaultCronJobRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.thmarx.cms.core.scheduler; | ||
|
||
/*- | ||
* #%L | ||
* cms-core | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
|
||
import com.github.thmarx.cms.api.scheduler.CronJob; | ||
import com.github.thmarx.cms.api.scheduler.CronJobContext; | ||
import static com.github.thmarx.cms.core.scheduler.SingleCronJobRunner.DATA_CONTEXT; | ||
import static com.github.thmarx.cms.core.scheduler.SingleCronJobRunner.DATA_CRONJOB; | ||
import org.quartz.Job; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class DefaultCronJobRunner implements Job { | ||
|
||
@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); | ||
((CronJob)context.getJobDetail().getJobDataMap().get(DATA_CRONJOB)).accept(jobContext); | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
cms-core/src/main/java/com/github/thmarx/cms/core/scheduler/ScriptCronJobRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.github.thmarx.cms.core.scheduler; | ||
|
||
/*- | ||
* #%L | ||
* cms-core | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
|
||
import com.github.thmarx.cms.api.scheduler.CronJob; | ||
import com.github.thmarx.cms.api.scheduler.CronJobContext; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
import org.quartz.Job; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class ScriptCronJobRunner 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(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
cms-core/src/main/java/com/github/thmarx/cms/core/scheduler/SingleCronJobScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.thmarx.cms.core.scheduler; | ||
|
||
/*- | ||
* #%L | ||
* cms-core | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import com.github.thmarx.cms.api.scheduler.CronJob; | ||
import com.github.thmarx.cms.api.scheduler.CronJobContext; | ||
import com.github.thmarx.cms.api.scheduler.CronJobScheduler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.quartz.Scheduler; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
@Slf4j | ||
public class SingleCronJobScheduler extends AbstractCronJobScheduler implements CronJobScheduler { | ||
|
||
public SingleCronJobScheduler(Scheduler scheduler, CronJobContext context) { | ||
super(scheduler, context); | ||
} | ||
|
||
@Override | ||
public void schedule(String cronExpression, String name, CronJob job) { | ||
super.schedule(cronExpression, name, job, SingleCronJobRunner.class); | ||
} | ||
|
||
@Override | ||
public void remove(String name) { | ||
super.remove(name); | ||
} | ||
|
||
@Override | ||
public boolean exists(String name) { | ||
return super.exists(name); | ||
} | ||
} |
Oops, something went wrong.