eve-seat / seat

SeAT 0x. [UNSUPPORTED]
https://github.com/eveseat/seat
MIT License
69 stars 38 forks source link

Corrupt cache interrupting update tasks #409

Closed MilosRasic closed 7 years ago

MilosRasic commented 8 years ago

I noticed my data pulled from API keys is growing stale, with very low number or 0 tasks in queue and some keys last updated days or even weeks ago.

Found out, by starting seatscheduled:api-update-all-characters manually, that corrupt cache files are throwing an exception and interrupting the task, starving all the keys that are supposed to be iterated after the one with corrupt cache.

The error is in method validateCache($xml) which throws an exception when it runs into invalid xml. My solution is to not throw an exception and simply return false if invalid xml is encountered:

public function validateCache($xml)
{
    $tz = date_default_timezone_get();
    date_default_timezone_set("UTC");

    try {
        $xml = @new \SimpleXMLElement($xml);
    }
    catch (Exception $e) {
        $xml = false;
    }

    if (!$xml)
        return false;

    $dt = (int) strtotime($xml->cachedUntil);
    $time = time();

    date_default_timezone_set($tz);

    return (bool) ($dt > $time);
}

Not sure if just return false; would work, but this is good enough.

You also need to use Exception; or try/catch blocks will be ignored.

eve-seat commented 8 years ago

Is this in the PhealNG dependency? For now we may as well delete a corrupt cache entry tbh (assuming I am understanding this correctly).

With the move to Laravel 5.1, I will update the dependencies too, hoping the upstream package is fixed.

MilosRasic commented 8 years ago

Good point. Editing the dependency is not a good idea in your case. Maybe try to catch and handle the exception wherever validateCache() is called?

eve-seat commented 8 years ago

Yeah some form of error handling will have to be done in this case. Hoping upstream has this sorted though :)