Firmware breaking code execution - red light flashes

I have been trying to resolve the issue in following simple firmware,

basically I want to execute do work for 30 seconds

int secAlive = 30;//number of seconds to keep on reading
int secPassedSinceTrigger = 0;

String write_cont_fast() {
    int secPrev = Time.local() % 86400;
    bool waitUntilTimeUp = true;
    while(waitUntilTimeUp){
        delay(500);
        
        //do some work
        CloudPublish("do work", "do work");
        
        int secNow = Time.local() % 86400;
        secPassedSinceTrigger = secNow - secPrev;
        
        CloudPublish("seconds passed", String(secPassedSinceTrigger));
        
        if(secPassedSinceTrigger >= secAlive){
            CloudPublish("condition", "condition");
            waitUntilTimeUp = false;
        }
    }
    secPassedSinceTrigger = 0;
}

String write_cont_exit() {
     CloudPublish("do work2", "do work2");
    delay(4000);//let the command execute
}

void CloudPublish(String key, String value) {
    Particle.publish(key, value);
}

void setup() {
    
}

void loop() {
    write_cont_fast();
    write_cont_exit();
    CloudPublish("exit", "exited");
}

My firmware never executes until exit.
it just flashes the red light after 30 seconds

help

Try changing all these time related variable types to unsigned long or timer_t

secAlive
secPrev
secNow

also the publish rate is too high - a device is only allowed 1 publish per second or 4 in 4s … so you may need to consolidate messages or introduce a larger delay