Skip to content

Commit

Permalink
Merge pull request #205 from dukhlov/periodic-work-delay-fix
Browse files Browse the repository at this point in the history
Fix Cron periodic work to run at the beginning of each minute.
  • Loading branch information
res0nance authored Feb 9, 2024
2 parents 0f7c5f6 + 962c138 commit cd2deb2
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.PeriodicWork;
import hudson.model.AperiodicWork;
import hudson.triggers.Trigger;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;

import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

@Extension
public class Cron extends PeriodicWork {
public class Cron extends AperiodicWork {
private static final Logger LOGGER = Logger.getLogger(Cron.class.getName());

// time constants
protected static final long MIN = 1000 * 60;

@Override
public AperiodicWork getNewInstance() {
return new Cron();
}

@Override
public long getRecurrencePeriod() {
return TimeUnit.MINUTES.toMillis(1);
return getInitialDelay();
}

@Override
Expand All @@ -29,7 +36,7 @@ public long getInitialDelay() {
}

@Override
protected void doRun() {
protected void doAperiodicRun() {
Jenkins instance = Jenkins.get();

for (AbstractProject<?, ?> project : instance.allItems(AbstractProject.class)) {
Expand Down

0 comments on commit cd2deb2

Please sign in to comment.