Workers is a service offered by the JFrog Cloud Platform that allows you to develop and execute Plugins, enhancing the functionality of the JFrog Platform through an integrated serverless execution environment.
Benefits of Using Workers:
-Enhanced automation of workflows
-Minimal maintenance required
-Simple setup process
-Smooth user experience
HTTP-triggered workers:
These Workers are executed in response to HTTP requests. In simpler words, when there is a trigger using REST API or JFog CLI, validate certain condition (optional) and perform defined action.
For example - cleanup:
Condition Trigger Action
Steps to perform Generic Cleanup using http triggered worker:
Create a http triggered worker
Add the related typescript script from the JFrog Github link (for artifact cleanup), name the workers, and toggle the enabled button.
Test it in the “Testing” tab by adding the payload with dryrun enabled. The payload contains the repositories and the other parameters like timeUnit and timeInterval that are set to determine the cleanup candidates.
Test it in the “Testing” tab by adding the payload with dryrun enabled. The payload contains the repositories and the other parameters like timeUnit and timeInterval that are set to determine the cleanup candidates.
The worker can be triggered by using REST API or by utilizing the JFrog CLI by defining the payload in a json file using the format given below.
Note:
By setting the dryrun as false - the workers would actually get triggered, i.e. the data will be deleted from the mentioned repositories provided they meet the set criteria.
Example CLI command to execute the worker:
jf worker exec <worker> @payload.json
Example REST API to execute the worker
curl -XPOST --location 'https://<servername>/worker/api/v1/execute/cleanup' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"repos": [
"test-libs-release-local"
],
"timeUnit": "day",
"timeInterval": 90,
"dryRun": true,
"disablePropertiesSupport": true,
"limit": 100,
"concurrency": 10
}'
{"data":{"status":"STATUS_SUCCESS","message":"1 item(s) processed"},"executionStatus":"STATUS_SUCCESS"}
Note:
The above workflow is valid for various repositories cleanup but not docker, for docker, please follow this article.