Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48603

Add a 'nowait' option to the lockable resources plugin

      I found some requests to add a timeout to the plugin, or a number of tries.

      My proposal is simpler: add a nowait option

      This option would try to acquire the lock only once, enter the closure code if it could successfully lock the resource and throw an exception if it couldn't.

      We actually use the lockable-resource plugin with "virtual ressources" to check concurrent access to some environment by different jobs. We dont want to wait for the resource to be free, i strongly believe that this behaviour may also be wanted with real resources (easy to implement a loop for retries and fallbacks with a nowait option).

      We actually use an ugly workaround like

          stage("Check concurrent environment access") {
              try {
                  timeout(time: 3, unit: 'SECONDS') {
                      lock("${EnvName}-${EnvNumber}") {}
                  }
              } catch (Exception e) {
                  error("Another job on this environment is already in progress: " + e)
              }
              println "No concurrent access detected, executing job..."
          }
           // Lock environment resource
          lock("${EnvName}-${EnvNumber}") {
              closure()
          }

      Which is not safe, we would prefer to use something like

              try {
                  lock("${EnvName}-${EnvNumber}", nowait=true) {

                      closure()

                  }
              } catch (LockedResource e) {
                  error("Another job on this environment is already in progress: " + e)
              }
       

       

          [JENKINS-48603] Add a 'nowait' option to the lockable resources plugin

          Eric Van de Flaes created issue -
          Eric Van de Flaes made changes -
          Description Original: I found some requests to add a timeout to the plugin, or a number of tries.

          My proposal is simpler: add a nowait option

          This option would try to acquire the lock only once, enter the closure code if it could successfully lock the resource and throw an exception if it couldn't.

          We actually use the lockable-resource plugin with "virtual ressources" to check concurrent access to some environment by different jobs. We dont want to wait for the resource to be free, i strongly believe that this behaviour may also be wanted with real resources (easy to implement a loop for retries and fallbacks with a nowait option).

          We actually use an ugly workaround like

              *stage("Check concurrent environment access") \{*
                   *try \{*
                       *timeout(time: 3, unit: 'SECONDS') \{*
                           *lock("$\{EnvName}-$\{EnvNumber}") \{}*
                       *}*
                   *} catch (Exception e) \{*
                       *error("Another job on this environment is already in progress: " + e)*
                   *}*
                   *println "No concurrent access detected, executing job..."*
               *}*
                *// Lock environment resource*
               *lock("cnx-$\{EnvName}-$\{EnvNumber}") \{*
                   *closure()*
               *}*

          Which is not safe, we would prefer to use something like

                  *try \{*
                       *lock("$\{EnvName}-$\{EnvNumber}", nowait=true) \{*

                          c*losure()*

                      *}*
                   *} catch (LockedResource e) \{*
                       *error("Another job on this environment is already in progress: " + e)*
                   *}*
           

           
          New: I found some requests to add a timeout to the plugin, or a number of tries.

          My proposal is simpler: add a nowait option

          This option would try to acquire the lock only once, enter the closure code if it could successfully lock the resource and throw an exception if it couldn't.

          We actually use the lockable-resource plugin with "virtual ressources" to check concurrent access to some environment by different jobs. We dont want to wait for the resource to be free, i strongly believe that this behaviour may also be wanted with real resources (easy to implement a loop for retries and fallbacks with a nowait option).

          We actually use an ugly workaround like

              *stage("Check concurrent environment access") \{*
                   *try \{*
                       *timeout(time: 3, unit: 'SECONDS') \{*
                           *lock("$\{EnvName}-$\{EnvNumber}") \{}*
                       *}*
                   *} catch (Exception e) \{*
                       *error("Another job on this environment is already in progress: " + e)*
                   *}*
                   *println "No concurrent access detected, executing job..."*
               *}*
                *// Lock environment resource*
               *lock("$\{EnvName}-$\{EnvNumber}") \{*
                   *closure()*
               *}*

          Which is not safe, we would prefer to use something like

                  *try \{*
                       *lock("$\{EnvName}-$\{EnvNumber}", nowait=true) \{*

                          closure()

                      *}*
                   *} catch (LockedResource e) \{*
                       *error("Another job on this environment is already in progress: " + e)*
                   *}*
            

           
          Daniel Beck made changes -
          Link New: This issue is related to JENKINS-41699 [ JENKINS-41699 ]
          Luis Tejada made changes -
          Link New: This issue is related to JENKINS-61502 [ JENKINS-61502 ]

            Unassigned Unassigned
            ericvdf Eric Van de Flaes
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: