[data-migration] Make Runs observable

- Allow Runs to execute a post-process specified in Migration Plan
This commit is contained in:
Prateeksha Singh 2018-07-28 22:34:55 +05:30
parent 1922dcc87f
commit 158d324b76
2 changed files with 88 additions and 8 deletions

View file

@ -15,6 +15,7 @@
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@ -41,10 +42,12 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
"translatable": 0,
"unique": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@ -72,10 +75,12 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@ -103,6 +108,71 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "preprocess_method",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Preprocess Method",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "postprocess_method",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Postprocess Method",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}
],
@ -116,8 +186,8 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-09-13 15:47:26.336541",
"modified_by": "prateeksha@erpnext.com",
"modified": "2018-07-28 15:49:54.019073",
"modified_by": "cave@aperture.com",
"module": "Data Migration",
"name": "Data Migration Plan",
"name_case": "",
@ -125,7 +195,6 @@
"permissions": [
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 1,
"delete": 1,

View file

@ -116,12 +116,20 @@ class DataMigrationRun(Document):
push_failed = self.get_log('push_failed', [])
pull_failed = self.get_log('pull_failed', [])
if push_failed or pull_failed:
fields['status'] = 'Partial Success'
else:
fields['status'] = 'Success'
status = 'Partial Success'
if not push_failed and not pull_failed:
status = 'Success'
fields['percent_complete'] = 100
fields['status'] = status
# Execute post process
postprocess_method_path = self.get_plan().postprocess_method
frappe.get_attr(postprocess_method_path)({
"status": status
})
self.db_set(fields, notify=True, commit=True)
def get_plan(self):
@ -277,7 +285,9 @@ class DataMigrationRun(Document):
doc = mapping.get_mapped_record(doc)
try:
print("======================1==========================")
response_doc = connection.insert(mapping.remote_objectname, doc)
print("======================2==========================")
frappe.db.set_value(mapping.local_doctype, d.name,
mapping.migration_id_field, response_doc[connection.name_field],
update_modified=False)
@ -285,6 +295,7 @@ class DataMigrationRun(Document):
self.update_log('push_insert', 1)
# post process after insert
self.post_process_doc(local_doc=d, remote_doc=response_doc)
print("======================3==========================")
except Exception:
self.update_log('push_failed', d.name)