<?php
set_time_limit(3600);
error_reporting(E_ALL);
require_once 'config.php';

$flag = APPLICATION_PATH . '/../data/log/notifygs.lock';

if (@file_exists($flag)) {
    echo "Another process is running.\r\n";
    echo "{$flag}\r\n";
    exit();
}

$handler = fopen($flag, 'wb');
fclose($handler);

echo '[', date('Y-m-d H:i:s'), '] Starting.', "\r\n";

$condition = array('status'=>'0');
$counts = Service_GsInventoryNotify::getByCondition($condition,'count(*)');

if($counts>0){
    $pageSize = 1;
    $page = 1;
    $i = 1;
    while( $rows = Service_GsInventoryNotify::getByCondition($condition,'*',$pageSize,$page) ) {
        $condition['gin_id_gt'] = $rows[ count($rows) - 1 ]['gin_id'];
        try{
            $notify = new Service_GsNotifyProcess();
            $notify->notifyGS($rows);

        } catch( Exception $e) {
            echo $e->getMessage()."\r\n";
        }
        sleep(2);
        ++$i;
        //echo "[" . date('Y-m-d H:i:s') . "] End run\r\n";
        //@unlink($flag);
        //exit;
    }
}
echo "[" . date('Y-m-d H:i:s') . "] End run\r\n";
@unlink($flag);

