Skip to content

Commit

Permalink
Merge pull request #376 from moka-guys/smartsheet_update
Browse files Browse the repository at this point in the history
Smartsheet update
  • Loading branch information
preciserobot authored Feb 18, 2022
2 parents 287a728 + 47a7988 commit 18877a2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
2 changes: 1 addition & 1 deletion automate_demultiplex_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

# Set debug mode
testing = False
testing = True

# =====location of input/output files=====
# root of folder that contains the apps, automate_demultiplexing_logfiles and
Expand Down
48 changes: 30 additions & 18 deletions demultiplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(self, now):
# Requests info
self.headers = config.smartsheet_request_headers
self.url = config.smartsheet_request_url

# variables to hold checksums:
self.sequencer_checksum = ""
self.workstation_checksum = ""
Expand Down Expand Up @@ -527,33 +527,45 @@ def smartsheet_demultiplex_in_progress(self):
', "value": "Demultiplex"}, {"columnId": ' + self.ss_samples + ', "value": ' + str(self.sample_count) + '},{"columnId": ' + self.ss_status + \
', "value": "In Progress"},{"columnId": ' + self.ss_priority + ', "value": "Medium"},{"columnId": ' + self.ss_assigned + \
', "value": "aledjones@nhs.net"},{"columnId": ' + self.ss_received + ', "value": "' + str(self.smartsheet_started) + '"}],"toBottom":true}'

# Create url for uploading a new row
url = self.url + "/rows"

# Add the row using POST
r = requests.post(url, headers=self.headers, data=payload)
# capture the output of the POST statement to capture the id of the row that has been updated.
# This can be used when updating the status to complete in function smartsheet_demultiplex_complete().
response = r.json()
# capture the value of the row id from the json response
self.rowid = response["result"]["id"]

# Use response.get("") instead of response[""] to avoid KeyError if "message" missing.
if response.get("message") == "SUCCESS":
# Report to system log file
self.logger("Smartsheet updated with initiation of demultiplexing for run " + self.runfolder, "smartsheet_pass")
#Add try statement to stop script from failing
try:
r = requests.post(url, headers=self.headers, data=payload)
# capture the output of the POST statement to capture the id of the row that has been updated.
# This can be used when updating the status to complete in function smartsheet_demultiplex_complete().
response = r.json()
except:
self.script_logfile.write("Unable to connect to SmartSheet API. Check payload and URL\n")
self.logger("Unable to connect to SmartSheet API for run " + self.runfolder, "Check payload and URL")
return False
else:
# Record error message to script log file
self.script_logfile.write("smartsheet NOT updated at in progress step\n" + str(response))
# Record failure in system logs so that an error can be reported via slack.
# Failure to update smartsheet is not critical as it does not stop the run being processed.
self.logger("Smartsheet was NOT updated to say demultiplexing is in progress for run " + self.runfolder, "smartsheet_fail")
# capture the value of the row id from the json response
self.rowid = response["result"]["id"]
# Use response.get("") instead of response[""] to avoid KeyError if "message" missing.
if response.get("message") == "SUCCESS":
# Report to system log file
self.logger("Smartsheet updated with initiation of demultiplexing for run " + self.runfolder, "smartsheet_pass")
else:
# Record error message to script log file
self.script_logfile.write("smartsheet NOT updated at in progress step\n" + str(response))
# Record failure in system logs so that an error can be reported via slack.
# Failure to update smartsheet is not critical as it does not stop the run being processed.
self.logger("Smartsheet was NOT updated to say demultiplexing is in progress for run " + self.runfolder, "smartsheet_fail")

def smartsheet_demultiplex_complete(self):
"""Update smartsheet to say demultiplexing is complete.
Add the completed date and calculate the duration (in days) and if met TAT.
"""
try:
assert self.rowid
except AssertionError:
self.script_logfile.write("No rowid available to update API. RowID not added\n")
self.logger("No rowid available to update API " + self.runfolder, "RowID not added")
return

# assign current timestamp to self.smartsheet_complete
self.smartsheet_complete = '{:%Y-%m-%d}'.format(datetime.datetime.now())

Expand Down
41 changes: 22 additions & 19 deletions upload_and_setoff_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def quarterback(self):
# if not TSO500 will return None
if TSO500_sample_list:
# tar runfolder
self.tar_runfolder()
#self.tar_runfolder()
# set list of samplenames as list of processed samples - this will allow the project to be named properly.
# set tar folder path in place of the list of fastqs to upload
self.list_of_processed_samples, self.fastq_string = TSO500_sample_list, self.runfolder_obj.runfolder_tarball_path + " " + self.runfolder_obj.runfolder_samplesheet_path
Expand Down Expand Up @@ -2146,26 +2146,29 @@ def smartsheet_workflows_commands_sent(self):

# create url for uploading a new row
url = self.smartsheet_url + "/rows"

# add the row using POST
r = requests.post(url, headers=self.headers, data=payload)

# capture the row id
response = r.json()

try:
# add the row using POST
r = requests.post(url, headers=self.headers, data=payload)
# capture the row id
response = r.json()
except:
self.script_logfile.write("Unable to connect to API. Check payload and URL\n")
self.logger("Unable to connect to smartsheet API for run " + self.runfolder + ". Check payload and url")
return False
else:
# check the result of the update attempt
for line_key in response:
if line_key == "message":
if response[line_key] == "SUCCESS":
self.loggers.script.info(
"smartsheet_pass 'smartsheet updated to say in progress'"
)
else:
self.loggers.script.error(
"smartsheet_fail 'run started NOT added to smartsheet for run {}'".format(
self.runfolder_obj.runfolder_name
for line_key in response:
if line_key == "message":
if response[line_key] == "SUCCESS":
self.loggers.script.info(
"smartsheet_pass 'smartsheet updated to say in progress'"
)
else:
self.loggers.script.error(
"smartsheet_fail 'run started NOT added to smartsheet for run {}'".format(
self.runfolder_obj.runfolder_name
)
)
)

def write_opms_queries_custom_panel(self, list_of_processed_samples):
"""
Expand Down

0 comments on commit 18877a2

Please sign in to comment.