def push_to_orcid(sender, record, *args, **kwargs): """If needed, queue the push of the new changes to ORCID.""" if not is_hep(record) or not current_app.config[ 'FEATURE_FLAG_ENABLE_ORCID_PUSH']: 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 task_name = current_app.config['ORCID_PUSH_TASK_ENDPOINT'] orcids = get_orcids_for_push(record) orcids_and_tokens = get_push_access_tokens(orcids) for orcid, access_token in orcids_and_tokens: push_to_orcid_task = Task() push_to_orcid_task.name = task_name push_to_orcid_task.apply_async( queue='orcid_push', kwargs={ 'orcid': orcid, 'rec_id': record['control_number'], 'oauth_token': access_token, }, )
def push_to_orcid(sender, record, *args, **kwargs): """If needed, queue the push of the new changes to ORCID. """ if not is_hep(record): return def _get_orcid(author_ids): for author_id in author_ids: if author_id.get('schema', '').lower() == 'orcid': return author_id['value'] task_name = current_app.config['ORCID_PUSH_TASK_ENDPOINT'] authors = record.get('authors', ()) for author in authors: orcid = _get_orcid(author.get('ids', ())) if not orcid: continue token = get_push_access_token(orcid) if token is None: continue push_to_orcid_task = Task() push_to_orcid_task.name = task_name push_to_orcid_task.apply_async( queue='orcid_push', kwargs={ 'orcid': orcid, 'rec_id': record['control_number'], 'token': token, }, )
def send(self, message): # 生产者配置 app = Celery(broker=celery_config.BROKER_URL) task = Task() task.name = celery_config.REQUEST_TASK task.bind(app) task.apply_async([message], exchange=celery_config.REQUEST_NAME, routing_key=celery_config.ROUNTING_KEY, expires=60 * 60 * 24)