@@ -22,6 +22,7 @@ import { LeaseAcquisitionError } from './lease_errors.js'
22
22
23
23
export class ListrLease {
24
24
public static readonly DEFAULT_LEASE_ACQUIRE_ATTEMPTS = 10
25
+ public static readonly ACQUIRE_LEASE_TASK_TITLE = 'Acquire lease'
25
26
26
27
private constructor ( ) {
27
28
throw new Error ( 'This class cannot be instantiated' )
@@ -30,7 +31,7 @@ export class ListrLease {
30
31
public static newAcquireLeaseTask ( lease : Lease , task : ListrTaskWrapper < any , any , any > ) {
31
32
return task . newListr ( [
32
33
{
33
- title : 'Acquire lease' ,
34
+ title : ListrLease . ACQUIRE_LEASE_TASK_TITLE ,
34
35
task : async ( _ , task ) => {
35
36
await ListrLease . acquireWithRetry ( lease , task )
36
37
}
@@ -49,17 +50,17 @@ export class ListrLease {
49
50
50
51
let attempt : number
51
52
let innerError : Error | null = null
52
- for ( attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
53
+ for ( attempt = 0 ; attempt < maxAttempts ; attempt ++ ) {
53
54
try {
54
55
await lease . acquire ( )
55
56
task . title = `${ title } - ${ chalk . green ( 'lease acquired successfully' ) } ` +
56
- `, attempt: ${ chalk . cyan ( attempt . toString ( ) ) } /${ chalk . cyan ( maxAttempts . toString ( ) ) } `
57
+ `, attempt: ${ chalk . cyan ( ( attempt + 1 ) . toString ( ) ) } /${ chalk . cyan ( maxAttempts . toString ( ) ) } `
57
58
return
58
59
} catch ( e : LeaseAcquisitionError | any ) {
59
60
task . title = `${ title } - ${ chalk . gray ( `lease exists, attempting again in ${ lease . DurationSeconds } seconds` ) } ` +
60
- `, attempt: ${ chalk . cyan ( attempt . toString ( ) ) } /${ chalk . cyan ( maxAttempts . toString ( ) ) } `
61
+ `, attempt: ${ chalk . cyan ( ( attempt + 1 ) . toString ( ) ) } /${ chalk . cyan ( maxAttempts . toString ( ) ) } `
61
62
62
- if ( attempt === maxAttempts ) {
63
+ if ( attempt === maxAttempts - 1 ) {
63
64
innerError = e
64
65
}
65
66
}
0 commit comments