Ref T9252. Currently, Harbormaster and Drydock work like this in some cases:
- Queue a lease for activation.
- Then, a little later, save the lease PHID somewhere.
- When the target/resource is destroyed, destroy the lease.
However, something can happen between (1) and (2). In Drydock this window is very short and the "something" would have to be a lighting strike or something similar, but in Harbormaster we wait until the resource activates to do (2) so the window can be many minutes long. In particular, a user can use "Abort Build" during those many minutes.
If they do, the target is destroyed but it doesn't yet have a record of the artifact, so the artifact isn't cleaned up.
Make these things work like this instead:
- Create a new lease and pre-generate a PHID for it.
- Save that PHID as something that needs to be cleaned up.
- Queue the lease for activation.
- When the target/resource is destroyed, destroy the lease if it exists.
This makes sure there's no step in the process where we might lose track of a lease/resource.
Also, clean up and standardize some other stuff I hit.