Particle Electron seems to stop publishing. Why?

Particle.function() should return an int, and it should return quickly, so putting long delays in those is not good practice. I doubt this has anything to do with your publish problem, but it should be corrected anyway.