-
Notifications
You must be signed in to change notification settings - Fork 357
[ENG-11068] | bound external HTTP in celery tasks to stop worke… #11777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from api.share import utils as share_utils | ||
| from osf.metadata.osf_gathering import OsfmapPartition | ||
| from osf_tests.factories import ProjectFactory | ||
| from website import settings | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| class TestShareRequestTimeout: | ||
|
|
||
| @pytest.fixture() | ||
| def public_node(self): | ||
| return ProjectFactory(is_public=True) | ||
|
|
||
| def test_delete_trove_record_passes_timeout(self, public_node): | ||
| with mock.patch.object(share_utils.requests, 'delete') as mock_delete: | ||
| share_utils.pls_delete_trove_record(public_node, osfmap_partition=OsfmapPartition.MAIN) | ||
| assert mock_delete.call_args.kwargs['timeout'] == settings.EXTERNAL_REQUEST_TIMEOUT | ||
|
|
||
| def test_send_trove_record_passes_timeout(self, public_node): | ||
| fake_serializer = mock.Mock(mediatype='text/turtle') | ||
| fake_serializer.serialize.return_value = b'<turtle>' | ||
| with ( | ||
| mock.patch.object(share_utils, 'pls_get_magic_metadata_basket'), | ||
| mock.patch.object(share_utils, 'get_metadata_serializer', return_value=fake_serializer), | ||
| mock.patch.object(share_utils.requests, 'post') as mock_post, | ||
| ): | ||
| share_utils.pls_send_trove_record( | ||
| public_node, | ||
| is_backfill=False, | ||
| osfmap_partition=OsfmapPartition.MAIN, | ||
| ) | ||
| assert mock_post.call_args.kwargs['timeout'] == settings.EXTERNAL_REQUEST_TIMEOUT |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| from osf.external.askismet.client import AkismetClient | ||
|
|
||
|
|
||
| @celery_app.task() | ||
| @celery_app.task(soft_time_limit=60, time_limit=90) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably these should be configurable as well. |
||
| def submit_spam(guid): | ||
| from osf.models import Guid | ||
| resource = Guid.load(guid).referent | ||
|
|
@@ -20,7 +20,7 @@ def submit_spam(guid): | |
| ) | ||
|
|
||
|
|
||
| @celery_app.task() | ||
| @celery_app.task(soft_time_limit=60, time_limit=90) | ||
| def submit_ham(guid): | ||
| from osf.models import Guid | ||
| resource = Guid.load(guid).referent | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| from framework.celery_tasks import app as celery_app | ||
| from framework.postcommit_tasks.handlers import run_postcommit | ||
| from django.contrib.contenttypes.models import ContentType | ||
| from django.db import transaction | ||
| from osf.external.askismet.client import AkismetClient | ||
| from osf.external.oopspam.client import OOPSpamClient | ||
| from osf.utils.fields import ensure_str | ||
|
|
@@ -24,20 +23,19 @@ def reclassify_domain_references(notable_domain_id, current_note, previous_note) | |
| from osf.models.notable_domain import DomainReference, NotableDomain | ||
| domain = NotableDomain.load(notable_domain_id) | ||
| references = DomainReference.objects.filter(domain=domain) | ||
| with transaction.atomic(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So my only concern with this removal is that I suspect that it's handling some logic for if something fails in the middle, not leaving the database in a weird state. Would it make sense to leave it in an atomic transaction and then spin off a task to do anything that would make an http request, or something else to keep the db from getting into a bad state? |
||
| for item in references: | ||
| item.is_triaged = current_note != NotableDomain.Note.UNKNOWN | ||
| if current_note == NotableDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION_AND_CONTENT: | ||
| item.referrer.confirm_spam(save=False, domains=[domain.domain]) | ||
| elif previous_note == NotableDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION_AND_CONTENT: | ||
| try: | ||
| item.referrer.spam_data['domains'].remove(domain.domain) | ||
| except (KeyError, AttributeError, ValueError) as error: | ||
| logger.info(error) | ||
| if not item.referrer.spam_data.get('domains') and not item.referrer.spam_data.get('who_flagged'): | ||
| item.referrer.unspam(save=False) | ||
| item.save() | ||
| item.referrer.save() | ||
| for item in references: | ||
| item.is_triaged = current_note != NotableDomain.Note.UNKNOWN | ||
| if current_note == NotableDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION_AND_CONTENT: | ||
| item.referrer.confirm_spam(save=False, domains=[domain.domain]) | ||
| elif previous_note == NotableDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION_AND_CONTENT: | ||
| try: | ||
| item.referrer.spam_data['domains'].remove(domain.domain) | ||
| except (KeyError, AttributeError, ValueError) as error: | ||
| logger.info(error) | ||
| if not item.referrer.spam_data.get('domains') and not item.referrer.spam_data.get('who_flagged'): | ||
| item.referrer.unspam(save=False) | ||
| item.save() | ||
| item.referrer.save() | ||
|
|
||
|
|
||
| def _check_resource_for_domains(resource, content): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are very long timeouts. Maybe we should also add settings for these so Cloud can adjust as necessary.