1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-10 15:16:02 +02:00

Compare commits

..

9 Commits

Author SHA1 Message Date
15c3299b99 CHANGELOG.md: Add changes for v0.6.0 2018-10-31 19:26:45 +02:00
d36be5ee50 contrib: Update systemd unit files for refactor 2018-10-28 11:14:21 +02:00
2f45d27554 dspace_statistics_api/app.py: remove unused code
This was added accidentally when I refactored. I was trying to see
if I could use Falcon's on_exit() hook.
2018-10-28 11:14:21 +02:00
b8356f7a87 Add "application" alias to API object
By default gunicorn looks for an "application" object to run, so this
saves us having to type api:app.
2018-10-28 11:14:21 +02:00
2136dc79ce Remove shebang from indexer.py
This is run as a Python module now so does not need a shebang.
2018-10-28 11:14:21 +02:00
ed60120cef Remove executable bit from indexer.py
Now it is run as a Python module.
2018-10-28 11:14:21 +02:00
c027f01b48 Refactor project structure
This follows guidance from several well-known Python best practices
guides. Basically, the idea is create a package for the application
that is comprised of several re-usable modules.

See: https://docs.python-guide.org/writing/structure/
See: https://realpython.com/python-application-layouts/
2018-10-28 11:14:21 +02:00
754663f062 CHANGELOG.md: Add changes for version 0.5.2 2018-10-28 11:12:27 +02:00
507699e58a requirements.txt: Update libraries
Switch to a personal fork of SolrClient so that we can use kazoo 2.5.0
and get rid of the error about the 'async' keyword on Python 3.7. Also
this bumps some of the other libraries to their latest versions.
2018-10-28 11:09:47 +02:00
11 changed files with 25 additions and 21 deletions

View File

@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### [0.6.0] - 2018-10-31
## Changed
- Refactor project structure (note breaking changes to API and indexing invocation, see contrib and README.md)
### [0.5.2] - 2018-10-28
## Changed
- Update library versions in requirements.txt
### [0.5.1] - 2018-10-24 ### [0.5.1] - 2018-10-24
## Changed ## Changed
- Use Python's native json instead of ujson - Use Python's native json instead of ujson

View File

@ -24,11 +24,11 @@ Set up the environment variables for Solr and PostgreSQL:
Index the Solr statistics core to populate the PostgreSQL database: Index the Solr statistics core to populate the PostgreSQL database:
$ ./indexer.py $ python -m dspace_statistics_api.indexer
Run the REST API: Run the REST API:
$ gunicorn app:api $ gunicorn dspace_statistics_api.app
Test to see if there are any statistics: Test to see if there are any statistics:

View File

@ -12,7 +12,7 @@ Group=nogroup
WorkingDirectory=/var/lib/dspace-statistics-api WorkingDirectory=/var/lib/dspace-statistics-api
ExecStart=/var/lib/dspace-statistics-api/venv/bin/gunicorn \ ExecStart=/var/lib/dspace-statistics-api/venv/bin/gunicorn \
--bind 127.0.0.1:5000 \ --bind 127.0.0.1:5000 \
app:api dspace_statistics_api.app
ExecReload=/bin/kill -s HUP $MAINPID ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID ExecStop=/bin/kill -s TERM $MAINPID

View File

@ -11,7 +11,7 @@ Environment=DATABASE_HOST=localhost
User=nobody User=nobody
Group=nogroup Group=nogroup
WorkingDirectory=/var/lib/dspace-statistics-api WorkingDirectory=/var/lib/dspace-statistics-api
ExecStart=/var/lib/dspace-statistics-api/venv/bin/python indexer.py ExecStart=/var/lib/dspace-statistics-api/venv/bin/python -m dspace_statistics_api.indexer
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

View File

@ -1,4 +1,4 @@
from database import database_connection from .database import database_connection
import falcon import falcon
db = database_connection() db = database_connection()
@ -63,10 +63,7 @@ class ItemResource:
cursor.close() cursor.close()
def on_exit(api): api = application = falcon.API()
print("Shutting down DB")
api = falcon.API()
api.add_route('/items', AllItemsResource()) api.add_route('/items', AllItemsResource())
api.add_route('/item/{item_id:int}', ItemResource()) api.add_route('/item/{item_id:int}', ItemResource())

View File

@ -1,7 +1,7 @@
from config import DATABASE_NAME from .config import DATABASE_NAME
from config import DATABASE_USER from .config import DATABASE_USER
from config import DATABASE_PASS from .config import DATABASE_PASS
from config import DATABASE_HOST from .config import DATABASE_HOST
import psycopg2, psycopg2.extras import psycopg2, psycopg2.extras
def database_connection(): def database_connection():

5
indexer.py → dspace_statistics_api/indexer.py Executable file → Normal file
View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# #
# indexer.py # indexer.py
# #
@ -30,10 +29,10 @@
# See: https://solrclient.readthedocs.io/en/latest/SolrClient.html # See: https://solrclient.readthedocs.io/en/latest/SolrClient.html
# See: https://wiki.duraspace.org/display/DSPACE/Solr # See: https://wiki.duraspace.org/display/DSPACE/Solr
from database import database_connection from .database import database_connection
import json import json
import psycopg2.extras import psycopg2.extras
from solr import solr_connection from .solr import solr_connection
def index_views(): def index_views():
# get total number of distinct facets for items with a minimum of 1 view, # get total number of distinct facets for items with a minimum of 1 view,

View File

@ -1,4 +1,4 @@
from config import SOLR_SERVER from .config import SOLR_SERVER
from SolrClient import SolrClient from SolrClient import SolrClient
def solr_connection(): def solr_connection():

View File

@ -1,4 +1,4 @@
certifi==2018.8.24 certifi==2018.10.15
chardet==3.0.4 chardet==3.0.4
falcon==1.4.1 falcon==1.4.1
gunicorn==19.9.0 gunicorn==19.9.0
@ -6,7 +6,7 @@ idna==2.7
kazoo==2.5.0 kazoo==2.5.0
psycopg2-binary==2.7.5 psycopg2-binary==2.7.5
python-mimeparse==1.6.0 python-mimeparse==1.6.0
requests==2.19.1 requests==2.20.0
six==1.11.0 six==1.11.0
SolrClient==0.2.1 -e git://github.com/alanorth/SolrClient.git@c629e3475be37c82770b2be61748be7e29882648#egg=SolrClient
urllib3==1.23 urllib3==1.24