Example #1
0
def index_after_commit(sender, changes):
    """Index a record in ES after it was committed to the DB.

    This cannot happen in an ``after_record_commit`` receiver from Invenio-Records
    because, despite the name, at that point we are not yet sure whether the record
    has been really committed to the DB.
    """
    for model_instance, change in changes:
        if isinstance(model_instance, RecordMetadata):
            if change in ("insert", "update", "delete"):
                LOGGER.debug(f"Record commited",
                             change=change,
                             uuid=str(model_instance.id))
                pid_type = PidStoreBase.get_pid_type_from_schema(
                    model_instance.json.get("$schema"))
                delete = "delete" in changes
                arguments = InspireRecord.get_subclasses(
                )[pid_type]._record_index(model_instance.json,
                                          _id=str(model_instance.id),
                                          force_delete=delete)
                arguments["record_version"] = model_instance.version_id
                LOGGER.debug(
                    f"Record sending to index",
                    uuid=str(model_instance.id),
                    delete=delete,
                )
                current_celery_app.send_task(
                    "inspirehep.records.indexer.tasks.index_record",
                    kwargs=arguments)
            else:
                raise RuntimeError("Wrong operation `%s` on record %r", change,
                                   model_instance.id)
Example #2
0
def assign_to_author(from_author_recid, to_author_recid, literature_recids):
    author_record = AuthorsRecord.get_record_by_pid_value(to_author_recid)
    num_workers = count_consumers_for_queue("assign")
    for batch in chunker(literature_recids, 10, num_workers):
        current_celery_app.send_task(
            "inspirehep.assign.tasks.assign_papers",
            kwargs={
                "from_author_recid": from_author_recid,
                "to_author_record": author_record,
                "author_papers_recids": batch,
            },
        )
    unstub_author_by_recid(to_author_recid)
Example #3
0
def push_to_hal(record):
    """If needed, queue the push of the new changes to HAL."""
    if not current_app.config["FEATURE_FLAG_ENABLE_HAL_PUSH"]:
        LOGGER.info("HAL push feature flag not enabled")
        return

    # Ensure there is a control number. This is not always the case because of broken store_record.
    if "control_number" not in record:
        return

    if is_hal_set(record):
        current_celery_app.send_task(
            "inspirehep.hal.tasks.hal_push",
            kwargs={"recid": record["control_number"]})
Example #4
0
def assign_to_new_stub_author(from_author_recid, literature_recids):
    # TODO: differentiate from BEARD created stub author
    author_papers = get_literature_records_by_recid(literature_recids)
    author_signatures = get_author_signatures(from_author_recid, author_papers)
    stub_author_data = update_author_names({"name": {}}, author_signatures)
    to_author = create_new_stub_author(**stub_author_data)
    num_workers = count_consumers_for_queue("assign")
    for batch in chunker(literature_recids, 10, num_workers):
        current_celery_app.send_task(
            "inspirehep.assign.tasks.assign_papers",
            kwargs={
                "from_author_recid": from_author_recid,
                "to_author_record": to_author,
                "author_papers_recids": batch,
                "is_stub_author": True,
            },
        )
    return to_author["control_number"]
Example #5
0
    def index(self, force_delete=None):
        """Index record in ES

        This method do not have any important logic.
        It just runs self._index() with proper arguments in separate worker.

        To properly index data it requires to fully commit the record first!
        It won't index outdated record.

        Args:
            force_delete: set to True if record has to be deleted,
                If not set, tries to determine automatically if record should be deleted
        Returns:
            celery.result.AsyncResult: Task itself
        """
        indexing_args = self._record_index(self, force_delete=force_delete)
        indexing_args["record_version"] = self.model.version_id
        task = current_celery_app.send_task(
            "inspirehep.records.indexer.tasks.index_record", kwargs=indexing_args
        )
        LOGGER.info(
            "Record indexing", recid=self.get("control_number"), uuid=str(self.id)
        )
        return task
Example #6
0
def _send_push_task(kwargs):
    current_celery_app.send_task("inspirehep.orcid.tasks.orcid_push",
                                 queue="orcid_push",
                                 kwargs=kwargs)