Skip to content

Commit

Permalink
Merge pull request #19 from gustavofonseca/avoid-redeposits
Browse files Browse the repository at this point in the history
Adiciona controle para documentos já depositados
  • Loading branch information
gustavofonseca authored Mar 8, 2021
2 parents 1405432 + 7e68d56 commit 52da64d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
15 changes: 12 additions & 3 deletions doi_request/controller.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import logging

from tasks.celery import registry_dispatcher_document
from tasks.celery import (
registry_dispatcher_document,
registry_dispatcher_document_skip_deposited,
)


logger = logging.getLogger(__name__)


class Depositor(object):

def deposit_by_pids(self, pids_list):
def deposit_by_pids(self, pids_list, skip_deposited=False):
"""
Receive a list of pids and collection to registry their dois.
scl
"""
if skip_deposited:
register_document = registry_dispatcher_document_skip_deposited
else:
register_document = registry_dispatcher_document

for item in pids_list:
collection, code = item.split('_')
registry_dispatcher_document.delay(code, collection)
register_document.delay(code,
collection)
logger.info('enqueued deposit for "%s"', item)

2 changes: 1 addition & 1 deletion processing/exportDOI.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run(self):

code = '_'.join([document.collection, document.code])
logger.info('collecting document for deposit: %s', code)
self._depositor.deposit_by_pids([code])
self._depositor.deposit_by_pids([code], skip_deposited=True)
count += 1

logger.info('finished collecting documents. total: %d', count)
Expand Down
30 changes: 26 additions & 4 deletions tasks/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,23 @@ def request_doi_status(self, code):
autoretry_for=(ServerError,), retry_backoff=True)
@log_call
def registry_dispatcher_document(self, code, collection):
"""
This task receive a list of codes that should be queued for DOI registry
"""
return _registry_dispatcher_document(code, collection, skip_deposited=False)


@app.task(bind=True, throws=(ChainAborted,), task_time_limit=60,
autoretry_for=(ServerError,), retry_backoff=True)
@log_call
def registry_dispatcher_document_skip_deposited(self, code, collection):
"""
This task receive a list of codes that should be queued for DOI registry
"""
return _registry_dispatcher_document(code, collection, skip_deposited=True)


def _registry_dispatcher_document(code, collection, skip_deposited):
"""
This task receive a list of codes that should be queued for DOI registry
"""
Expand Down Expand Up @@ -518,11 +535,16 @@ def registry_dispatcher_document(self, code, collection):
with transactional_session() as session:
deposit = session.query(Deposit).filter_by(code=code).first()
if deposit:
logger.info('deposit already exists. it will be deleted and '
're-created: "%s"', code)
session.delete(deposit)

if skip_deposited:
logger.info('deposit already exists. skipping: "%s"', code)
return
else:
logger.info('deposit already exists. it will be deleted and '
're-created: "%s"', code)
session.delete(deposit)

session.add(depitem)

logger.info('deposit successfuly created for "%s": %s', code,
repr(deposit))

Expand Down

0 comments on commit 52da64d

Please sign in to comment.