Why use scheduled workers?
Scheduled Workers are automated processes that run tasks at specific intervals or predetermined times, handling maintenance activities, cleanup jobs, and other essential routines for platform management.
Note:
By executing tasks during off-peak hours, Scheduled Workers maximize resource usage and minimize operational disruptions, ensuring smooth and efficient functioning of the platform.
Steps to perform artifact cleanup using scheduled workers
Follow these steps to set up and execute Scheduled Workers for cleaning up older artifacts:
1. Create a new scheduled worker by navigating to the JFrog Platform --> Administration Tab --> Workers --> New Workers and select "New Scheduled Workers."
2. In the settings section, enter the appropriate CRON expression.
3. Copy the provided script from the Github link here (an example for cleanup using workers) and add the following function in the script just before the function doArtifactCleanup(context: PlatformContext, data: ArtifactCleanupPayload) as shown in the screenshot below[fig 1.0].
export default async function artifactCleanup(context: PlatformContext) {
await doArtifactCleanup(context, {
repos: ['repo-1', 'repo-2'],
dryRun: false,
disablePropertiesSupport: false,
timeUnit: 'minute',
timeInterval: 1,
limit: DEFAULT_LIMIT,
concurrency: DEFAULT_REMOVE_CONCURRENCY
});
}
fig 1.0
Please note: We need to embed the code within the script and pass the value to it; scheduled workers can execute it based on the cron accordingly. If we pass this in the payload, it will simultaneously work for testing but not for the cron schedules.
The function includes the following parameters for cleanup:
repos: An array of repositories, e.g., ['repo-1', 'repo-2'], to specify multiple repositories.
timeUnit: The unit of time, which can be 'minute', 'hour', 'day', 'month', or 'year'.
timeInterval: A number that corresponds to the timeUnit. For example, if the timeUnit is 'month', setting the timeInterval to 1 will target artifacts older than 1 month.
dryRun: A boolean parameter that enables dry-run mode when set to true. This allows you to test the function without making any actual changes.
Other parameters are optional.
4. Enable the toggle to activate the cron job and save the scheduled workers for future use.
5. To verify the dry-run logs, check the execution logs shown in the screenshot.
Please note: Running the script without a dry run set to true will delete the artifacts from the mentioned repositories. We suggest doing a dry run with a sample set before running the cleanup for the first time to avoid any unintentional data loss.