Beispiel #1
0
    def run_tasks(self):
        """
        Passes entries to the target task(s) configured for this connection
        :return:
        """
        tasks = self.config.get('task')
        tasks_re = self.config.get('task_re')
        if tasks:
            if isinstance(tasks, basestring):
                tasks = [tasks]
            log.info('Injecting %d entries into tasks %s', len(self.entry_queue), ', '.join(tasks))
            manager.execute(options={'tasks': tasks, 'cron': True, 'inject': self.entry_queue}, priority=5)

        if tasks_re:
            tasks_entry_map = {}
            for entry in self.entry_queue:
                matched = False
                for task, config in tasks_re.items():
                    if isinstance(config, dict):
                        config = [config]
                    for c in config:
                        if re.search(c['regexp'], entry.get(c['field'], '')):
                            matched = True
                            if not tasks_entry_map.get(task):
                                tasks_entry_map[task] = []
                            tasks_entry_map[task].append(entry)
                if not matched:
                    log.info('Entry "%s" did not match any task regexp.', entry['title'])

            for task, entries in tasks_entry_map.items():
                log.info('Injecting %d entries into task "%s"', len(entries), task)
                manager.execute(options={'tasks': [task], 'cron': True, 'inject': entries}, priority=5)

        self.entry_queue = []
Beispiel #2
0
    def run_tasks(self):
        """
        Passes entries to the target task(s) configured for this connection
        :return:
        """
        tasks = self.config.get('task')
        tasks_re = self.config.get('task_re')
        if tasks:
            if isinstance(tasks, str):
                tasks = [tasks]
            logger.debug('Injecting {} entries into tasks {}',
                         len(self.entry_queue), ', '.join(tasks))
            options = {
                'tasks': tasks,
                'cron': True,
                'inject': self.entry_queue,
                'allow_manual': True,
            }
            manager.execute(options=options,
                            priority=5,
                            suppress_warnings=['input'])

        if tasks_re:
            tasks_entry_map = {}
            for entry in self.entry_queue:
                matched = False
                for task_config in tasks_re:
                    pattern_match = 0
                    for pattern in task_config.get('patterns'):
                        if re.search(pattern['regexp'],
                                     entry.get(pattern['field'], ''),
                                     re.IGNORECASE):
                            pattern_match += 1

                    # the entry is added to the task map if all of the defined regex matched
                    if len(task_config.get('patterns')) == pattern_match:
                        matched = True
                        if not tasks_entry_map.get(task_config.get('task')):
                            tasks_entry_map[task_config.get('task')] = []
                        tasks_entry_map[task_config.get('task')].append(entry)

                if not matched:
                    logger.debug('Entry "{}" did not match any task regexp.',
                                 entry['title'])

            for task, entries in tasks_entry_map.items():
                logger.debug('Injecting {} entries into task "{}"',
                             len(entries), task)
                options = {
                    'tasks': [task],
                    'cron': True,
                    'inject': entries,
                    'allow_manual': True
                }
                manager.execute(options=options,
                                priority=5,
                                suppress_warnings=['input'])

        self.entry_queue = []
Beispiel #3
0
    def run_tasks(self):
        """
        Passes entries to the target task(s) configured for this connection
        :return:
        """
        tasks = self.config.get('task')
        tasks_re = self.config.get('task_re')
        if tasks:
            if isinstance(tasks, basestring):
                tasks = [tasks]
            log.debug('Injecting %d entries into tasks %s',
                      len(self.entry_queue), ', '.join(tasks))
            options = {
                'tasks': tasks,
                'cron': True,
                'inject': self.entry_queue,
                'allow_manual': True
            }
            manager.execute(options=options,
                            priority=5,
                            suppress_warnings=['input'])

        if tasks_re:
            tasks_entry_map = {}
            for entry in self.entry_queue:
                matched = False
                for task, config in tasks_re.items():
                    if isinstance(config, dict):
                        config = [config]
                    for c in config:
                        if re.search(c['regexp'], entry.get(c['field'], ''),
                                     re.IGNORECASE):
                            matched = True
                            if not tasks_entry_map.get(task):
                                tasks_entry_map[task] = []
                            tasks_entry_map[task].append(entry)
                if not matched:
                    log.debug('Entry "%s" did not match any task regexp.',
                              entry['title'])

            for task, entries in tasks_entry_map.items():
                log.debug('Injecting %d entries into task "%s"', len(entries),
                          task)
                options = {
                    'tasks': [task],
                    'cron': True,
                    'inject': entries,
                    'allow_manual': True
                }
                manager.execute(options=options,
                                priority=5,
                                suppress_warnings=['input'])

        self.entry_queue = []
Beispiel #4
0
def execute():
    kwargs = request.json or {}
    options_string = kwargs.pop('options_string', '')
    if options_string:
        try:
            kwargs['options'] = exec_parser.parse_args(options_string, raise_errors=True).execute
        except ValueError as e:
            return jsonify(error='invalid options_string specified: %s' % e.message), 400

    # We'll stream the log results as they arrive in the bufferqueue
    kwargs['output'] = BufferQueue()
    manager.execute(**kwargs)

    return Response(kwargs['output'], mimetype='text/plain'), 200
