<?php
/************************************************
 * Name: MyMVC
 * Desc: Bu yapı Özel olarak tasarlanmıştır izinson olarak kullanılması yasaktır
 * Auth: Berk Ermiş(0530 044 64 78)
 * Vers: v1.1
*************************************************/

use App\System\Model\LogModel;
use App\System\Model\TaskModel;
use App\System\Vendor\beTask;

require_once(dirname(__FILE__)."/../init.php");
$time = BE_TIME;
$tasks = TaskModel::beSelect("tid,tname,tfilename,tcronminute,tcronhour,tcronday")->beWhere("tstatus","1")->beWhere("tnextruntime",$time,"<")->beWhere("tlocktime",$time,"<")->beOrder("tqueque","ASC")->beGetAll();
foreach($tasks as $task){
    $response = beTask::beRunTask($task);
    if(!$response["status"]){
        if($response["type"] == 2){
            TaskModel::beUpdate([
                "tlastruntime" => $time,
                "tlocktime" => $time+360
            ])->beWhere("tid",$task["tid"])->beExecute();
        }
        else{
            TaskModel::beUpdate([
                "tstatus" => 0,
                "tlastruntime" => $time
            ])->beWhere("tid",$task["tid"])->beExecute();
        }
        continue;
    }
    TaskModel::beUpdate([
        "tlastruntime" => $time,
        "tnextruntime" => beTask::beGetNextRun($task["tcronminute"],$task["tcronhour"],$task["tcronday"])
    ])->beWhere("tid",$task["tid"])->beExecute();
}
?>