code: def filter_tasks(self, request, context):
          
          _log_request(request, context)
          tasks_pattern, tasks_negate = PATTERN_PARAMS_OP(request.tasks_filter)
          state_pattern = request.state_pattern
          limit, reverse = request.limit, request.reverse
  
          pregex = re.compile(tasks_pattern)  # pattern filter condition
          sregex = re.compile(state_pattern)  # state filter condition
  
          def pcondition(task):
              return accepts(pregex, tasks_negate, task.name, task.routing_key)
  
          def scondition(task):
              return accepts(sregex, tasks_negate, task.state)
  
          found_tasks = (task for _, task in
                         self.listener.memory.tasks_by_time(limit=limit or None,
                                                            reverse=reverse)
                         if pcondition(task) and scondition(task))
  
          def callback(t):
              logger.debug('%s iterated %d tasks in %s (%s)', self.filter_tasks.__name__,
                           t.count, t.duration_human, t.throughput_human)
  
          for task in about_time(callback, found_tasks):
              yield ClearlyServer._event_to_pb(task)[1]
docs: Filter tasks by matching patterns to name, routing key and state.