Hello World,I am currently working on the Automatic Git Cache Maintenance Project under GSoC 2022. The aim of the project is to integrate git maintenance command to Jenkins to optimize the caches present on the Jenkins Controller.
Administrators can schedule various maintenance tasks by entering CronSytax in the UI. The data entered is stored internally in an XML file. I am confused between PeriodicWork/AsyncPeriodicWork to schedule the maintenance tasks.
The way I am thinking to implement is to extend this class and check every minute whether any of the maintenance task satisfy the cronSyntax entered by the administrator. If the current time satisfies the cronSyntax of a particulat task, then that task is added to a queue.
I am planning to create another thread which consumes the maintenance tasks present in the queue. The reason for creating another thread is to not block the thread which validates and pushes the maintenance task into the queue. The javadoc of PeriodicWork suggests to use it if the work done is short. I am more inclined towards using PeriodicWork. However, I am not sure about the performance.
I am not sure if this is the best approach and looking for help from the community. Open to suggestions and discussion.
Thank You Hrushikesh Rao || -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/5ed04dcb-898b-d48e-69ca-6b91db44b1ab%40gmail.com.Title: PeriodicWork (Jenkins core 2.354 API)
Class PeriodicWork
- java.lang.Object
-
- java.util.TimerTask
-
- hudson.triggers.SafeTimerTask
-
- hudson.model.PeriodicWork
-
- All Implemented Interfaces:
ExtensionPoint,Runnable
- Direct Known Subclasses:
AsyncPeriodicWork,ComputerRetentionWork,HudsonHomeDiskUsageChecker,LoadStatistics.LoadStatisticsUpdater,MemoryUsageMonitor,NodeProvisioner.NodeProvisionerInvoker,Trigger.Cron
public abstract class PeriodicWork extends SafeTimerTask implements ExtensionPoint
Extension point to perform a periodic task in Hudson (throughTimer.)This extension point is useful if your plugin needs to perform some work in the background periodically (for example, monitoring, batch processing, garbage collection, etc.)
Put
Extensionon your class to have it picked up and registered automatically, or manually insert this toTrigger.timer.This class is designed to run a short task. Implementations whose periodic work takes a long time to run should extend from
AsyncPeriodicWorkinstead.- Author:
- Kohsuke Kawaguchi
- See Also:
AsyncPeriodicWork
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class hudson.triggers.SafeTimerTask
SafeTimerTask.ExceptionRunnable
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description PeriodicWork()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ExtensionList<PeriodicWork>all()Returns all the registeredPeriodicWorks.longgetInitialDelay()Gets the number of milliseconds til the first execution.abstract longgetRecurrencePeriod()Gets the number of milliseconds between successive executions.static voidinit()-
Methods inherited from class hudson.triggers.SafeTimerTask
doRun, getLogsRoot, of, run
-
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
-
-
-
Field Detail
-
logger
@Deprecated protected final Logger logger
Deprecated.Use your own logger, or send messages to the logger inAsyncPeriodicWork.execute(hudson.model.TaskListener).
-
MIN
protected static final long MIN
- See Also:
- Constant Field Values
-
HOUR
protected static final long HOUR
- See Also:
- Constant Field Values
-
DAY
protected static final long DAY
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRecurrencePeriod
public abstract long getRecurrencePeriod()
Gets the number of milliseconds between successive executions.Hudson calls this method once to set up a recurring timer, instead of calling this each time after the previous execution completed. So this class cannot be used to implement a non-regular recurring timer.
IOW, the method should always return the same value.
-
getInitialDelay
public long getInitialDelay()
Gets the number of milliseconds til the first execution.By default it chooses the value randomly between 0 and
getRecurrencePeriod()
-
all
public static ExtensionList<PeriodicWork> all()
Returns all the registeredPeriodicWorks.
-
init
@Initializer(after=JOB_CONFIG_ADAPTED) public static void init()
-
-
Class AsyncPeriodicWork
- java.lang.Object
-
- java.util.TimerTask
-
- hudson.triggers.SafeTimerTask
-
- hudson.model.PeriodicWork
-
- hudson.model.AsyncPeriodicWork
-
- All Implemented Interfaces:
ExtensionPoint,Runnable
- Direct Known Subclasses:
BackgroundGlobalBuildDiscarder,ConnectionActivityMonitor,DailyCheck,FingerprintCleanupThread,Telemetry.TelemetryReporter,WorkspaceCleanupThread
public abstract class AsyncPeriodicWork extends PeriodicWork
PeriodicWorkthat takes a long time to run.Subclasses will implement the
execute(TaskListener)method and can carry out a long-running task. This runs in a separate thread so as not to block the timer thread, and this class handles all those details.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class hudson.triggers.SafeTimerTask
SafeTimerTask.ExceptionRunnable
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAsyncPeriodicWork(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StreamTaskListenercreateListener()voiddoRun()Schedules this periodic work now in a new thread, if one isn't already running.protected abstract voidexecute(TaskListener listener)Executes the task.protected LevelgetErrorLoggingLevel()Returns the logging level at which error messages are displayed.protected FilegetLogFile()Determines the log file that records the result of this task.protected LevelgetNormalLoggingLevel()Returns the logging level at which normal messages are displayed.protected LevelgetSlowLoggingLevel()Returns the logging level at which previous task still executing messages is displayed.-
Methods inherited from class hudson.model.PeriodicWork
all, getInitialDelay, getRecurrencePeriod, init
-
Methods inherited from class hudson.triggers.SafeTimerTask
getLogsRoot, of, run
-
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
-
-
-
Field Detail
-
name
public final String name
Human readable name of the work.
-
-
Constructor Detail
-
AsyncPeriodicWork
protected AsyncPeriodicWork(String name)
-
-
Method Detail
-
doRun
public final void doRun()
Schedules this periodic work now in a new thread, if one isn't already running.- Specified by:
doRunin classSafeTimerTask
-
createListener
protected StreamTaskListener createListener()
-
getLogFile
protected File getLogFile()
Determines the log file that records the result of this task.
-
getNormalLoggingLevel
protected Level getNormalLoggingLevel()
Returns the logging level at which normal messages are displayed.- Returns:
- The logging level as @Level.
- Since:
- 1.551
-
getSlowLoggingLevel
protected Level getSlowLoggingLevel()
Returns the logging level at which previous task still executing messages is displayed.- Returns:
- The logging level as @Level.
- Since:
- 1.565
-
getErrorLoggingLevel
protected Level getErrorLoggingLevel()
Returns the logging level at which error messages are displayed.- Returns:
- The logging level as @Level.
- Since:
- 1.551
-
execute
protected abstract void execute(TaskListener listener) throws IOException, InterruptedException
Executes the task.- Parameters:
listener- Output sent will be reported to the users. (this work is TBD.)- Throws:
InterruptedException- The caller will record the exception and moves on.IOException- The caller will record the exception and moves on.
-
-