Beispiel #5
0
    def run_tasks(self):
        """
        Passes entries to the target task(s) configured for this connection
        :return:
        """
        tasks = self.config.get('task')
        tasks_re = self.config.get('task_re')
        if tasks:
            if isinstance(tasks, basestring):
                tasks = [tasks]
            log.debug(
                'Injecting %d entries into tasks %s', len(self.entry_queue), ', '.join(tasks)
            )
            options = {
                'tasks': tasks,
                'cron': True,
                'inject': self.entry_queue,
                'allow_manual': True,
            }
            manager.execute(options=options, priority=5, suppress_warnings=['input'])

        if tasks_re:
            tasks_entry_map = {}
            for entry in self.entry_queue:
                matched = False
                for task_config in tasks_re:
                    pattern_match = 0
                    for pattern in task_config.get('patterns'):
                        if re.search(
                            pattern['regexp'], entry.get(pattern['field'], ''), re.IGNORECASE
                        ):
                            pattern_match += 1

                    # the entry is added to the task map if all of the defined regex matched
                    if len(task_config.get('patterns')) == pattern_match:
                        matched = True
                        if not tasks_entry_map.get(task_config.get('task')):
                            tasks_entry_map[task_config.get('task')] = []
                        tasks_entry_map[task_config.get('task')].append(entry)

                if not matched:
                    log.debug('Entry "%s" did not match any task regexp.', entry['title'])

            for task, entries in tasks_entry_map.items():
                log.debug('Injecting %d entries into task "%s"', len(entries), task)
                options = {'tasks': [task], 'cron': True, 'inject': entries, 'allow_manual': True}
                manager.execute(options=options, priority=5, suppress_warnings=['input'])

        self.entry_queue = []
Beispiel #6
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    from flexget.manager import manager

    finished_events = manager.execute(options={"tasks": tasks, "cron": True}, priority=5)
    for task_id, task_name, event in finished_events:
        event.wait()
Beispiel #7
0
def execute():
    kwargs = request.json or {}
    options_string = kwargs.pop('options_string', '')
    if options_string:
        try:
            kwargs['options'] = exec_parser.parse_args(
                options_string, raise_errors=True).execute
        except ValueError as e:
            return jsonify(error='invalid options_string specified: %s' %
                           e.message), 400

    # We'll stream the log results as they arrive in the bufferqueue
    kwargs['output'] = BufferQueue()
    manager.execute(**kwargs)

    return Response(kwargs['output'], mimetype='text/plain'), 200
Beispiel #8
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    log.debug('executing tasks: %s', tasks)
    finished_events = manager.execute(options={'tasks': tasks, 'cron': True, 'allow_manual': False}, priority=5)
    for _, task_name, event_ in finished_events:
        log.debug('task finished executing: %s', task_name)
        event_.wait()
    log.debug('all tasks in schedule finished executing')
Beispiel #9
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    log.debug("executing tasks: %s", tasks)
    finished_events = manager.execute(options={"tasks": tasks, "cron": True}, priority=5)
    for task_id, task_name, event in finished_events:
        log.debug("task finished executing: %s", task_name)
        event.wait()
    log.debug("all tasks in schedule finished executing")
Beispiel #10
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    log.debug('executing tasks: %s', tasks)
    finished_events = manager.execute(options={'tasks': tasks, 'cron': True, 'allow_manual': False}, priority=5)
    for _, task_name, event in finished_events:
        log.debug('task finished executing: %s', task_name)
        event.wait()
    log.debug('all tasks in schedule finished executing')
Beispiel #11
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    finished_events = manager.execute(options={
        'tasks': tasks,
        'cron': True
    },
                                      priority=5)
    for task_id, task_name, event in finished_events:
        event.wait()
Beispiel #12
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    from flexget.manager import manager
    finished_events = manager.execute(options={
        'tasks': tasks,
        'cron': True
    },
                                      priority=5)
    for event in finished_events:
        event.wait()
Beispiel #13
0
    def run_tasks(self):
        """
        Passes entries to the target task(s) configured for this connection
        :return:
        """
        tasks = self.config.get("task")
        tasks_re = self.config.get("task_re")
        if tasks:
            if isinstance(tasks, basestring):
                tasks = [tasks]
            log.info("Injecting %d entries into tasks %s", len(self.entry_queue), ", ".join(tasks))
            manager.execute(
                options={"tasks": tasks, "cron": True, "inject": self.entry_queue, "allow_manual": True}, priority=5
            )

        if tasks_re:
            tasks_entry_map = {}
            for entry in self.entry_queue:
                matched = False
                for task, config in tasks_re.items():
                    if isinstance(config, dict):
                        config = [config]
                    for c in config:
                        if re.search(c["regexp"], entry.get(c["field"], ""), re.IGNORECASE):
                            matched = True
                            if not tasks_entry_map.get(task):
                                tasks_entry_map[task] = []
                            tasks_entry_map[task].append(entry)
                if not matched:
                    log.info('Entry "%s" did not match any task regexp.', entry["title"])

            for task, entries in tasks_entry_map.items():
                log.info('Injecting %d entries into task "%s"', len(entries), task)
                manager.execute(
                    options={"tasks": [task], "cron": True, "inject": entries, "allow_manual": True}, priority=5
                )

        self.entry_queue = []
Beispiel #14
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    from flexget.manager import manager
    finished_events = manager.execute(options={'tasks': tasks, 'cron': True}, priority=5)
    for event in finished_events:
        event.wait()
Beispiel #15
0
def run_job(tasks):
    """Add the execution to the queue and waits until it is finished"""
    finished_events = manager.execute(options={'tasks': tasks, 'cron': True}, priority=5)
    for task_id, task_name, event in finished_events:
        event.wait()