Example #1
0
    def handle(self,  *args, **options):

        # 最后一个参数设置为1,也就是缺省用户tao的整数id

        import_csv_card_all(options['site'],
                            options['all_file'],
                            options['card_file'],
                            options['location_name'],
                            options['location_desc'],
                            1,
                            'tao')
Example #2
0
    def do_job(self, job_data):
        try:
            args = json.loads(job_data)

            with open(args["log_file"], "at") as lf:
                lf.write("===new task===\n[%s]start import site:%s's data...\n" % (NowTime(), args["site"]))
                lf.close()

            # import
            start_date, end_date = import_csv_card_all(
                args["site"],
                args["all_file"],
                args["card_file"],
                args["location"],
                args["location_desc"],
                args["userid"],
                args["username"],
                args["station_id"],
            )

            with open(args["log_file"], "at") as lf:
                lf.write("[%s]end import site:%s's data...\n" % (NowTime(), args["site"]))
                lf.close()

            # need update station info?
            if args["need_update_station_info"]:
                with open(args["log_file"], "at") as lf:
                    lf.write("[%s]start update site:%s info...\n" % (NowTime(), args["site"]))
                    lf.close()

                nb_guns = get_nb_guns_of_station(args["site"])
                guns_id = get_guns_id_by_site(args["site"])
                update_station_info(
                    args["site"],
                    args["site_desc"],
                    args["locid"],
                    nb_guns,
                    None,  # phone
                    None,  # address
                    None,  # brand
                    None,  # distance
                    guns_id,
                )

                with open(args["log_file"], "at") as lf:
                    lf.write("[%s]end update site:%s info...\n" % (NowTime(), args["site"]))
                    lf.close()

            # 计算相关性
            with open(args["log_file"], "at") as lf:
                lf.write("[%s]start compute assoc on site:%s...\n" % (NowTime(), args["site"]))
                lf.close()

            call_command("compute_item_assoc", interactive=False, period=0, site=args["site"])
            call_command("compute_item_assoc", interactive=False, period=1, site=args["site"])
            call_command("compute_item_assoc", interactive=False, period=2, site=args["site"])
            call_command("compute_item_assoc", interactive=False, period=3, site=args["site"])

            with open(args["log_file"], "at") as lf:
                lf.write("[%s]%s\n" % (NowTime(), args["import_flag_string"]))
                lf.write("[%s]end compute assoc on site:%s...\n===finish task===\n" % (NowTime(), args["site"]))
                lf.close()

            # 离线计算油品每天销售
            args["start_date"] = start_date.strftime("%Y-%m-%d")
            args["end_date"] = end_date.strftime("%Y-%m-%d")
            call_command("gearman_submit_job", "compute_fuel_daybatch", json.dumps(args), foreground=False)
            call_command("gearman_submit_job", "compute_station_daybatch", json.dumps(args), foreground=False)
        except Exception, e:
            with open(args["log_file"], "at") as lf:
                lf.write("[%s]%s\n" % (NowTime(), args["import_flag_string"]))
                lf.write("[%s]handle task error:%s\n===finish task===\n" % (NowTime(), str(e)))
                lf.close()
            gearman_logger.error("gearman error: " + str(e))
            gearman_logger.error("stack:" + exception_stuck())