def run_async_task(self, site=None, user=None, cmd=None, form_dict=None, hijack_std=False): ret = {} frappe.init(site) frappe.connect() frappe.local.task_id = self.request.id if hijack_std: original_stdout, original_stderr = sys.stdout, sys.stderr sys.stdout, sys.stderr = get_std_streams(self.request.id) frappe.local.stdout, frappe.local.stderr = sys.stdout, sys.stderr try: set_task_status(self.request.id, "Running") frappe.db.commit() frappe.set_user(user) # sleep(60) frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, from_async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Error", response=ret) task_logger.error('Exception in running {}: {}'.format(cmd, ret['exc']))
def run_async_task(self, site, user, cmd, form_dict): ret = {} frappe.init(site) frappe.connect() sys.stdout, sys.stderr = get_std_streams(self.request.id) frappe.local.stdout, frappe.local.stderr = sys.stdout, sys.stderr frappe.local.task_id = self.request.id frappe.cache() try: set_task_status(self.request.id, "Running") frappe.db.commit() frappe.set_user(user) # sleep(60) frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() if not frappe.flags.in_test: frappe.db.commit() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Failed", response=ret) task_logger.error('Exception in running {}: {}'.format( cmd, ret['exc']))
def run_async_task(self, site, user, cmd, form_dict): ret = {} frappe.init(site) frappe.connect() sys.stdout, sys.stderr = get_std_streams(self.request.id) frappe.local.stdout, frappe.local.stderr = sys.stdout, sys.stderr frappe.local.task_id = self.request.id frappe.cache() try: set_task_status(self.request.id, "Running") frappe.db.commit() frappe.set_user(user) # sleep(60) frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, from_async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() if not frappe.flags.in_test: frappe.db.commit() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Failed", response=ret) task_logger.error('Exception in running {}: {}'.format(cmd, ret['exc']))
# sleep(60) frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, from_async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Error", response=ret) task_logger.error('Exception in running {}: {}'.format(cmd, ret['exc'])) else: set_task_status(self.request.id, "Success", response=ret) if not frappe.flags.in_test: frappe.db.commit() finally: if not frappe.flags.in_test: frappe.destroy() if hijack_std: sys.stdout.write('\n' + END_LINE) sys.stderr.write('\n' + END_LINE) sys.stdout.close() sys.stderr.close() sys.stdout, sys.stderr = original_stdout, original_stderr return ret
frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, from_async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Error", response=ret) task_logger.error('Exception in running {}: {}'.format( cmd, ret['exc'])) else: set_task_status(self.request.id, "Success", response=ret) if not frappe.flags.in_test: frappe.db.commit() finally: if not frappe.flags.in_test: frappe.destroy() if hijack_std: sys.stdout.write('\n' + END_LINE) sys.stderr.write('\n' + END_LINE) sys.stdout.close() sys.stderr.close() sys.stdout, sys.stderr = original_stdout, original_stderr return ret
# sleep(60) frappe.local.form_dict = frappe._dict(form_dict) execute_cmd(cmd, from_async=True) ret = frappe.local.response except Exception, e: frappe.db.rollback() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Failed", response=ret) task_logger.error('Exception in running {}: {}'.format(cmd, ret['exc'])) else: set_task_status(self.request.id, "Finished", response=ret) if not frappe.flags.in_test: frappe.db.commit() finally: sys.stdout.write('\n' + END_LINE) sys.stderr.write('\n' + END_LINE) if not frappe.flags.in_test: frappe.destroy() sys.stdout.close() sys.stderr.close() sys.stdout, sys.stderr = original_stdout, original_stderr return ret
ret = frappe.local.response except Exception, e: frappe.db.rollback() if not frappe.flags.in_test: frappe.db.commit() ret = frappe.local.response http_status_code = getattr(e, "http_status_code", 500) ret['status_code'] = http_status_code frappe.errprint(frappe.get_traceback()) frappe.utils.response.make_logs() set_task_status(self.request.id, "Failed", response=ret) task_logger.error('Exception in running {}: {}'.format( cmd, ret['exc'])) else: set_task_status(self.request.id, "Finished", response=ret) if not frappe.flags.in_test: frappe.db.commit() finally: sys.stdout.write('\n' + END_LINE) sys.stderr.write('\n' + END_LINE) if not frappe.flags.in_test: frappe.destroy() sys.stdout.close() sys.stderr.close() sys.stdout, sys.stderr = 1, 0 return ret @celery_task() def sendmail(site,