コード例 #1
0
def duplicate_task(task_id: int) -> Response:
    """Duplicate a task."""
    my_task = Task.query.filter_by(id=task_id).first()
    if my_task:
        new_task = Task()

        # pylint: disable=protected-access
        for key in my_task.__table__.columns.keys():
            if key not in ["id", "last_run", "last_run_job_id", "status_id"]:
                setattr(new_task, key, getattr(my_task, key))

        new_task.enabled = 0
        new_task.creator_id = current_user.id
        new_task.updater_id = current_user.id
        new_task.status_id = None
        new_task.order = None
        new_task.name = str(my_task.name or "") + " - Duplicated"

        db.session.add(new_task)
        db.session.commit()

        return redirect(url_for("task_bp.one_task", task_id=new_task.id))

    flash("Task does not exist.")
    return redirect(url_for("task_bp.all_tasks"))
コード例 #2
0
ファイル: api.py プロジェクト: icodeface/x.codeface.cn
def api_create():
    name = request.json.get('name')
    config = request.json.get('config')
    task = Task(author=g.user, name=name, config=config)
    task.save()
    return jsonify({
        'code': 1,
        'data': {
            'id': str(task.id),
            'name': task.name,
            'create_time': task.create_time,
            'config': task.config,
            'author': task.author.email
        }
    })
コード例 #3
0
ファイル: api.py プロジェクト: icodeface/x.codeface.cn
def api_del_task(tid):
    try:
        task = Task.objects(id=tid).first()
        if task.author == g.user:
            return jsonify({
                'code': 1,
                'tip': "delete success"
            })
        return jsonify({
            'code': 0,
            'tip': "no access to this task"
        })
    except db.errors.ValidationError:
        return jsonify({
            'code': 0,
            'data': {}
        })
