Skip to content

Commit

Permalink
Merge pull request #7 from MD-Studio/cleanup
Browse files Browse the repository at this point in the history
clean up and update db
  • Loading branch information
felipeZ authored Oct 1, 2018
2 parents 4cb3940 + 774892b commit 01d2196
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 01-10-2018

## Added
* Interface to Cerise
* Retrieve result from remote using Cerise


## Removed
* unused code

## fixed
* function complexity
* clean up in case of cerise failure

38 changes: 30 additions & 8 deletions lie_md/cerise_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import os
import six
import sys


def create_cerise_config(input_session):
Expand Down Expand Up @@ -56,17 +57,26 @@ def call_cerise_gromit(gromacs_config, cerise_config, cerise_db):
:returns: MD output file paths
:rtype: :py:dict
"""
try:
# Run Jobs
srv = create_service(cerise_config)
srv_data = yield submit_new_job(srv, gromacs_config, cerise_config)

# Register Job
register_srv_job(srv_data, cerise_db)

# Run Jobs
srv = create_service(cerise_config)
srv_data = yield submit_new_job(srv, gromacs_config, cerise_config)
sim_dict = yield extract_simulation_info(srv_data, cerise_config)
# extract results
sim_dict = yield extract_simulation_info(srv_data, cerise_config)

# register job in DB
yield register_srv_job(srv_data, cerise_db)
# register job in DB
update_srv_info_at_db(sim_dict, cerise_db)

# Shutdown Service if there are no other jobs running
yield try_to_close_service(srv_data, cerise_db)
except:
print("simulation failed due to: ", sys.exc_info()[0])
sim_dict = None
finally:
# Shutdown Service if there are no other jobs running
yield try_to_close_service(srv_data, cerise_db)

return_value(serialize_files(sim_dict))

Expand Down Expand Up @@ -272,6 +282,18 @@ def register_srv_job(srv_data, cerise_db):
print("Added service to mongoDB")


def update_srv_info_at_db(srv_data, cerise_db):
"""
Update the service-job data store in the `cerise_db`,
using the new `srv_data` information.
"""
# Do not try to update id in the db
if "_id" in srv_data:
srv_data.pop("_id")
query = {'task_id': srv_data['task_id']}
cerise_db.update_one('cerise', query, {"$set": srv_data})


def wait_for_job(job, cerise_log):
"""
Wait until job is done.
Expand Down

0 comments on commit 01d2196

Please sign in to comment.