mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-05-10 15:16:02 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
754663f062
|
|||
507699e58a
|
|||
a016916995
|
|||
6fd2827a7c
|
|||
62142eb79e
|
|||
fda0321942
|
|||
963aa245c8
|
|||
568ff2eebb
|
|||
deecb8a10b
|
|||
12f45d7c08
|
15
CHANGELOG.md
15
CHANGELOG.md
@ -4,6 +4,21 @@ 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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
### [0.5.2] - 2018-10-28
|
||||
## Changed
|
||||
- Update library versions in requirements.txt
|
||||
|
||||
### [0.5.1] - 2018-10-24
|
||||
## Changed
|
||||
- Use Python's native json instead of ujson
|
||||
|
||||
### [0.5.0] - 2018-10-24
|
||||
## Added
|
||||
- Example nginx configuration to README.md
|
||||
|
||||
## Changed
|
||||
- Don't initialize Solr connection in API
|
||||
|
||||
### [0.4.3] - 2018-10-17
|
||||
## Changed
|
||||
- Use pip install as script for Travis CI
|
||||
|
21
README.md
21
README.md
@ -35,7 +35,26 @@ Test to see if there are any statistics:
|
||||
$ curl 'http://localhost:8000/items?limit=1'
|
||||
|
||||
## Deployment
|
||||
There are example systemd service and timer units in the `contrib` directory.
|
||||
There are example systemd service and timer units in the `contrib` directory. The API service listens on localhost by default so you will need to expose it publicly using a web server like nginx.
|
||||
|
||||
An example nginx configuration is:
|
||||
|
||||
```
|
||||
server {
|
||||
#...
|
||||
|
||||
location ~ /rest/statistics/?(.*) {
|
||||
access_log /var/log/nginx/statistics.log;
|
||||
proxy_pass http://statistics_api/$1$is_args$args;
|
||||
}
|
||||
}
|
||||
|
||||
upstream statistics_api {
|
||||
server 127.0.0.1:5000;
|
||||
}
|
||||
```
|
||||
|
||||
This would expose the API at `/rest/statistics`.
|
||||
|
||||
## Using the API
|
||||
The API exposes the following endpoints:
|
||||
|
5
app.py
5
app.py
@ -1,10 +1,8 @@
|
||||
from database import database_connection
|
||||
import falcon
|
||||
from solr import solr_connection
|
||||
|
||||
db = database_connection()
|
||||
db.set_session(readonly=True)
|
||||
solr = solr_connection()
|
||||
|
||||
class AllItemsResource:
|
||||
def on_get(self, req, resp):
|
||||
@ -65,6 +63,9 @@ class ItemResource:
|
||||
|
||||
cursor.close()
|
||||
|
||||
def on_exit(api):
|
||||
print("Shutting down DB")
|
||||
|
||||
api = falcon.API()
|
||||
api.add_route('/items', AllItemsResource())
|
||||
api.add_route('/item/{item_id:int}', ItemResource())
|
||||
|
@ -9,8 +9,8 @@ Environment=DATABASE_PASS=dspacestatistics
|
||||
Environment=DATABASE_HOST=localhost
|
||||
User=nobody
|
||||
Group=nogroup
|
||||
WorkingDirectory=/opt/ilri/dspace-statistics-api
|
||||
ExecStart=/opt/ilri/dspace-statistics-api/venv/bin/gunicorn \
|
||||
WorkingDirectory=/var/lib/dspace-statistics-api
|
||||
ExecStart=/var/lib/dspace-statistics-api/venv/bin/gunicorn \
|
||||
--bind 127.0.0.1:5000 \
|
||||
app:api
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
|
@ -10,8 +10,8 @@ Environment=DATABASE_PASS=dspacestatistics
|
||||
Environment=DATABASE_HOST=localhost
|
||||
User=nobody
|
||||
Group=nogroup
|
||||
WorkingDirectory=/opt/ilri/dspace-statistics-api
|
||||
ExecStart=/opt/ilri/dspace-statistics-api/venv/bin/python indexer.py
|
||||
WorkingDirectory=/var/lib/dspace-statistics-api
|
||||
ExecStart=/var/lib/dspace-statistics-api/venv/bin/python indexer.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
@ -31,7 +31,7 @@
|
||||
# See: https://wiki.duraspace.org/display/DSPACE/Solr
|
||||
|
||||
from database import database_connection
|
||||
import ujson
|
||||
import json
|
||||
import psycopg2.extras
|
||||
from solr import solr_connection
|
||||
|
||||
@ -56,7 +56,7 @@ def index_views():
|
||||
}, rows=0)
|
||||
|
||||
# get total number of distinct facets (countDistinct)
|
||||
results_totalNumFacets = ujson.loads(res.get_json())['stats']['stats_fields']['id']['countDistinct']
|
||||
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['id']['countDistinct']
|
||||
|
||||
# divide results into "pages" (cast to int to effectively round down)
|
||||
results_per_page = 100
|
||||
@ -115,7 +115,7 @@ def index_downloads():
|
||||
}, rows=0)
|
||||
|
||||
# get total number of distinct facets (countDistinct)
|
||||
results_totalNumFacets = ujson.loads(res.get_json())['stats']['stats_fields']['owningItem']['countDistinct']
|
||||
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['owningItem']['countDistinct']
|
||||
|
||||
# divide results into "pages" (cast to int to effectively round down)
|
||||
results_per_page = 100
|
||||
|
@ -1,4 +1,4 @@
|
||||
certifi==2018.8.24
|
||||
certifi==2018.10.15
|
||||
chardet==3.0.4
|
||||
falcon==1.4.1
|
||||
gunicorn==19.9.0
|
||||
@ -6,8 +6,7 @@ idna==2.7
|
||||
kazoo==2.5.0
|
||||
psycopg2-binary==2.7.5
|
||||
python-mimeparse==1.6.0
|
||||
requests==2.19.1
|
||||
requests==2.20.0
|
||||
six==1.11.0
|
||||
SolrClient==0.2.1
|
||||
ujson==1.35
|
||||
urllib3==1.23
|
||||
-e git://github.com/alanorth/SolrClient.git@c629e3475be37c82770b2be61748be7e29882648#egg=SolrClient
|
||||
urllib3==1.24
|
||||
|
Reference in New Issue
Block a user