Skip to content

Commit

Permalink
Replace ElementsAPICall model with a celery task to patch update an E… (
Browse files Browse the repository at this point in the history
#173)

Replace ElementsAPICall model with a celery task to patch update an Elements record. Delete elements models and make database migration. Update tests.
  • Loading branch information
hakbailey committed Jan 9, 2020
1 parent e8252af commit dd81735
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 639 deletions.
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ python_version = "3.7"
[dev-packages]
coverage = ">=4.5.1"
freezegun = "*"
requests-mock = "*"

[packages]
# Only needed for Heroku
Expand All @@ -32,3 +33,5 @@ newrelic = "*"
whitenoise = "*"
Pillow = "*"
sentry-sdk = "*"
celery = "*"
redis = "*"
121 changes: 121 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions solenoid/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ('celery_app',)
14 changes: 14 additions & 0 deletions solenoid/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'solenoid.settings.base')

app = Celery('solenoid')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
50 changes: 0 additions & 50 deletions solenoid/elements/admin.py

This file was deleted.

10 changes: 10 additions & 0 deletions solenoid/elements/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Error(Exception):
"""Base class for exceptions in this module."""
pass


class RetryError(Error):
"""Exception raised for HTTP status codes that indicate a Symplectic
Elements API call should be retried (409, 500, 504).
"""
pass
24 changes: 24 additions & 0 deletions solenoid/elements/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from xml.etree.ElementTree import Element, SubElement

from django.utils import timezone


def make_xml(username):
top = Element('update-object')
top.set('xmlns', 'http://www.symplectic.co.uk/publications/api')
oa_field = SubElement(top, 'oa')

# Update library status field
status_field = SubElement(oa_field, 'library-status')
status_field.set('status', 'full-text-requested')
date_field = SubElement(status_field, 'last-requested-when')
date_field.text = timezone.now().isoformat()
note_field = SubElement(status_field, 'note-field')
note_field.set('clear-existing-note', 'true')
note = SubElement(note_field, 'note')
note.text = "Library status changed to Full text requested on " \
"{date} by {username}.".format(
date=timezone.now().strftime('%-d %B %Y'),
username=username)

return top
21 changes: 0 additions & 21 deletions solenoid/elements/management/commands/delete_stale_api_calls.py

This file was deleted.

26 changes: 0 additions & 26 deletions solenoid/elements/management/commands/issue_unsent_calls.py

This file was deleted.

16 changes: 16 additions & 0 deletions solenoid/elements/migrations/0003_delete_elementsapicall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.7 on 2019-11-21 19:56

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('elements', '0002_auto_20180308_1812'),
]

operations = [
migrations.DeleteModel(
name='ElementsAPICall',
),
]
Loading

0 comments on commit dd81735

Please sign in to comment.