Bozhidar Slaveykov 1 year ago
parent
commit
38b57104d6
2 changed files with 20 additions and 0 deletions
  1. 8 0
      bin/delete-cron-job.sh
  2. 12 0
      web/app/Models/CronJob.php

+ 8 - 0
bin/delete-cron-job.sh

@@ -0,0 +1,8 @@
+username=$1
+schedule=$2
+command=$3
+
+# Get the user's crontab, filter out the specific command and schedule, and install the updated crontab
+crontab -u $username -l | grep -v -F "$schedule $command" | crontab -u $username -
+
+echo "done!"

+ 12 - 0
web/app/Models/CronJob.php

@@ -33,6 +33,18 @@ class CronJob extends Model
                 return false;
             }
         });
+
+        static::deleting(function ($model) {
+
+            $args = escapeshellarg($model->user) .' '. escapeshellarg($model->schedule) . ' ' . escapeshellarg($model->command);
+            $args = str_replace(PHP_EOL, '', $args);
+            $command = '/usr/local/phyre/bin/delete-cron-job.sh ' . $args;
+            $deleteCron = shell_exec($command);
+            if (empty($deleteCron)) {
+                return false;
+            }
+
+        });
     }
 
 //    protected function sushiShouldCache()