root 4 жил өмнө
parent
commit
5f790e05b6

+ 32 - 14
app/Jobs/Vps/SnapshotVmJob.php

@@ -19,51 +19,52 @@ class SnapshotVmJob extends BaseJob {
 
     public function handle($text = null)  {
         openlog("ProxmoxSnapshot", LOG_PID,LOG_SYSLOG);
-        syslog(LOG_NOTICE,"Snapshot Create for " . $this->model->id );
         $this->initParams();
         $this->setHostingId($this->getWhmcsParamByKey("serviceid"));
         if ($this->isDone()) {
             return true;
         } elseif ($this->isTaskRunning())  {
             //sleep
-            $this->sleep(5);
+            $this->sleep(25);
             return false;
         }
+        
+        syslog(LOG_NOTICE,"Snapshot Create for " . $this->model->id );
         $snapshot = new Snapshot();
         $snapshot->setApi($this->api());
         $snapshot->setPath($this->vm()->getPath() . "/snapshot");
         $snapshot->setAttributes([
     	    // Changed by Roland at 2021-08-28 because duplicate snappshot names which causes the error: TASK ERROR: snapshot name 'Secure_280' already used
-    	    // Added ' "_" . date("m") . "_" . date("d") . "_" . date("H"),' to make the snapshot-name more unique
-            "name"        => $this->getSnapshotJob()->name . "_" . $this->model->id . "_" . date("m") . "_" . date("d") . "_" . date("H"),
+    	    // Added ' "_" . date("m") . "_" . date("d") . "_" . date("H") . "_" . date("i"),' to make the snapshot-name more unique
+            "name"        => $this->getSnapshotJob()->name . "_" . date("m") . "_" . date("d") . "_" . date("H") . "_" . date("i"),
             "description" => $this->snapshotJob->description,
         ]);
         syslog(LOG_NOTICE,"   Creating Snapshot for " . $this->getSnapshotJob()->name . "_" . $this->model->id . "_" . date("m") . "_" . date("d") . "_" . date("H"));
         if (!is_null($this->snapshotJob->vmstate ) && $this->vm() instanceof  Kvm) {
             $snapshot->setVmstate($this->snapshotJob->vmstate );
         }
+        
         try {
     	    $taskId =  $snapshot->create();
         } catch(\Exception $ex) {
     	    $message = $ex->getMessage();
+    	    syslog(LOG_NOTICE,"!!Snapshot throw Exception: " . $message );
 	    if (strpos($message,"snapshot") === false && strpos($message,"already") === false && strpos($message,"used") === false ) {
     	        throw $ex;
     	    }
         }
-
+        sleep(25);
+        $this->clean();
+	$this->sleep(5);
+	
         //save task id
         $this->putModelDataAndSave(["taskId" => $taskId, "node" => $this->vm()->getNode()]);
         
-        //sleep
-        $this->sleep(25);
-        $this->clean();
-	$this->sleep(5);
-
-	$stackTrace = implode("\n", debug_backtrace());
-	syslog(LOG_NOTICE,"Stack Trace " . $stackTrace );
+        syslog(LOG_NOTICE,"Snapshot Processing DONE" );
         return false;
     }
 
+
     /**
      * @return SnapshotJob
      */
@@ -97,9 +98,26 @@ class SnapshotVmJob extends BaseJob {
             if($toDelete <=0){
                 break;
             }
-            syslog(LOG_NOTICE,"   ->Delete Snapshot: " . $entity->getName() . " (" . $entity->getPath() . ")" );
-            $entity->delete();
+            $errorCount = 0;
+            $errorMessage = "NOT EMPTY";
+            while(!empty($errorMessage) && $errorCount < 18) { 
+        	syslog(LOG_NOTICE,"   ->Delete Snapshot: " . $entity->getName() );
+                try {
+	            $result = $entity->delete();
+	            //syslog(LOG_NOTICE,"   ->RESULT " . print_r($result,true) );
+
+	            $errorMessage = "";
+	            syslog(LOG_NOTICE,"   ->SUCCESS " . $result );
+	            sleep(45);
+        	} catch(\Exception $ex) {
+    		    $errorMessage = $ex->getMessage();
+    	    	    syslog(LOG_NOTICE,"   ->ERROR " . $errorCount . ": " . $errorMessage );
+    	    	    $errorCount ++;
+    	    	    sleep(45);
+		}
+            }
             $toDelete --;
         }
+        syslog(LOG_NOTICE,"Snapshot Clean DONE" );
     }
 }

+ 0 - 1
core/CommandLine/Application.php

@@ -52,7 +52,6 @@ class Application extends \Symfony\Component\Console\Application
         foreach ($commands as $command)
         {
             $class = ModuleConstants::getRootNamespace() . '\App\\' . $this->dir . '\\' . $command;
-
             $this->add(new $class);
         }
     }

+ 11 - 18
core/Queue/Manager.php

@@ -29,33 +29,26 @@ class Manager {
      *  snapshot name 'Snapshot_320_08_30_02' already used
      */
     public function fire(){
-        try  {
+        try {
             $this->job->setRunning();
 
             $ret    = $this->resolveAndFire($this->job->job, $this->job->data);
             if($ret !== false) {
                 $this->job->setFinished();
-            }
+            } 
         } catch(\Exception $ex) {
-    	    $message = $ex->getMessage();
-    	    if (strpos($message,"snapshot") !== false && strpos($message,"already") !== false && strpos($message,"used") !== false) {
-    		$this->job->setFinished();
-    	    
-    		//add log message
-        	$this->log->error($ex->getMessage(), debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
-    	    } else {
-        	//Set error in job
-                $this->job->setError();
-	        $this->job->setRetryAfter(date('Y-m-d H:i:s', strtotime('+ 60 seconds')));
-    	        $this->job->increaseRetryCount();
+    	    //Set error in job
+            $this->job->setError();
+	    $this->job->setRetryAfter(date('Y-m-d H:i:s', strtotime('+ 60 seconds')));
+    	    $this->job->increaseRetryCount();
 
-        	//add log message
-        	$this->log->error($ex->getMessage(), debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
-    	    }
-        
-        }
+    	    //add log message
+    	    $this->log->error($ex->getMessage(), debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
+    	}
     }
 
+
+
     /**
      * @param $job
      * @param $data