1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-13 00:17:47 +02:00

Compare commits

...

7 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
10 changed files with 17 additions and 17 deletions

View File

@ -4,6 +4,10 @@ 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 ### [0.5.2] - 2018-10-28
## Changed ## Changed
- Update library versions in requirements.txt - Update library versions in requirements.txt

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():