Introduction Many organizations may find it useful to track Artifactory usage on a repository level. No two use cases are exactly the same. Here we will implement one use case of tracking the last time any item was downloaded from a repository. This method can be used as a jumping off point for further custom made solutions that fit your organization’s needs. This solution will provide us with a repository level property with a timestamp of the last time an artifact was downloaded from that repository.Guide To get started, ensure workers are set up in the environment. For general details on workers and installation, please refer to our documentation. Once workers are installed and configured, we can create a new event driven worker ‘After Download’. Please see ‘After Download’ worker example here.
We can use the linked sample code and modify it to better fit our use case. Instead of doing an Artifactory ping, we can add a property to the repository using the Set Property API:
const now = Date.now();
const repo = data.metadata.repoPath.key;
const res = await context.clients.platformHttp.put(`/artifactory/api/storage/${repo}?properties=last_downloaded_repo=${now}&recursive=0`);
These three lines of code get the current time, get the repository that the user just downloaded from, and set a property on that repository noting the most recent download timestamp. We can then add the repositories in the worker settings that we would like the worker to apply to:Now, after downloading an artifact from a repository, we will see the repository level property update to the current timestamp (refer to the image in the introduction). We can apply this same method to further customize properties based on Artifactory events to better track usage. For more information regarding worker capabilities, please see our documentation here: https://jfrog.com/help/r/jfrog-platform-administration-documentation/workers.