Ejemplo n.º 1
0
def del_sqlcronjob(job_id):
    try:
        sql_schedule = Schedule.objects.get(name=job_id)
        Schedule.delete(sql_schedule)
        logger.debug('del_sqlcronjob:' + job_id)
    except Schedule.DoesNotExist:
        logger.debug('del_sqlcronjob {} failed, job does not exist'.format(job_id))
Ejemplo n.º 2
0
def del_schedule(name):
    """删除task"""
    try:
        sql_schedule = Schedule.objects.get(name=name)
        Schedule.delete(sql_schedule)
        # logger.debug(f'删除task:{name}')
    except Schedule.DoesNotExist:
        pass
Ejemplo n.º 3
0
def schedule(func, *args, **kwargs):
    """
    Create a schedule.

    :param func: function to schedule.
    :param args: function arguments.
    :param name: optional name for the schedule.
    :param hook: optional result hook function.
    :type schedule_type: Schedule.TYPE
    :param repeats: how many times to repeat. 0=never, -1=always.
    :param next_run: Next scheduled run.
    :type next_run: datetime.datetime
    :param cluster: optional cluster name.
    :param cron: optional cron expression
    :param kwargs: function keyword arguments.
    :return: the schedule object.
    :rtype: Schedule
    """
    name = kwargs.pop("name", None)
    hook = kwargs.pop("hook", None)
    schedule_type = kwargs.pop("schedule_type", Schedule.ONCE)
    minutes = kwargs.pop("minutes", None)
    repeats = kwargs.pop("repeats", -1)
    next_run = kwargs.pop("next_run", timezone.now())
    cron = kwargs.pop("cron", None)
    cluster = kwargs.pop("cluster", None)

    # check for name duplicates instead of am unique constraint
    if name and Schedule.objects.filter(name=name).exists():
        raise IntegrityError("A schedule with the same name already exists.")

    # create and return the schedule
    s = Schedule(
        name=name,
        func=func,
        hook=hook,
        args=args,
        kwargs=kwargs,
        schedule_type=schedule_type,
        minutes=minutes,
        repeats=repeats,
        next_run=next_run,
        cron=cron,
        cluster=cluster,
    )
    # make sure we trigger validation
    s.full_clean()
    s.save()
    return s