Skip to content

Commit

Permalink
LIMS-1302 - add visit to container even if UAS fails (#762)
Browse files Browse the repository at this point in the history
* LIMS-1302: Add session to container even if UAS says session not found

* LIMS-1302: Only log errors from UAS, not successes

* LIMS-1302: Convert tabs to spaces

---------

Co-authored-by: Mark Williams <[email protected]>
  • Loading branch information
ndg63276 and Mark Williams authored Dec 16, 2024
1 parent b33e254 commit c373c3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
10 changes: 4 additions & 6 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,8 @@ function _update_autocollect_session($sessionId, $uasSessionId, $containerId, $t
$uas = new UAS($auto_user, $auto_pass);
$code = $uas->update_session($uasSessionId, $data);

if ($code == 200) {
// Update ISPyB records
if ($code == 200 || $code == 404) {
// Update ISPyB records, even if UAS says session not found
$this->db->pq("UPDATE container SET sessionid=:1 WHERE containerid=:2", array($sessionId, $containerId));
// For debugging - actually just want to return Success!
$result = array(
Expand All @@ -1216,13 +1216,11 @@ function _update_autocollect_session($sessionId, $uasSessionId, $containerId, $t
);
} else if ($code == 403) {
$this->_error('UAS Error - samples and/or investigators not valid. ISPyB/UAS Session ID: ' . $sessionId . ' / ' . $uasSessionId);
} else if ($code == 404) {
$this->_error('UAS Error - session not found in UAS, Session ID: ' . $sessionId . ' UAS Session ID: ' . $uasSessionId);
} else {
$this->_error('UAS Error - something wrong creating a session for that container ' . $containerId . ', response code was: ' . $code);
$this->_error('UAS Error - something went wrong updating a session for that container ' . $containerId . ', response code was: ' . $code);
}
} else {
error_log("Something wrong - an Auto Collect session exists but with no containers " . $sessionId);
error_log("Something went wrong - an Auto Collect session exists but with no containers " . $sessionId);

$this->_error('No valid containers on the existing Auto Collect Session id:', $sessionId);
}
Expand Down
56 changes: 28 additions & 28 deletions api/src/UAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
class UAS
{

function __construct($user=null, $pass=null) {
global $uas_url, $vmxi_user, $vmxi_pass;
function __construct($user=null, $pass=null) {
global $uas_url, $vmxi_user, $vmxi_pass;

$this->url = $uas_url;
$this->url = $uas_url;

$cas = new CAS();

Expand All @@ -33,12 +33,12 @@ function __construct($user=null, $pass=null) {
}

// print_r(array('sess', $this->session));
}
}



function create_session($data=array()) {
$resp = $this->_curl(array(
function create_session($data=array()) {
$resp = $this->_curl(array(
'URL' => $this->url.'/uas/rest/v1/session',
'FIELDS' => $data,
'HEADERS' => array(
Expand All @@ -48,21 +48,21 @@ function create_session($data=array()) {
),
));

// print_r(array($resp));
// print_r(array($resp));

if ($this->code == 200) {
$resp = json_decode($resp);
} else {
$resp = json_decode($resp);
} else {
error_log("UAS::create_session error from UAS, code: " . $this->code);
error_log(print_r($resp), true);
}

return array('code' => $this->code, 'resp' => $resp);
}
return array('code' => $this->code, 'resp' => $resp);
}


function update_session($sessionid, $data=array()) {
$resp = $this->_curl(array(
function update_session($sessionid, $data=array()) {
$resp = $this->_curl(array(
'URL' => $this->url.'/uas/rest/v1/session/'.$sessionid,
'FIELDS' => $data,
'PATCH' => 1,
Expand All @@ -73,19 +73,19 @@ function update_session($sessionid, $data=array()) {
),
));

if ($this->code == 200) {
if ($this->code != 200) {
error_log("UAS::update_session error from UAS, code: " . $this->code);
error_log(print_r($resp), true);
}

// print_r(array($resp));
// print_r(array($resp));

return $this->code;
}
return $this->code;
}

function close_session($sessionid, $data = array()) {
function close_session($sessionid, $data = array()) {
$data['endAt'] = date('Y-m-d\TH:i:s.000\Z');
$resp = $this->_curl(array(
$resp = $this->_curl(array(
'URL' => $this->url.'/uas/rest/v1/session/'.$sessionid,
'FIELDS' => $data,
'PATCH' => 1,
Expand All @@ -96,11 +96,11 @@ function close_session($sessionid, $data = array()) {
),
));

return $this->code;
}
return $this->code;
}

function get_sessions() {
$resp = $this->_curl(array(
function get_sessions() {
$resp = $this->_curl(array(
'URL' => $this->url.'/uas/rest/v1/proposal?state=OPEN&fetch=samples&fetch=investigators',
'GET' => 1,
'HEADERS' => array(
Expand All @@ -110,12 +110,12 @@ function get_sessions() {
),
));

if ($this->code == 200) {
$resp = json_decode($resp);
}
if ($this->code == 200) {
$resp = json_decode($resp);
}

return array('code' => $this->code, 'resp' => $resp);
}
return array('code' => $this->code, 'resp' => $resp);
}



Expand Down

0 comments on commit c373c3c

Please sign in to comment.