filecoin-project / filecoin-chain-archiver

Filecoin snapshot / chain export software
Other
5 stars 3 forks source link

wait for lock to be acquired #52

Closed coryschwartz closed 1 year ago

coryschwartz commented 1 year ago

Add a flag to wait until the lock can be acquired.

This is to facilitate lock acquisition in scripts.

This is how it works:

  1. create a new lock

    ./filecoin-chain-archiver nodelocker operator lock abc pass
    peerid:abc, acquired:true, expiry:2022-11-04 17:39:56.820841486 -0700 PDT
  2. Using the same secret, you can update the lock, as usual.

/filecoin-chain-archiver nodelocker operator lock abc pass
peerid:abc, acquired:true, expiry:2022-11-04 17:40:53.458506528 -0700 PDT
  1. Using a new secret, encounter an error trying to get the lock. This is new behavior. We get an exit code telling us the lock was not acquired correctly.
./filecoin-chain-archiver nodelocker operator lock abc pass2
peerid:abc, acquired:false, expiry:2022-11-04 17:41:52.042761722 -0700 PDT
2022-11-04T17:40:55.100-0700    ERROR   filecoin-chain-archiver filecoin-chain-archiver/main.go:44  exit    {"error": "lock not aquired"}

echo $?
1
  1. To make things easier, pass the -w flag. This will wait until the lock is acquired. This will continue until we own the lock.
    
    ./filecoin-chain-archiver nodelocker operator lock -w abc pass2
    peerid:abc, acquired:false, expiry:2022-11-04 17:48:02.350208491 -0700 PDT
    peerid:abc, acquired:true, expiry:2022-11-04 17:49:03.357054703 -0700 PDT

echo $? 0