from fireworks import LaunchPad
lp = LaunchPad( host='localhost',
port=27018,
name='fireworks-jhoermann',
username='fireworks',
password='fireworks' )
import sys
sys.version
import os
from monty.serialization import loadfn
from monty.os.path import zpath
from fireworks.utilities.fw_serializers import reconstitute_dates
from datetime import datetime
import tempfile
launch_id = 12392
m_launch = lp.get_launch_by_id(launch_id)
ping_loc = os.path.join(m_launch.launch_dir, "FW_ping.json")
ping_loc
with tempfile.NamedTemporaryFile(mode='w+',suffix='.json') as f:
f.write('{"ping_time": "2019-07-28T12:54:43.213215"}')
f.seek(0)
ping_dict = loadfn(f.name)
ping_dict
type(ping_dict['ping_time'])
ptime = ping_dict['ping_time']
update_time = ptime
update_time = update_time or datetime.utcnow()
update_time
type(update_time)
m_launch.state_history
m_launch.touch_history(ptime,checkpoint=None)
m_launch.state_history
m_launch.to_db_dict()['state_history']
lp.launches.update_one(
{'launch_id': launch_id, 'state': 'RUNNING'},
{'$set': {
'state_history': m_launch.to_db_dict()['state_history'],
'trackers': [t.to_dict() for t in m_launch.trackers]}
}
)
offline_loc = zpath(os.path.join(m_launch.launch_dir,
"FW_offline.json"))
offline_loc
with tempfile.NamedTemporaryFile(mode='w+',suffix='.json') as f:
f.write('{"launch_id": 12392, "started_on": "2019-07-24T12:54:41.031150", "checkpoint": {"_task_n": 0, "_all_stored_data": {}, "_all_update_spec": {}, "_all_mod_spec": []}}')
f.seek(0)
offline_data = loadfn(f.name)
offline_data
m_launch.state = 'RUNNING'
for s in m_launch.state_history:
if s['state'] == 'RUNNING':
s['created_on'] = reconstitute_dates(offline_data['started_on'])
m_launch.state_history
l = lp.launches.find_one_and_replace({'launch_id': m_launch.launch_id},
m_launch.to_db_dict(), upsert=True)
fw_id = l['fw_id']
fw_id
f = lp.fireworks.find_one_and_update(
{'fw_id': fw_id},
{'$set':
{'state': 'RUNNING',
'updated_on': datetime.utcnow()
}
}
)
lp._refresh_wf(fw_id)
m_launch.touch_history(checkpoint=offline_data['checkpoint'])
m_launch.state_history
lp.launches.find_one_and_replace(
{'launch_id': m_launch.launch_id},
m_launch.to_db_dict(), upsert=True)