def _generate_task_mapping_work_items(mongo: MongoWrapper) -> Iterable[ProjectTaskMappingWorkItem]:
    """
    Generate task mapping work items that need to be processed.

    :param mongo: Mongo db containing work item queue.
    :return: Iterator over task mapping work items.
    """
    work_item = ProjectTaskMappingWorkItem.next(mongo.task_mappings_queue())
    while work_item:
        yield work_item
        work_item = ProjectTaskMappingWorkItem.next(mongo.task_mappings_queue())
def _process_one_task_mapping_work_item(
    work_item: ProjectTaskMappingWorkItem,
    evg_api: EvergreenApi,
    mongo: MongoWrapper,
    after_date: datetime,
) -> None:
    """
    Process a task mapping work item.

    :param work_item: Task mapping to create.
    :param evg_api: An instance of the evg_api client
    :param mongo: An instance of MongoWrapper.
    :param after_date: The date at which to start analyzing commits of the project.
    """
    with tmp_bind(LOGGER, project=work_item.project, evergreen_module=work_item.module) as log:
        log.info("Starting task mapping work item processing for work_item")
        if _seed_task_mappings_for_project(evg_api, mongo, work_item, after_date, log):
            work_item.complete(mongo.task_mappings_queue())
示例#3
0
def create_task_mapping(ctx: Context, project: str, src_regex: str,
                        build_regex: str) -> None:
    """
    Add a project to the queue to be tracked for task mappings.

    This command is meant for testing purposes only. Adding new projects to the task mappings
    should normally be done via the REST API.
    \f
    :param ctx: Command Context.
    :param project: Evergreen project to add to queue.
    :param src_regex: Regular expression for project source files.
    :param build_regex: Regular expression for build variants.
    """
    evergreen_project = get_evg_project(ctx.obj["evg_api"], project)
    if not evergreen_project:
        raise ValueError("Evergreen project not found")

    work_item = ProjectTaskMappingWorkItem.new_task_mappings(
        project, src_regex, build_variant_regex=build_regex)
    work_item.insert(ctx.obj["mongo"].task_mappings_queue())
def post(
        work_item_params: TaskMappingsWorkItem,
        project: str,
        evg_api: EvergreenApi = Depends(get_evg),
        db: MongoWrapper = Depends(get_db),
) -> CustomResponse:
    """
    Enqueue a project task mapping work item.

    :param evg_api: Evergreen API.
    :param db: The database.
    :param work_item_params: The work items to enqueue.
    :param project: The evergreen project identifier.
    """
    evg_project = try_retrieve_evergreen_project(project, evg_api)
    module = work_item_params.module
    module_source_file_regex = work_item_params.module_source_file_regex
    if module and not module_source_file_regex:
        raise HTTPException(
            status_code=400,
            detail="The module_source_file_regex param is required if "
            "a module name is passed in",
        )

    work_item = ProjectTaskMappingWorkItem.new_task_mappings(
        evg_project.identifier,
        work_item_params.source_file_regex,
        module,
        module_source_file_regex,
        work_item_params.build_variant_regex,
    )

    if work_item.insert(db.task_mappings_queue()):
        return CustomResponse(
            custom=f"Work item added for project '{evg_project.identifier}'")
    else:
        raise HTTPException(
            status_code=422,
            detail=
            f"Work item already exists for project '{evg_project.identifier}'",
        )