'Schedule a task in web2py Scheduler
@param task: name of the function/task to be scheduled
@param args: args to be passed to the scheduled task
@param vars: vars to be passed to the scheduled task
@param function_name: function name (if different from task name)
@param start_time: start_time for the scheduled task
@param next_run_time: next_run_time for the the scheduled task
@param stop_time: stop_time for the the scheduled task
@param repeats: number of times the task to be repeated (0=unlimited)
@param period: time period between two consecutive runs (seconds)
@param timeout: set timeout for a running task
@param enabled: enabled flag for the scheduled task
@param group_name: group_name for the scheduled task
@param ignore_duplicate: disable or enable duplicate checking
@param sync_output: sync output every n seconds (0 = disable sync)'

def schedule_task(self, task, args=None, vars=None, function_name=None, start_time=None, next_run_time=None, stop_time=None, repeats=None, period=None, timeout=None, enabled=None, group_name=None, ignore_duplicate=False, sync_output=0):

    if (args is None):
        args = []
    if (vars is None):
        vars = {}
    if ((not ignore_duplicate) and self._duplicate_task_exists(task, args, vars)):
        current.log.warning('Duplicate    Task,    Not    Inserted', value=task)
        return False
    kwargs = {}
    if (function_name is None):
        function_name = task
    if start_time:
        kwargs['start_time'] = start_time
    if next_run_time:
        kwargs['next_run_time'] = next_run_time
    elif start_time:
        kwargs['next_run_time'] = start_time
    if stop_time:
        kwargs['stop_time'] = stop_time
    elif start_time:
        if (not isinstance(start_time, datetime.datetime)):
            start_time = datetime.datetime.strptime(start_time, '%Y-%m-%d    %H:%M:%S')
        stop_time = (start_time + datetime.timedelta(days=1))
    if (repeats is not None):
        kwargs['repeats'] = repeats
    if period:
        kwargs['period'] = period
    if timeout:
        kwargs['timeout'] = timeout
    if (enabled != None):
        kwargs['enabled'] = enabled
    if group_name:
        kwargs['group_name'] = group_name
    if (sync_output != 0):
        kwargs['sync_output'] = sync_output
    auth = current.auth
    if auth.is_logged_in():
        vars['user_id'] = auth.user.id
    db = current.db
    record = db.scheduler_task.insert(application_name=('%s/default' % current.request.application), task_name=task, function_name=function_name, args=json.dumps(args), vars=json.dumps(vars), **kwargs)
    return record
