Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bigbang/tasks_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def _schedule_migrate_and_publish_journals(username, enabled):
force_update=False,
status=[],
valid_status=["REPROC", "TODO", "DOING", "DONE", "PENDING", "BLOCKED"],
force_import_acron_id_file=False,
force_core_sync=False,
),
description=_("Migra e publica os periódicos"),
priority=TITLE_DB_MIGRATION_PRIORITY,
Expand Down
2 changes: 2 additions & 0 deletions migration/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def create_or_update_journal(
exc_traceback=exc_traceback,
)
raise e
journal.core_synchronized = True
journal.save()
return journal


Expand Down
10 changes: 2 additions & 8 deletions proc/source_classic_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ def create_or_update_migrated_journal(
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
UnexpectedEvent.create(
action="proc.sources.classic_website.create_or_update_migrated_journal",
item=scielo_issn,
e=e,
exc_traceback=exc_traceback,
detail={
"task": "proc.sources.classic_website.create_or_update_migrated_journal",
"user_id": user.id,
"username": user.username,
"collection": collection.acron,
"pid": scielo_issn,
"force_update": force_update,
},
)


Expand Down
36 changes: 27 additions & 9 deletions proc/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def task_migrate_and_publish_journals(
status=None,
valid_status=None,
force_import_acron_id_file=False,
force_core_sync=False,
):
"""
Ponto de entrada para migração e publicação de periódicos.
Expand All @@ -325,6 +326,7 @@ def task_migrate_and_publish_journals(
"force_update": force_update,
"status": status,
"force_import_acron_id_file": force_import_acron_id_file,
"force_core_sync": force_core_sync,
}
for collection in _get_collections(collection_acron):
task_migrate_and_publish_journals_by_collection.delay(
Expand All @@ -335,12 +337,13 @@ def task_migrate_and_publish_journals(
force_update=force_update,
status=status,
force_import_acron_id_file=force_import_acron_id_file,
force_core_sync=force_core_sync,
)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
UnexpectedEvent.create(
action="proc.tasks.task_migrate_and_publish_journals",
item=f"{collection_acron}-{journal_acron}",
item=collection_acron,
e=e,
exc_traceback=exc_traceback,
detail={"task_params": task_params},
Expand All @@ -357,6 +360,7 @@ def task_migrate_and_publish_journals_by_collection(
force_update=False,
status=None,
force_import_acron_id_file=False,
force_core_sync=False,
):
"""
Migra e publica periódicos de uma coleção.
Expand All @@ -374,10 +378,11 @@ def task_migrate_and_publish_journals_by_collection(
"force_update": force_update,
"status": status,
"force_import_acron_id_file": force_import_acron_id_file,
"force_core_sync": force_core_sync,
}
task_exec = TaskExecution(
name="proc.tasks.task_migrate_and_publish_journals_by_collection",
item=f"{collection_acron}-{journal_acron}",
item=f"{collection_acron}",
params=task_params,
)
try:
Expand All @@ -386,7 +391,7 @@ def task_migrate_and_publish_journals_by_collection(
classic_website = controller.get_classic_website(collection_acron)
collection = Collection.objects.get(acron=collection_acron)
create_or_update_migrated_journal(
user, collection, classic_website, force_update
user, collection, classic_website, force_import_acron_id_file
)

journal_filter = {}
Expand All @@ -398,6 +403,10 @@ def task_migrate_and_publish_journals_by_collection(
| Q(qa_ws_status__in=status)
| Q(public_ws_status__in=status)
)
if not force_core_sync:
# seleciona também aqueles que não estão sincronizados
query_by_status |= Q(journal__core_synchronized=False)

fix_publication_status(collection)
items_to_process = JournalProc.objects.filter(
query_by_status, collection=collection, **journal_filter
Expand All @@ -414,18 +423,26 @@ def task_migrate_and_publish_journals_by_collection(
try:
detail = {}
event = journal_proc.start(user, "migrate journal")
completed = journal_proc.create_or_update_item(
user, force_update, controller.create_or_update_journal
)
if force_update or not journal_proc.journal.core_synchronized:

if force_core_sync or (
journal_proc.journal and not journal_proc.journal.core_synchronized
):
fetch_and_create_journal(
user,
collection_acron=collection.acron,
issn_electronic=journal_proc.issn_electronic,
issn_print=journal_proc.issn_print,
force_update=force_update,
force_update=force_core_sync,
)
detail["journal_data_source"] = "core data"
else:
# cria journal a partir de migrated journal
journal_proc.create_or_update_item(
user, force_update, controller.create_or_update_journal
)
detail["journal_data_source"] = "classic website data"
if qa_api_data and not qa_api_data.get("error"):
detail["task_publish_journal_on_qa_website"] = "scheduled"
task_publish_journal.apply_async(
kwargs=dict(
user_id=user_id,
Expand All @@ -437,6 +454,7 @@ def task_migrate_and_publish_journals_by_collection(
)
)
if public_api_data and not public_api_data.get("error"):
detail["task_publish_journal_on_public_website"] = "scheduled"
task_publish_journal.apply_async(
kwargs=dict(
user_id=user_id,
Expand Down Expand Up @@ -476,7 +494,7 @@ def task_migrate_and_publish_journals_by_collection(
except Exception:
UnexpectedEvent.create(
action="proc.tasks.task_migrate_and_publish_journals_by_collection",
item=f"{collection_acron}-{journal_acron}",
item=f"{collection_acron}",
e=e,
exc_traceback=exc_traceback,
detail=task_params,
Expand Down