Multiple Volumes Unmounted, Run Macro Once

Does that matter?

I'll admit I haven't tested, so I don't know what happens when you've three or four instances of the macro all trying to eject the same list of disks, but that's a separate problem.

It's good practice to make functions, sub-routines, sub-macros, etc as self-contained as possible -- if only so you don't have to remember to include a whole bunch of constraints in any caller. If we never want multiple concurrent instances of "Backup Drives [Off]" it makes sense to add an insta-kill lock. If we never want multiple concurrent instances of the calling macro we can use a (different) lock on that, too -- whether that be an insta-kill or one to force serialisation.

What's best will depend on the overall requirements and constraints, and I don't think we have the full picture here. But I also have the feeling that these macros are being split up for "organisational" rather than "functional" reasons -- I'd probably have them all in a single "eject the disks, once all unmounted turn off the enclosure" macro.

Perhaps not, in this case. Rule #23: Never argue with Nige.

As I said earlier it probably doesn’t matter that it runs multiple times, but it’s unnecessary and therefore inefficient. Thus, @Airy, I appreciate the suggestion for the Semaphore lock with the timeout for that stage as it is also part of the problem I was trying to solve in my initial question.

They are indeed all functional. I normally create sub macros across the board for obvious reasons as I am always running them from other macros, at different times, for different purposes. In this case, the drive unmount trigger macro kills multiple birds: automatic after a backup is complete, or if I manually eject any disks outside of the backup. The outlet control is triggered after a backup but I also use it with a different macro that I run manually to control the outlets.

1 Like

Which is why you may want to semaphore that, too.

It does depend on the macro. If it's

if outlet is on then
   turn it off
else
   do nothing

...then there's probably no need. But if it's:

toggle outlet state

...then you probably should. Lots of options, so very much suck it and see.

Yes, exactly - I agree, makes it much more self contained, which I love. I was previously using a pause (see below) but the Lock makes more sense.

In this case I’m not bothering to check if the outlet is on because as long as the drive(s) is on then the outlet is on. But yes, the lock at the control script is necessary because the script triggers a Python script that authenticates to a PDU via ssh and the PDU ssh implementation isn’t great so instead of trying to allow multiple connections (which I’m not sure is even possible with the PDU), it’s easier to force one at a time.

1 Like