Commit ebc7ecb9 authored by Dillenn Terumalai's avatar Dillenn Terumalai
Browse files

fix: Fixed bug #1 and #2

parent 25773229
Pipeline #2646 passed with stage
in 10 seconds
......@@ -12,6 +12,7 @@ use Dterumal\LaravelCluster\Events\JobCompleted;
use Dterumal\LaravelCluster\Events\JobFailed;
use Dterumal\LaravelCluster\Events\JobQueued;
use Dterumal\LaravelCluster\Storage\JobModel;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Symfony\Component\Process\Exception\ProcessFailedException;
......@@ -70,9 +71,12 @@ class SlurmConnector implements ClusterInterface
case 'CANCELLED':
$event = 'cancelled_at';
break;
case 'FAILED' || 'TIMEOUT' || 'DEADLINE' || 'REVOKED':
case 'FAILED':
$event = 'failed_at';
break;
case 'TIMEOUT':
$event = 'timed_out_at';
break;
default:
$event = null;
break;
......@@ -96,12 +100,14 @@ class SlurmConnector implements ClusterInterface
$collection->each(function ($job) {
$clusterJob = JobModel::findOrFail($job['id']);
event(new JobQueued($clusterJob, $job['queued_at']));
if ($job['event'] === 'completed_at') {
event(new JobCompleted($clusterJob, $job['datetime']));
} elseif ($job['event'] === 'failed_at') {
event(new JobFailed($clusterJob, $job['datetime']));
} elseif ($job['event'] === 'cancelled_at') {
event(new JobCancelled($clusterJob, $job['datetime']));
if (array_key_exists('event', $job)) {
if ($job['event'] === 'completed_at') {
event(new JobCompleted($clusterJob, $job['datetime']));
} elseif ($job['event'] === 'failed_at') {
event(new JobFailed($clusterJob, $job['datetime']));
} elseif ($job['event'] === 'cancelled_at') {
event(new JobCancelled($clusterJob, $job['datetime']));
}
}
});
}
......@@ -212,6 +218,8 @@ class SlurmConnector implements ClusterInterface
*/
public function run($job): void
{
$job->created_at = Carbon::now();
// We format the array of commands to a string with newlines between commands
$content = implode("\n", $job->handle());
......@@ -239,7 +247,7 @@ EOF",
$sudoUser = config('laravel-cluster.connections.slurm.sudo_account');
if(!is_null($sudoUser)) {
if (!is_null($sudoUser)) {
$process = Process::fromShellCommandline("sudo -u $sudoUser sbatch --chdir=/tmp --parsable $payload");
} else {
$process = Process::fromShellCommandline("sbatch --chdir=/tmp --parsable $payload");
......@@ -259,13 +267,14 @@ EOF",
/**
* @inheritDoc
*/
public function monitorStatus(): void {
public function monitorStatus(): void
{
$output = $this->execute([
'scontrol',
'ping'
], fn() => '');
if(Str::of($output)->contains('UP')) {
if (Str::of($output)->contains('UP')) {
event(new ClusterUpDetected());
} else {
event(new ClusterDownDetected());
......
......@@ -30,7 +30,7 @@ class DatabaseJobRepository implements JobRepository
'std_out_path' => "{$job->exportPath}/{$job->name}_{$job->id}.out",
'std_err_path' => "{$job->exportPath}/{$job->name}_{$job->id}.err",
'export_path' => $job->exportPath,
'created_at' => Carbon::now()
'created_at' => $job->created_at
]);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment