jenkinsapi icon indicating copy to clipboard operation
jenkinsapi copied to clipboard

Add support for lockable resources

Open cdleonard opened this issue 5 months ago • 3 comments

This adds a new class for managing lockable resources from python. It includes some helpful context managers so you can do stuff like this:

    with jenkins.lockable_resources.reservation_by_label("aaa") as r:
        print(f"locked resource {r.locked_resource_name}")

The intended use case is hardware reservation systems backed by jenkins. There is no CLI.

I also found a similar implementation as external package: https://gitlab.com/alexandre-perrin1/jenkins-lockable-resources. It seems unmaintained, I was unable to install due to dependency conflicts and such.

This PR contains full systest support so the CI will test the code against a running jenkins instance. Hopefully this makes it easy to maintain.

cdleonard avatar Jul 23 '25 12:07 cdleonard

This went through several force-pushes as I added more features and fix linting issues.

Current version is stable

cdleonard avatar Jul 25 '25 12:07 cdleonard

Rebased addressing review comments and integrating a some other changes:

  • Rewrite RetryConfig so that it is reusable.
  • Turn ResourceSelector into ABC
  • Add custom ResourceReservationTimeoutError class
  • Add LockedResourceReservation.is_active, with tests
  • Remove unused LockedResourceReservation.locked field
  • Improve documentation

The RetryConfig class is very basic, the purpose of this abstraction is to allow more complex implementations - for example based on tenacity. I wanted to avoid adding dependencies.

cdleonard avatar Aug 25 '25 16:08 cdleonard

rebased to fix codacy

cdleonard avatar Aug 25 '25 16:08 cdleonard