Offline and/or reboot a node after job completes

I wrote a hook to reboot a node once a jobs completes. I have it set to run on event=jobexec_end.
It works, but unfortunately once the node comes back online, it seems to think it needs to run that hook again, and I end up in a boot loop. What am I doing wrong?

I would not recommend to reboot the node in a hook events. You can have an external script that monitors the node based on its idleness or threshold time limit with no jobs on the node (say there were no jobs running on the node for a duration of 5 minutes), then reboot the node.