Skip to content

Commit

Permalink
Call CANCEL to WES when the Button is pressed in Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
lvarin committed Jun 17, 2021
1 parent c15e7c5 commit 3c17056
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
43 changes: 42 additions & 1 deletion controllers/WorkflowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use Yii;
use yii\filters\AccessControl;
use yii\httpclient\Client;
use yii\web\Controller;
use yii\web\Response;
use yii\web\UploadedFile;
Expand Down Expand Up @@ -533,9 +534,49 @@ public function actionGetLogs($jobid)
*/
public function actionCleanUp($name,$jobid,$status)
{
// Call WES to cancel
$url=Yii::$app->params['wesEndpoint'] . '/ga4gh/wes/v1/runs/' . $jobid . '/cancel';
$client = new Client();
$response = $client->createRequest()
->addHeaders(['Content-Type'=>'application/json','Accept'=>'application/json'])
->setMethod('POST')
->setUrl($url)
->send();
$statusCode=$response->getStatusCode();
if ($statusCode!=200)
{
switch($statusCode) {
case 400:
$error='Malformed request. Please contact an administrator';
break;
case 401:
$error='Request unauthorized. Please contact an administrator';
break;
case 403:
$error='Requester not authorized to perform this action. Please contact an administrator';
break;
case 404:
$error="Error 404. URL: $url, not found";
break;
case 405:
$error="The method is not allowed for the requested URL.";
break;
case 500:
$error='Error 500. Please contact an administrator';
break;
case 502:
$error='Error 502. Please contact an administrator';
break;
default:
$error='Unknown error '.$statusCode;
}
error_log("While trying: ".$url." this happened ".$error);
return;
}

$model=new Software;

// $results=$model::cleanUp($name,$jobid,$status);
$results=$model::cleanUp($name,$jobid,$status);

}

Expand Down
7 changes: 1 addition & 6 deletions models/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,7 @@ public static function runWorkflow($workflow, $newLocation, $tmpWorkflowFolder,
}
else if ($statusCode==500)
{
$error='An unexpected error occurred. Please contact an administrator';
return ['jobid'=>'','error'=>$error];
}
else if ($statusCode==500)
{
$error='Error 500. Please contact an administrator';
$error='An unexpected error occurred (500). Please contact an administrator';
return ['jobid'=>'','error'=>$error];
}
else if ($statusCode==502)
Expand Down
3 changes: 2 additions & 1 deletion web/js/workflow/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ $(document).ready(function()
{
var jobid=$("#hidden_jobid_input").val();
var name=$("#hidden_name_input").val();
// workflow/clean-up => actionCleanUp
$.ajax({
url: "index.php?r=software/clean-up",
url: "index.php?r=workflow/clean-up",
type: "GET",
data: { "jobid": jobid, "name": name, "status": "Canceled"},
dataType: "html",
Expand Down

0 comments on commit 3c17056

Please sign in to comment.