Worflow never finish running as schedule job

I have one workflow that run under schedule when an employee field condition is accomplish.
I saw that some employees ran well but I realize that there are two similar process running with the same employee name but one apperar complete but the other is still runing 4 days age.

I’ve had occasions where I had to unblock workflows by going in the database and manually marking as deleted a job that was hung in table job_queue.

But it would be important to figure out exactly which circumstances cause the job to hang in the first place… to avoid future problems.

pgr, thanks for your comments, this errro started after hosting migration. the database is now mariadb.
I just deleted the job in Job_queue. But I don’t know why is triggering twice.
The loginc of work flow is very simple.
I created in the employee table a data field called “next_insurance_charge”. The workflow run only on the schedule when this date is <= today the work flow run creating a record is one table and updating emplyee field “next_insurance_charge” + one week, then the work flow is running a weekly basis.
Before migration every this worked well but since teh cron ob was created the process with some records happen. It is odd becase each week the process is repeated with dioferents employees.
Is there any way to check if the process is running before to lauch the new one?.

Both these methods from object SugarJobQueue are executed for every cron run:

    /**
     * Cleanup old, failed or long running jobs
     * Forcefully remove jobs that are marked as running when they exceed the timeout value
     * @return bool true if no failed job discovered, false if some job were failed
     */
    public function cleanup()
    {
        $ret = true;
        $date = $this->db->convert($GLOBALS['timedate']->getNow()->modify("-{$this->timeout} seconds")->asDb(), 'datetime');
        $sql = "SELECT id FROM {$this->job_queue_table} WHERE status='".SchedulersJob::JOB_STATUS_RUNNING."' AND date_modified <= '{$date}'";
        $res = $this->db->query($sql);
        while ($row = $this->db->fetchByAssoc($res)) {
            $this->resolveJob($row["id"], SchedulersJob::JOB_FAILURE, translate('ERR_TIMEOUT', 'SchedulersJobs'));
            $ret = false;
        }
        return $ret;
    }

    /**
     * Marks jobs for deletion that have exceeded their history lifetime
     * Uses different values for successful and failed jobs
     */
    public function clearHistoricJobs()
    {
        // Process successful jobs
        $date = $this->db->convert($GLOBALS['timedate']->getNow()->modify("-{$this->success_lifetime} days")->asDb(), 'datetime');
        $sql = "SELECT id FROM {$this->job_queue_table} WHERE status='".SchedulersJob::JOB_STATUS_DONE."' AND resolution='".SchedulersJob::JOB_SUCCESS."' AND date_modified <= '{$date}'";
        $res = $this->db->query($sql);
        while ($row = $this->db->fetchByAssoc($res)) {
            $this->deleteJob($row["id"]);
        }

        // Process failed jobs
        $date = $this->db->convert($GLOBALS['timedate']->getNow()->modify("-{$this->failure_lifetime} days")->asDb(), 'datetime');
        $sql = "SELECT id FROM {$this->job_queue_table} WHERE status='".SchedulersJob::JOB_STATUS_DONE."' AND resolution!='".SchedulersJob::JOB_SUCCESS."' AND date_modified <= '{$date}'";
        $res = $this->db->query($sql);
        while ($row = $this->db->fetchByAssoc($res)) {
            $this->deleteJob($row["id"]);
        }
    }

I don’t understand all that they do, but supposedly the code is there to take care of these situations… maybe you can try running that in your case through a debugger and see what is really happening.

I would suspect date format issues, since you mentioned a hosting change. Check that your date.timezone is correct in both php.inis: both the web server one, and the CLI - which is what the schedulers will use when running.