Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update processing to be more general #26

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions examples/local-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ def process_task(self, token):
print(key, value)
print("-----------------------")

# Start running the main job
# /usr/bin/time -v ./process_task.sh [input] [tokenid] 2> logs_[token_id].err 1> logs_[token_id].out
command = "/usr/bin/time -v ./process_task.sh " + "\"" +token['input'] + "\" " + token['_id'] + " 2> logs_" + str(token['_id']) + ".err 1> logs_" + str(token['_id']) + ".out"
# Start running the main job, the logging is done internally and saved below
# /usr/bin/time -v ./process_task.sh [input] [tokenid]
command = ["/usr/bin/time", "-v", "./process_task.sh", token['input'], token['_id']]
out = execute(command)

logsout = f"logs_{token['_id']}.out"
logserr = f"logs_{token['_id']}.err"

# write the logs
with open(logsout, 'w') as f:
f.write(out[2].decode('utf-8'))
with open(logserr, 'w') as f:
f.write(out[3].decode('utf-8'))

out = execute(command, shell=True)
self.subprocess = out[0]

# Get the job exit code and done in the token
Expand All @@ -61,11 +70,9 @@ def process_task(self, token):
# Attach logs in token
curdate = time.strftime("%d/%m/%Y_%H:%M:%S_")
try:
logsout = "logs_" + str(token['_id']) + ".out"
log_handle = open(logsout, 'rb')
token.put_attachment(logsout, log_handle.read())

logserr = "logs_" + str(token['_id']) + ".err"
log_handle = open(logserr, 'rb')
token.put_attachment(logserr, log_handle.read())
except:
Expand Down
2 changes: 1 addition & 1 deletion examples/process_task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo $TOKENID
echo $OUTPUT

#Start processing
eval $INPUT
bash -c "$INPUT"
if [[ "$?" != "0" ]]; then
echo "Program interrupted. Exit now..."
exit 1
Expand Down