Exemplo n.º 1
0
    def __init__(self, request):
        cur = Currency(request)
        data = cur.rq_post_json('data')
        self.dtconn = dataconn.DatabaseConnection(logger)
        self.jd = BatchJobData(data)

        self.error_msg = []
        self.result = self._SUCCESS
Exemplo n.º 2
0
def get_update_job_data(request):
    # 获取 更新任务数据
    response = HttpResponse()
    cur = Currency(request)
    _id = cur.rq_post_json('_id')
    jd = JobData({})
    response.write(json.dumps(jd.get_job_data_by_id(_id)))
    return response
Exemplo n.º 3
0
def get_batch_job_instance_data_by_id(request):
    # 根据ID获取批处理作业数据
    cur = Currency(request)
    batch_job_instance_id = cur.rq_post('instance_id')
    bjid = BatchJobInstanceData({})
    data = bjid.get_batch_job_instance_by_id(batch_job_instance_id)
    response = HttpResponse()
    response.write(json.dumps(data))
    return response
Exemplo n.º 4
0
def run_job(request):
    # 执行任务
    response = HttpResponse()
    cur = Currency(request)
    data = cur.rq_post_json('data')
    # run(**data)
    run.delay(**data)
    response.write(json.dumps(_SUCCESS))
    return response
Exemplo n.º 5
0
def check_permission(request):
    # 检测用户权限
    nowuser = auth.get_user(request)
    cur = Currency(request)
    permission = cur.rq_post('permission')
    status = 0 if nowuser.has_perm(permission) else 1
    response = HttpResponse()
    response.write(json.dumps({'status': status}))
    return response
Exemplo n.º 6
0
def get_batch_job_sub_job_instance_data_by_id(request):
    # 根据ID获取批处理作业数据
    cur = Currency(request)
    batch_job_instance_id = cur.rq_get('instance_id')
    # if _type == 1: 数据同步类型为1
    data = BatchJobSubjobInstanceData.get_sub_job_datax_instance_data_by_id(
        batch_job_instance_id)
    response = HttpResponse()
    response.write(json.dumps(data))
    return response
Exemplo n.º 7
0
def get_datax_job_instance_by_id(request):
    # 根据ID查询任务实例
    cur = Currency(request)
    _id = cur.rq_post('_id')
    conn = dataconn.DatabaseConnection(logger)
    dtf = dataconn.DataTransform()
    sql = config.select_datax_job_instance_by_id_sql % _id
    source_data = conn.ygol.getsingle(sql)
    response = HttpResponse()
    response.write(json.dumps(dtf.get_row_by_dict_to_user(source_data)))
    return response
Exemplo n.º 8
0
def add_job_data(request):
    # 新增或者修改任务数据
    response = HttpResponse()
    cur = Currency(request)
    data = cur.rq_post_json('data')
    jd = JobData(data)

    if jd.operation_type == config.OPERATION_TYPE[0]:
        result = jd.create()  # 新增
    else:
        result = jd.update()  # 更新
    response.write(json.dumps(result))
    return response
Exemplo n.º 9
0
    def __init__(self, request):
        """
        RESPONSE_TYPE 返回给用户数据的方式
        1:20万行以内的数据,以excel方式返回
        2:超过20万行的数据,需要分批处理
        3:小量的数据以HTML表格的方式返回'
        """
        cur = Currency(request)
        data = cur.rq_post_json('data')
        self.dtconn = dataconn.DatabaseConnection(logger)
        self.jd = JobData(data)

        self.error_msg = []
        self.result = self._SUCCESS
Exemplo n.º 10
0
def get_batch_job_data_by_id(request):
    """
    根据ID获取批处理作业数据
    :param request: id
    :return:
    """
    cur = Currency(request)
    _id = cur.rq_post('_id')
    sql = config.query_batch_job_sql3 % _id
    dtconn = dataconn.DatabaseConnection(logger)
    dtsf = dataconn.DataTransform()
    source_data = dtconn.ygol.getsingle(sql)
    response = HttpResponse()
    response.write(json.dumps(dtsf.get_row_by_dict_to_user(source_data)))
    return response
Exemplo n.º 11
0
def add_batch_job_data(request):
    # 新增或者修改任务数据
    response = HttpResponse()
    cur = Currency(request)
    data = cur.rq_post_json('data')
    jd = BatchJobData(data)

    if jd.operation_type == _OPERATION_TYPE[0]:
        result = jd.create()  # 新批处理作业
        jd.create_PeriodicTask()  # 创建定时任务
    else:
        result = jd.update()
        jd.update_PeriodicTask()
    response.write(json.dumps(result))
    return response
Exemplo n.º 12
0
    def __init__(self, request):
        self.cur = Currency(request)
        self.rq_get = self.cur.rq_get

        self._offset = int(self.rq_get('offset'))
        self._limit = int(self.rq_get('limit'))
        self._SQL = config.select_datax_job_instance_sql
        self._TOTAL_SQL = config.count_datax_job_instance_sql
        self._set_table(self._table_dji)
Exemplo n.º 13
0
def test_periodic_task_mod(request):
    # 测试  修改周期任务 数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)
    test_mail(**data)
    response.write(json.dumps({'status': 0, 'msg': ['操作成功']}))
    return response
Exemplo n.º 14
0
def delete_crontab(request):
    # 删除 crontab 定时时间 数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)
    _id = data.get('id', '')
    CrontabSchedule.objects.get(pk=int(_id)).delete()
    response.write(json.dumps(''))
    return response
Exemplo n.º 15
0
def get_mod_crontab_data(request):
    # 获取 需要修改的 crontab 定时时间 数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    _id = rq_post('id')
    fields = ['minute', 'hour', 'day_of_week', 'day_of_month', 'month_of_year']
    crontabs_obj = CrontabSchedule.objects.get(pk=int(_id))
    crontabs_stf = [getattr(crontabs_obj, f) for f in fields]
    response.write(json.dumps(dict(zip(fields, crontabs_stf))))
    return response
Exemplo n.º 16
0
def delete_periodic_task(request):
    # 测试  修改周期任务 数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)
    _id = data.get('_id', '')
    PeriodicTask.objects.get(pk=int(_id)).delete()
    response.write(json.dumps({'status': 0, 'msg': ['操作成功']}))
    return response
Exemplo n.º 17
0
def test_periodic_task_result(request):
    # 获取 测试  新增周期任务 结果
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    _random = rq_post('_random')
    _r = redis.Redis(host=host2, port=port2, db=db2)

    msg = [_r.rpop(_random) for i in xrange(_r.llen(_random))]
    response.write(json.dumps({'msg': msg}))
    return response
Exemplo n.º 18
0
def run_batch_job_task(request):
    # 执行批处理作业
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)
    # run_batch_job(**data)
    run_batch_job.delay(**data)
    response.write(json.dumps({'status': 0, 'msg': u'操作成功'}))
    return response
Exemplo n.º 19
0
def get_batch_job_sub_job_by_id(request):
    """
    根据ID获取批处理作业中的子作业数据

    扩展:
         目前子作业只包含数据同步,后期加入了SQL脚本、SQL备份等等之后,
         需要先判断子作业的类型,再根据类型去相关表里查询子作业的详细信息。
         例如:如果有同步类型的子作业,就需要根据同步作业表查询同步的任务详情。
              如果有备份类型的,就去备份表里查询备份任务详情。
    :param request: id
    :return:
    """
    cur = Currency(request)
    _id = cur.rq_post('_id')
    sql = config.query_batch_job_sub_job_by_id_sql % _id
    dtconn = dataconn.DatabaseConnection(logger)
    dtsf = dataconn.DataTransform()
    source_data = dtconn.ygol.getall(sql)
    data = [dtsf.get_row_by_dict_to_user(dt) for dt in source_data]
    response = HttpResponse()
    response.write(json.dumps(data))
    return response
Exemplo n.º 20
0
def add_crontab(request):
    # 新增 crontab 定时时间
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)
    ndata = dict([(k, v.replace(' ', ''))
                  for k, v in data.items()])  # Remove all spaces
    crobj = schedules.crontab(**ndata)
    to_model_schedule = ModelEntry.to_model_schedule
    model_schedule, model_field = to_model_schedule(crobj)
    response.write(json.dumps(ndata))
    return response
Exemplo n.º 21
0
 def __init__(self, request):
     cur = Currency(request)
     rq_post = getattr(cur, 'rq_post')
     jdata = rq_post('data')
     data = json.loads(jdata)
     self.data = data
     self.error_msg = []
     self.task_name = data.get('task_name', '')
     self.task_template = data.get('task_template', '')
     self.is_enable = data.get('is_enable', '')
     self.is_encrypt = data.get('is_encrypt', '')
     self.mail_header = data.get('mail_header', '')
     self.receivers = data.get('receivers', [])
     self.cc = data.get('cc', [])
     self.crontab = data.get('crontab', '')
     self.sql_list = data.get('sql_list', '')
Exemplo n.º 22
0
def mod_periodic_task_data(request):
    # 修改周期任务数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)

    _id = data['_id']
    cc = data['cc']
    crontab = data['crontab']
    is_enable = data['is_enable']
    is_encrypt = data['is_encrypt']
    # is_sensitive = data['is_sensitive']
    mail_header = data['mail_header']
    receivers = data['receivers']
    sql_list = data['sql_list']
    task_name = data['task_name']
    task_template = data['task_template']

    mailpara = {
        'mail_host': mail_host,
        'mail_user': mail_user,
        'mail_pass': mail_pass,
        'sender': sender,
        'sender_zh_name': sender_zh_name,
        'receivers': receivers,
        'cc': cc,
        'is_encrypt': is_encrypt,
    }
    schedule = CrontabSchedule.objects.get(pk=crontab)

    schedule_dict = {
        'crontab': schedule,
        'args': dumps([mail_header, task_name, sql_list]),
        'kwargs': dumps(mailpara),
        'task': task_template,
        'enabled': is_enable,
        'name': task_name
    }
    obj, _ = PeriodicTask._default_manager.update_or_create(
        id=int(_id),
        defaults=schedule_dict,
    )
    # mail_excel(mail_header, task_name, sql_list, **mailpara)
    response.write(json.dumps({'status': 0, 'msg': ['操作成功']}))
    return response
Exemplo n.º 23
0
def get_mod_periodic_task_data(request):
    # 获取修改的周期任务数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    _id = rq_post('_id')
    obj = PeriodicTask.objects.get(pk=int(_id))
    data = {
        'name': obj.name,
        'task_template': obj.task,
        'crontab': obj.crontab.id,
        'args': obj.args,
        'kwargs': obj.kwargs,
        'enabled': obj.enabled,
    }
    response.write(json.dumps(data))
    return response
Exemplo n.º 24
0
def add_periodic_task_data(request):
    # 提交新增周期任务数据
    response = HttpResponse()
    cur = Currency(request)
    rq_post = getattr(cur, 'rq_post')
    jdata = rq_post('data')
    data = json.loads(jdata)

    cc = data['cc']
    crontab = data['crontab']
    is_enable = data['is_enable']
    is_encrypt = data['is_encrypt']
    # is_sensitive = data['is_sensitive']
    mail_header = data['mail_header']
    receivers = data['receivers']
    sql_list = data['sql_list']
    task_name = data['task_name']
    task_template = data['task_template']

    mailpara = {
        'mail_host': mail_host,
        'mail_user': mail_user,
        'mail_pass': mail_pass,
        'sender': sender,
        'sender_zh_name': sender_zh_name,
        'receivers': receivers,
        'cc': cc,
        'is_encrypt': is_encrypt,
    }

    schedule = CrontabSchedule.objects.get(pk=crontab).schedule
    create_or_update_task = DatabaseScheduler.create_or_update_task
    schedule_dict = {
        'schedule': schedule,
        'args': [mail_header, task_name, sql_list],
        'kwargs': mailpara,
        'task': task_template,
        'enabled': is_enable
    }
    create_or_update_task(task_name, **schedule_dict)
    # mail_excel(mail_header, task_name, sql_list, **mailpara)
    response.write(json.dumps({'status': 0, 'msg': ['操作成功']}))
    return response