mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-05-13 16:37:46 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
62142eb79e
|
|||
fda0321942
|
|||
963aa245c8
|
|||
568ff2eebb
|
|||
deecb8a10b
|
|||
12f45d7c08
|
@ -4,6 +4,13 @@ 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.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
|
### [0.4.3] - 2018-10-17
|
||||||
## Changed
|
## Changed
|
||||||
- Use pip install as script for Travis CI
|
- 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'
|
$ curl 'http://localhost:8000/items?limit=1'
|
||||||
|
|
||||||
## Deployment
|
## 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
|
## Using the API
|
||||||
The API exposes the following endpoints:
|
The API exposes the following endpoints:
|
||||||
|
5
app.py
5
app.py
@ -1,10 +1,8 @@
|
|||||||
from database import database_connection
|
from database import database_connection
|
||||||
import falcon
|
import falcon
|
||||||
from solr import solr_connection
|
|
||||||
|
|
||||||
db = database_connection()
|
db = database_connection()
|
||||||
db.set_session(readonly=True)
|
db.set_session(readonly=True)
|
||||||
solr = solr_connection()
|
|
||||||
|
|
||||||
class AllItemsResource:
|
class AllItemsResource:
|
||||||
def on_get(self, req, resp):
|
def on_get(self, req, resp):
|
||||||
@ -65,6 +63,9 @@ class ItemResource:
|
|||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
def on_exit(api):
|
||||||
|
print("Shutting down DB")
|
||||||
|
|
||||||
api = falcon.API()
|
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())
|
||||||
|
@ -9,8 +9,8 @@ Environment=DATABASE_PASS=dspacestatistics
|
|||||||
Environment=DATABASE_HOST=localhost
|
Environment=DATABASE_HOST=localhost
|
||||||
User=nobody
|
User=nobody
|
||||||
Group=nogroup
|
Group=nogroup
|
||||||
WorkingDirectory=/opt/ilri/dspace-statistics-api
|
WorkingDirectory=/var/lib/dspace-statistics-api
|
||||||
ExecStart=/opt/ilri/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
|
app:api
|
||||||
ExecReload=/bin/kill -s HUP $MAINPID
|
ExecReload=/bin/kill -s HUP $MAINPID
|
||||||
|
@ -10,8 +10,8 @@ Environment=DATABASE_PASS=dspacestatistics
|
|||||||
Environment=DATABASE_HOST=localhost
|
Environment=DATABASE_HOST=localhost
|
||||||
User=nobody
|
User=nobody
|
||||||
Group=nogroup
|
Group=nogroup
|
||||||
WorkingDirectory=/opt/ilri/dspace-statistics-api
|
WorkingDirectory=/var/lib/dspace-statistics-api
|
||||||
ExecStart=/opt/ilri/dspace-statistics-api/venv/bin/python indexer.py
|
ExecStart=/var/lib/dspace-statistics-api/venv/bin/python indexer.py
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
Reference in New Issue
Block a user