コード例 #4
0
def task_new(project_id: int) -> Union[str, Response]:
    """Create a new task."""
    cache.clear()
    # create tasks
    form = request.form

    me = Task(
        name=form.get("name", "undefined").strip(),
        project_id=project_id,
        creator_id=current_user.id,
        updater_id=current_user.id,
        max_retries=form.get("task-retry", 0, type=int),
        order=form.get("task-rank", 0, type=int),
        source_type_id=form.get("sourceType", None, type=int),
        source_database_id=form.get("task-source-database", None, type=int),
        source_query_include_header=form.get(
            "task_include_query_headers", None, type=int
        ),
        source_smb_id=form.get("task-source-smb", None, type=int),
        source_smb_file=form.get("sourceSmbFile", None, type=str),
        source_smb_ignore_delimiter=form.get("task_smb_ignore_delimiter", 0, type=int),
        source_smb_delimiter=form.get("sourceSmbDelimiter", None, type=str),
        source_sftp_id=form.get("task-source-sftp", None, type=int),
        source_sftp_file=form.get("sourceSftpFile", None, type=str),
        source_sftp_ignore_delimiter=form.get(
            "task_sftp_ignore_delimiter", None, type=int
        ),
        enable_source_cache=form.get("task_enable_source_cache", None, type=int),
        source_require_sql_output=form.get("task_require_sql_output", None, type=int),
        source_sftp_delimiter=form.get("sourceSftpDelimiter", None, type=str),
        source_ftp_id=form.get("task-source-ftp", None, type=int),
        source_ftp_file=form.get("sourceFtpFile", None, type=str),
        source_ftp_ignore_delimiter=form.get(
            "task_ftp_ignore_delimiter", None, type=int
        ),
        source_ftp_delimiter=form.get("sourceFtpDelimiter", None, type=str),
        source_ssh_id=form.get("task-source-ssh", None, type=int),
        source_query_type_id=form.get("sourceQueryType", None, type=int),
        query_params=form.get("taskParams", "", type=str).strip(),
        source_git=form.get("sourceGit", None, type=str),
        query_smb_file=form.get("sourceQuerySmbFile", None, type=str),
        query_smb_id=form.get("task-query-smb", None, type=int),
        query_sftp_file=form.get("sourceQuerySftpFile", None, type=str),
        query_sftp_id=form.get("task-query-sftp", None, type=int),
        query_ftp_file=form.get("sourceQueryFtpFile", None, type=str),
        query_ftp_id=form.get("task-query-ftp", None, type=int),
        source_url=form.get("sourceURL", None, type=str),
        source_code=form.get("sourceCode", None, type=str),
        processing_type_id=form.get("processingType", None, type=int),
        processing_smb_file=form.get("processingSmbFile", None, type=str),
        processing_smb_id=form.get("task-processing-smb", None, type=int),
        processing_sftp_file=form.get("processingSftpFile", None, type=str),
        processing_sftp_id=form.get("task-processing-sftp", None, type=int),
        processing_ftp_file=form.get("processingFtpFile", None, type=str),
        processing_ftp_id=form.get("task-processing-ftp", None, type=int),
        processing_git=form.get("processingGit", None, type=str),
        processing_url=form.get("processingUrl", None, type=str),
        processing_code=form.get("processingCode", None, type=str),
        processing_command=form.get("processingCommand", None, type=str),
        destination_quote_level_id=form.get("quoteLevel", 3, type=int),
        destination_file_type_id=form.get("fileType", None, type=int),
        destination_file_name=form.get(
            "destinationFileName", form.get("name", "undefined", type=str), type=str
        ),
        destination_create_zip=form.get("task_create_zip", None, type=int),
        destination_zip_name=form.get(
            "destinationZipName", form.get("name", "undefined", type=str), type=str
        ),
        destination_file_delimiter=form.get("fileDelimiter", None, type=str),
        destination_file_line_terminator=form.get("fileTerminator", None, type=str),
        destination_ignore_delimiter=form.get(
            "task_ignore_file_delimiter", None, type=int
        ),
        file_gpg=form.get("task_file_gpg", 0, type=int),
        file_gpg_id=form.get("task-file-gpg", None, type=int),
        destination_sftp=form.get("task_save_sftp", 0, type=int),
        destination_sftp_id=form.get("task-destination-sftp", None, type=int),
        destination_sftp_overwrite=form.get("task_overwrite_sftp", None, type=int),
        destination_sftp_dont_send_empty_file=form.get(
            "task_sftp_dont_send_empty", 0, type=int
        ),
        destination_ftp=form.get("task_save_ftp", 0, type=int),
        destination_ftp_id=form.get("task-destination-ftp", None, type=int),
        destination_ftp_overwrite=form.get("task_overwrite_ftp", None, type=int),
        destination_ftp_dont_send_empty_file=form.get(
            "task_ftp_dont_send_empty", 0, type=int
        ),
        destination_smb=form.get("task_save_smb", 0, type=int),
        destination_smb_id=form.get("task-destination-smb", None, type=int),
        destination_smb_overwrite=form.get("task_overwrite_smb", None, type=int),
        destination_smb_dont_send_empty_file=form.get(
            "task_smb_dont_send_empty", 0, type=int
        ),
        email_completion=form.get("task_send_completion_email", 0, type=int),
        email_completion_recipients=form.get("completionEmailRecip", "", type=str),
        email_completion_message=form.get("completion_email_msg", "", type=str),
        email_completion_log=form.get("task_send_completion_email_log", 0, type=int),
        email_completion_file=form.get("task_send_output", 0, type=int),
        email_completion_dont_send_empty_file=form.get(
            "task_dont_send_empty", 0, type=int
        ),
        email_completion_file_embed=form.get("task_embed_output", 0, type=int),
        email_error=form.get("task_send_error_email", 0, type=int),
        email_error_recipients=form.get("errorEmailRecip", "", type=str),
        email_error_message=form.get("errorEmailMsg", "", type=str),
        enabled=form.get("task-ooff", 0, type=int),
    )

    db.session.add(me)
    db.session.commit()

    log = TaskLog(
        task_id=me.id,
        status_id=7,
        message=(current_user.full_name or "none") + ": Task created.",
    )
    db.session.add(log)
    db.session.commit()

    if me.enabled == 1:
        submit_executor("enable_task", me.id)

    return redirect(url_for("task_bp.one_task", task_id=me.id))
コード例 #5
0
ファイル: api.py プロジェクト: icodeface/x.codeface.cn
def api_show_task():
    tasks = Task.objects(author=g.user)
    return jsonify({
                'code': 1,
                'data': tasks
    })