Skip to content
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

Implement graceful handling of WDQS rate-limiting #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexdutton
Copy link
Contributor

Has tests, and seems to work locally too.

Closes #47.

@alexdutton alexdutton added the enhancement New feature or request label Feb 7, 2019
@alexdutton alexdutton self-assigned this Feb 7, 2019
def refresh_labels(app_label, model, ids=None, queued_at=None):
@celery.shared_task(bind=True, queue='wdqs')
@utils.queries_wikidata
def refresh_labels(self, app_label, model, ids=None, queued_at=None, rate_limiting_handler=None):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function refresh_labels has 6 arguments (exceeds 4 allowed). Consider refactoring.

wdqs_rate_limiting = Signal(['retry_after'])


def templated_wikidata_query(query_name: str, context: dict,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function templated_wikidata_query has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.

rate_limiting_handler(False)


def queries_wikidata(task_func):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function queries_wikidata has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

@mock.patch('time.sleep')
def testRetriesIfTooManyRequests(self, time_sleep, urlopen):
retry_after = 10
urlopen.side_effect = HTTPError(url=None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

@mock.patch('time.sleep')
def testSuspendsConsuming(self, time_sleep, urlopen):
retry_after = 10
urlopen.side_effect = HTTPError(url=None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

@sagepe sagepe temporarily deployed to democratic-commons-demo-pr-48 February 7, 2019 15:32 Inactive
@alexdutton alexdutton temporarily deployed to democratic-commons-demo-pr-48 February 11, 2019 11:28 Inactive
@codecov
Copy link

codecov bot commented Feb 11, 2019

Codecov Report

Merging #48 into master will increase coverage by 1.44%.
The diff coverage is 98%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
+ Coverage   74.25%   75.69%   +1.44%     
==========================================
  Files          50       51       +1     
  Lines        1503     1576      +73     
==========================================
+ Hits         1116     1193      +77     
+ Misses        387      383       -4
Impacted Files Coverage Δ
commons_api/wikidata/utils.py 83.8% <100%> (+11.67%) ⬆️
commons_api/wikidata/tests/__init__.py 100% <100%> (ø) ⬆️
commons_api/settings.py 82.5% <100%> (+0.44%) ⬆️
commons_api/wikidata/tests/wdqs_rate_limiting.py 100% <100%> (ø)
commons_api/wikidata/tests/updating.py 100% <100%> (ø) ⬆️
commons_api/wikidata/tasks/wikidata_item.py 95.65% <100%> (+0.19%) ⬆️
commons_api/wikidata/tasks/country.py 43.75% <80%> (+5.65%) ⬆️
commons_api/wikidata/tasks/legislature.py 12.69% <87.5%> (-0.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 396f347...dfedd3e. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants