示例#1
0
def stop_project(ctx, project_name):
    """Stop a project."""
    from fulmar.scheduler.projectdb import projectdb

    project_name = project_name.split('/')[-1].strip(' .py')

    project_data = projectdb.get(project_name)
    if not project_data:
        click.echo('Sorry, can not find project:  "%s".' % project_name)
        return
    project_data.update({'is_stopped': True})
    projectdb.set(project_name, project_data)
    click.echo('Successfully stop project: "%s".' % project_name)
示例#2
0
def update_project(ctx, project_file):
    """Update a project."""
    from fulmar.scheduler.projectdb import projectdb
    from fulmar.utils import sha1string
    # TODO: add default dir to put projects
    raw_code = ''
    with open(project_file, 'rb') as f:
        for line in f:
            raw_code += line

    project_id = sha1string(raw_code)
    project_name = project_file.split('/')[-1].strip(' .py')
    data = {
        'project_name': project_name,
        'script': raw_code,
        'project_id': project_id,
        'update_time': time.time()
    }
    projectdb.set(project_name, data)

    click.echo('Successfully update the project "%s".' % project_name)
示例#3
0
def start_project(ctx, project):
    """Start a project."""
    from fulmar.message_queue import newtask_queue
    from fulmar.scheduler.projectdb import projectdb

    if not os.path.exists(project):
        raise IOError('No such file or directory: "%s".' % project)

    if not os.path.isfile(project):
        raise IOError('Is not a Python file: "%s".' % project)

    if not project.endswith('.py'):
        raise TypeError('Not a standard Python file: "%s". Please make sure it is a Python file which ends with ".py".' % project)

    project_name = project.split('/')[-1].strip(' .py')
    project_data = projectdb.get(project_name)

    if not project_data:
        ctx.invoke(update_project, project_file=project)
        project_data = projectdb.get(project_name)

    if project_data.get('is_stopped'):
        project_data.update({'is_stopped': False})
        projectdb.set(project_name, project_data)

    newtask = {
        "project_name": project_name,
        'project_id': project_data.get('project_id'),
        "taskid": project_name + ': on_start',
        "url": 'first_task: ' + project_name,
        "process": {
            "callback": "on_start",
        },
        "schedule": {
            "is_cron": True
        },
    }
    newtask_queue.put(newtask)

    click.echo('Successfully start project: "%s".' % project_name)