Example #1
0
    if result is False:
        print("register login task fail")
        return
    print("start run login task %s" % info["task_no"])
    result, info = control.get_login_info()
    table_content = ""
    if len(info["login_records"]) <= 0:
        print("No Login Records")
        return
    for item in info["login_records"]:
        tr_content = '<tr>'
        tr_content += '<td>%s</td>\n' % ip_str(item["server_ip"]) # unix_timestamp(item["run_begin"])
        tr_content += '<td>%s</td>\n' % item["server_name"]
        tr_content += '<td>%s</td>' % ip_str(item["user_ip"])
        tr_content += '<td>%s</td>\n' % item["user_name"]
        tr_content += '<td>%s</td>\n' % unix_timestamp(item["login_time"], style="datetime")
        tr_content += '</tr>\n'
        table_content += tr_content
    with open("../Web/templates/LOG/Login_Log.html") as rt:
        content = rt.read()
        content = content.replace("{{ TR }}", table_content.encode("utf-8"))
        subject = u"有用户登录到服务器"
        my_email.send_mail("*****@*****.**", subject, content)
    print("send success")


if current_env == "Production" or current_env == "Development":
    dms_job.append({"func": "%s:send_log_func" % __name__, "trigger": "cron", "id": "send_daily_log", "hour": 8, "minute": "30"})
    dms_job.append({"func": "%s:send_login_info_func" % __name__, "trigger": "cron", "id": "send_login_info", "hour": "9-17", "minute": "5"})

Example #2
0
def backup_table_func():
    t_name = request.json["t_name"]
    sql_path = "%s/%s.sql.backup" % (backup_dir, t_name)
    result, info = control.backup_table(g.user_name, g.user_role, t_name, sql_path)
    return jsonify({"status": result, "data": info})


# 每天0:30,备份线上数据表。
def backup_func():
    if current_env != "Production":
        print("Not Production")
        return
    result, info = control.register_backup_task()
    if result is False:
        print("register backup fail")
        return
    print("start run backup table task %s" % info["task_no"])
    allow_t = ["collect_variant", "health_examination_result", "health_examination_result_v3", "health_gift_result",
               "health_gift_result_v3", "health_report_survey", "health_survey_report", "health_survey_result",
               "log_project", "patient_info", "patient_test", "project_user_right", "sample_group", "sample_info",
               "sample_phenotype", "sample_report", "sample_user_right", "sys_patients", "sys_project_sample",
               "sys_projects", "sys_samples", "sys_users", "target_ratio_detail", "task_collect_variant", "test_value",
               "user_config", "user_geneset", "user_info", "user_task_list", "user_template", "variant_data_nums",
               "variant_data_pic", "variant_md5", "variant_remark"]
    for t_name in allow_t:
        sql_path = "%s/%s_%s.sql.backup" % (backup_dir, current_env, t_name)
        control.backup_table("system", 0, t_name, sql_path)
    print("backup success")

dms_job.append({"func": "%s:backup_func" % __name__, "trigger": "cron", "id": "backup_table", "day_of_week": "0-4", "hour": 0, "minute": 30})