Skip to content

Commit

Permalink
Merge pull request #96 from marcin-magemojo/master
Browse files Browse the repository at this point in the history
Fix for Issues #95 & #67
  • Loading branch information
gnuzealot authored Jun 12, 2020
2 parents 1ffa886 + 264b77a commit d678cbc
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getConfig() {
foreach($this->cronconfig->getJobs() as $groupname=>$group) {
$override = $this->resource->getConfigValue('system/cron/'.$groupname.'/schedule_generate_every',0,'default');
if ($override) {
$scheduleoverrides[$groupname] = $override;
$scheduleoverrides[$groupname] = '*/'.$override;
}
foreach($group as $name=>$job) {
if (!is_array($job)) continue;
Expand Down Expand Up @@ -351,15 +351,17 @@ public function execute() {
/**
* Get an individual configuration for a job_code
*
* @return array
* @return array|false
*/
public function getJobConfig($jobname) {
#if a consumers job get default consumers runner config
if (strpos($jobname,"mm_consumer") > -1) {
$job = $this->config["consumers_runner"];
$job["name"] = $jobname;
} else {
} elseif (isset($this->config[$jobname])) {
$job = $this->config[$jobname];
} else {
$job = false;
}
return $job;
}
Expand All @@ -370,12 +372,15 @@ public function getJobConfig($jobname) {
* @return string
*/
public function prepareStub($jobconfig, $stub, $scheduleid) {
if (!isset($jobconfig["instance"]) || !class_exists($jobconfig["instance"]) || !isset($jobconfig["method"])) {
return false;
}
$code = trim($stub);
$code = str_replace('<<basedir>>',$this->basedir,$code);
$code = str_replace('<<method>>',$jobconfig["method"],$code);
$code = str_replace('<<instance>>',$jobconfig["instance"],$code);
$code = str_replace('<<scheduleid>>',$scheduleid,$code);
$code = str_replace('<<name>>',$jobconfig["name"],$code);
$code = str_replace('<<name>>',$jobconfig["name"]??'',$code);
return $code;
}

Expand Down Expand Up @@ -502,8 +507,11 @@ public function service() {
$runcheck = $this->resource->getJobByStatus($job["job_code"],'running');
if (count($runcheck) == 0) {
$jobconfig = $this->getJobConfig($job["job_code"]);
if ($jobconfig == false) {
continue;
}
#if this is a consumers job use a different runtime cmd
if ($jobconfig["consumers"]) {
if (isset($jobconfig["consumers"])) {
$consumerName = str_replace("mm_consumer_","",$jobconfig["name"]);
$runtime = "bin/magento queue:consumers:start " . escapeshellarg($consumerName);
if ($maxConsumerMessages) {
Expand All @@ -516,7 +524,9 @@ public function service() {
$cmd = $runtime;
} else {
$runtime = $this->prepareStub($jobconfig,$stub,$job["schedule_id"]);
$cmd = escapeshellcmd($this->phpproc)." -r ".escapeshellarg($runtime);
if ($runtime) {
$cmd = escapeshellcmd($this->phpproc) . " -r " . escapeshellarg($runtime);
}
}
$exec = sprintf("%s; %s &> %s & echo $!",
'cd ' . escapeshellarg($this->basedir),
Expand Down Expand Up @@ -558,7 +568,9 @@ public function executeImmediate($jobname) {

$this->getConfig();
$jobconfig = $this->getJobConfig($jobname);

if ($jobconfig === false ) {
return;
}
#create a schedule
$schedule = array('scheduled_at' => time());
$scheduled = $this->resource->saveSchedule($jobconfig, time(), $schedule);
Expand Down

0 comments on commit d678cbc

Please sign in to comment.