def update_expired_embargos(): """Release expired embargoes every midnight.""" logger = current_app.logger base_url = urlunsplit( (current_app.config.get('PREFERRED_URL_SCHEME', 'http'), current_app.config['JSONSCHEMAS_HOST'], current_app.config.get('APPLICATION_ROOT') or '', '', '')) # The task needs to run in a request context as JSON Schema validation # will use url_for. with current_app.test_request_context('/', base_url=base_url): s = B2ShareRecordsSearch( using=current_search_client, index='records').query( 'query_string', query='open_access:false AND embargo_date:{{* TO {0}}}'.format( datetime.now(timezone.utc).isoformat()), allow_leading_wildcard=False).fields([]) record_ids = [hit.meta.id for hit in s.scan()] if record_ids: logger.info('Changing access of {} embargoed publications' ' to public.'.format(len(record_ids))) for record in Record.get_records(record_ids): logger.debug('Making embargoed publication {} public'.format( record.id)) record['open_access'] = True record.commit() db.session.commit() indexer = RecordIndexer() indexer.bulk_index(record_ids) indexer.process_bulk_queue()
def update_expired_embargoes(): """Release expired embargoes every midnight.""" logger = current_app.logger base_url = urlunsplit(( current_app.config.get('PREFERRED_URL_SCHEME', 'http'), current_app.config['JSONSCHEMAS_HOST'], current_app.config.get('APPLICATION_ROOT') or '', '', '' )) # The task needs to run in a request context as JSON Schema validation # will use url_for. with current_app.test_request_context('/', base_url=base_url): s = B2ShareRecordsSearch( using=current_search_client, index='records' ).query( 'query_string', query='open_access:false AND embargo_date:{{* TO {0}}}'.format( datetime.now(timezone.utc).isoformat() ), allow_leading_wildcard=False ).fields([]) record_ids = [hit.meta.id for hit in s.scan()] if record_ids: logger.info('Changing access of {} embargoed publications' ' to public.'.format(len(record_ids))) for record in Record.get_records(record_ids): logger.debug('Making embargoed publication {} public'.format( record.id)) record['open_access'] = True record.commit() db.session.commit() indexer = RecordIndexer() indexer.bulk_index(record_ids) indexer.process_bulk_queue()
def _get_deposits_split_by_type(query): """Get video/projects and both as records.""" video_schema = current_jsonschemas.path_to_url(Video._schema) project_schema = current_jsonschemas.path_to_url(Project._schema) # get list of videos, project and both as records video_ids = [] project_ids = [] record_ids = [] for data in query.scan(): if data['$schema'] == project_schema: project_ids.append(data.meta.id) if data['$schema'] == video_schema: video_ids.append(data.meta.id) record_ids.append(data.meta.id) records = {r.id: r for r in Record.get_records(record_ids)} projects = Project.get_records(project_ids) videos = Video.get_records(video_ids) return (videos, projects, records)