Blind server Calendar events not executing properly.

I have several scripts (they are sending emails by the way) that get executed from the Calendar App. They run on a Mac Mini (10.15) with no screen attached.

My suspicion is that when they execute the server is in sleep mode or something and since it at that point does not see the network they fail (I noted that it always takes a few seconds for the network is available on my other computer). Or would it be something else? Would be great to hear if anybody has another idea as to what it could be.

So, is there any way of waking the computer up to make sure it is all working as should before the rest of the script executes?

I tried this but that does not seem to make a difference:

set networkUp to false
repeat until networkUp is true
	try
		do shell script "ping -o -t 5 www.google.com"
		set networkUp to true
	on error
		beep
		delay 5
		-- something went wrong, so try again in 5 seconds
	end try
end repeat

Any ideas as to how to fix this?

Thanks KniazidisR and good morning. I can see why this is a better solution.

I am going to give this a go.