Skip to content

Commit

Permalink
Merge pull request #177
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
leonardosahon authored Oct 17, 2024
2 parents e14faac + 0dc3338 commit f212edc
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Libs/Cron/LayCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function php_bin(): string
* @return string|bool
* @throws \Exception
*/
public static function dump_crontab(bool $suppress_win_exception = false) : string|bool
public static function dump_crontab(bool $project_scope = true, bool $suppress_win_exception = false) : string|bool
{
if(LayConfig::get_os() == "WINDOWS") {
if($suppress_win_exception)
Expand All @@ -69,7 +69,7 @@ public static function dump_crontab(bool $suppress_win_exception = false) : stri
");
}

$out = self::new()->get_crontab();
$out = self::new()->get_crontab($project_scope);

if(!$out)
return false;
Expand Down Expand Up @@ -156,7 +156,7 @@ private function project_server_jobs(string $mailto, string $cron_jobs) : string
{
$all_jobs = "";
$app_id = LayConfig::app_id();
$server_jobs = $this->get_crontab() ?? [];
$server_jobs = $this->get_crontab(false) ?? [];

foreach ($server_jobs as $i => $job) {
if(empty($job))
Expand Down Expand Up @@ -407,13 +407,31 @@ public function get_job(string|int $uid) : ?array {
];
}

public function get_crontab() : ?array
public function get_crontab(bool $project_scope = true) : ?array
{
exec("crontab -l 2>&1", $out);
exec("crontab -l 2>&1", $jobs);

if(str_contains($out[0], "no crontab for"))
if(str_contains($jobs[0], "no crontab for"))
return null;

if(!$project_scope)
return $jobs;

$out = [$jobs[0]];

$app_id = LayConfig::app_id();

foreach ($jobs as $i => $job) {
if($i == 0 && str_starts_with($job, "MAILTO"))
continue;

$job_app_id = LayFn::extract_cli_tag(self::APP_ID_KEY, true, $job);
$job_app_id = $job_app_id ? trim($job_app_id, "'") : $job_app_id;

if($app_id == $job_app_id)
$out[] = $job;
}

return $out;
}

Expand Down

0 comments on commit f212edc

Please sign in to comment.