AntonLV 1 год назад
Родитель
Сommit
c5f2ae6dd1

+ 7 - 2
inc/classes/BxDolBackgroundJobs.php

@@ -89,12 +89,17 @@ class BxDolBackgroundJobs  extends BxDolFactory implements iBxDolSingleton
         if(empty($mixedJob['service_call']) || !BxDolService::isSerializedService($mixedJob['service_call']))
             return false;
 
+        $this->_oQuery->updateJob($mixedJob['name'], [
+            'status' => 'processing'
+        ]);
+
+        $fStart = microtime(true);
         BxDolService::callSerialized($mixedJob['service_call']);
+        $fTiming = microtime(true) - $fStart;
 
         $this->_oQuery->deleteJob($mixedJob['name']);
 
-        bx_log($this->_sObjectLog, "Processed: " . $mixedJob['name']);
-
+        bx_log($this->_sObjectLog, "Processed: " . $mixedJob['name'] . " / timing: " . $fTiming . " / memory: " . memory_get_usage());
         return true;
     }
 

+ 18 - 0
inc/classes/BxDolBackgroundJobsQuery.php

@@ -60,6 +60,24 @@ class BxDolBackgroundJobsQuery extends BxDolDb
         ]) !== false;
     }
 
+    public function updateJob($sName, $aParamsSet)
+    {
+        if(empty($sName))
+            return false;
+
+        return $this->updateJobExt($aParamsSet, [
+            'name' => $sName
+        ]);
+    }
+
+    public function updateJobExt($aParamsSet, $aParamsWhere)
+    {
+        if(empty($aParamsSet) || empty($aParamsWhere))
+            return false;
+
+        return $this->query("UPDATE `sys_background_jobs` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
+    }
+
     public function deleteJob($sName)
     {
         return $this->query("DELETE FROM `sys_background_jobs` WHERE `name`=:name", [

+ 1 - 0
install/sql/system.sql

@@ -2471,6 +2471,7 @@ CREATE TABLE `sys_background_jobs` (
   `added` int(11) unsigned NOT NULL default '0',
   `priority` tinyint(4) unsigned NOT NULL default '0',
   `service_call` text NOT NULL default '', 
+  `status` varchar(16) NOT NULL default 'awaiting',
   PRIMARY KEY (`id`),
   UNIQUE KEY `name` (`name`)
 );