Particle-CLI OTA Electron flashing timed out

Assuming that eventX() and eventY() are realy fast returning (< 1ms - if not the risk increases) but processEventX() and processEventY() are rather long running you may still run into the problem outlined above.

One workaround would be

void loop()
{
	uint32_t ms = millis();
	while(System.updatesPending() && millis() - ms < 120000) Particle.process();
   
	if (eventX())
	{
		processEventX();
	}
	
	if (eventY())
	{
		processEventY();
	}
}

This might still fail when the OTA update starts during processEventX() or processEventY() but should help in the other cases to keep your code from interfering while an update is being downloaded and applied (max. 2 minutes).

To have an option that also works in the edge cases, you could subscribe to the system event that indicates and OTA update and trap the code there.