forked from CenterForOpenScience/osf-pigeon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-2581][ENG-2578][ENG-2577][ENG-2340] Pigeon becomes a microservice (
CenterForOpenScience#25) * Implement updated Pigeon spec; run Pigeon as a microservice
- Loading branch information
1 parent
66f20e6
commit 7a7275d
Showing
24 changed files
with
6,387 additions
and
1,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# New tokens can be found at https://archive.org/account/s3.php | ||
IA_ACCESS_KEY = None | ||
IA_SECRET_KEY = None | ||
|
||
OSF_BEARER_TOKEN = None | ||
|
||
DATACITE_USERNAME = None | ||
DATACITE_PASSWORD = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ignore Everything | ||
** | ||
|
||
# Except for what's necessary | ||
!requirements.txt | ||
!osf_pigeon/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM python:3.7-alpine as base | ||
|
||
|
||
# Install requirements | ||
COPY requirements.txt . | ||
RUN apk add --no-cache --virtual .build-deps \ | ||
python3-dev \ | ||
gcc \ | ||
alpine-sdk \ | ||
musl-dev \ | ||
libxslt-dev \ | ||
libxml2 \ | ||
&& pip install -r requirements.txt \ | ||
&& apk del .build-deps | ||
|
||
# Install application into container | ||
COPY . . | ||
|
||
ENTRYPOINT ["python", "-m", "osf_pigeon"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
|
||
pigeon: | ||
build: . | ||
restart: unless-stopped | ||
ports: | ||
- 2020:2020 | ||
env_file: | ||
- .docker-compose.env | ||
stdin_open: true | ||
volumes: | ||
- /srv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,66 @@ | ||
import os | ||
import argparse | ||
from osf_pigeon.pigeon import main | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'-g', | ||
'--guid', | ||
help='This is the GUID of the target node on the OSF', | ||
required=True | ||
) | ||
parser.add_argument( | ||
'-d', | ||
'--datacite_password', | ||
help='This is the password for using datacite\'s api', | ||
required=False | ||
) | ||
parser.add_argument( | ||
'-u', | ||
'--datacite_username', | ||
help='This is the username for using datacite\'s api', | ||
required=False | ||
) | ||
parser.add_argument( | ||
'-a', | ||
'--ia_access_key', | ||
help='This is the access key for using Internet Archive\'s api', | ||
required=False | ||
) | ||
parser.add_argument( | ||
'-s', | ||
'--ia_secret_key', | ||
help='This is the secret key for using Internet Archive\'s api', | ||
required=False | ||
) | ||
import requests | ||
from sanic import Sanic | ||
from sanic.response import json | ||
from osf_pigeon import pigeon | ||
from concurrent.futures import ThreadPoolExecutor | ||
from sanic.log import logger | ||
|
||
|
||
app = Sanic("osf_pigeon") | ||
pigeon_jobs = ThreadPoolExecutor(max_workers=10, thread_name_prefix="pigeon_jobs") | ||
|
||
|
||
def task_done(future): | ||
if future.exception(): | ||
exception = future.exception() | ||
exception = str(exception) | ||
logger.debug(f"ERROR:{exception}") | ||
if future.result(): | ||
guid, url = future.result() | ||
resp = requests.post( | ||
f"{settings.OSF_API_URL}_/ia/{guid}/done/", json={"IA_url": url} | ||
) | ||
logger.debug(f"DONE:{future._result} Response:{resp}") | ||
|
||
|
||
@app.route("/") | ||
async def index(request): | ||
return json({"🐦": "👍"}) | ||
|
||
|
||
@app.route("/archive/<guid>", methods=["GET", "POST"]) | ||
async def archive(request, guid): | ||
future = pigeon_jobs.submit(pigeon.run, pigeon.archive(guid)) | ||
future.add_done_callback(task_done) | ||
return json({guid: future._state}) | ||
|
||
|
||
@app.route("/metadata/<guid>", methods=["POST"]) | ||
async def set_metadata(request, guid): | ||
item_name = pigeon.REG_ID_TEMPLATE.format(guid=guid) | ||
future = pigeon_jobs.submit(pigeon.sync_metadata, item_name, request.json) | ||
future.add_done_callback(task_done) | ||
return json({guid: future._state}) | ||
|
||
|
||
parser = argparse.ArgumentParser( | ||
description="Set the environment to run OSF pigeon in." | ||
) | ||
parser.add_argument( | ||
"--env", dest="env", help="what environment are you running this for" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
guid = args.guid | ||
datacite_password = args.datacite_password | ||
datacite_username = args.datacite_username | ||
ia_access_key = args.ia_access_key | ||
ia_secret_key = args.ia_secret_key | ||
main( | ||
guid, | ||
datacite_password=datacite_password, | ||
datacite_username=datacite_username, | ||
ia_access_key=ia_access_key, | ||
ia_secret_key=ia_secret_key | ||
) | ||
if args.env: | ||
os.environ["ENV"] = args.env | ||
|
||
from osf_pigeon import settings | ||
|
||
if args.env == "production": | ||
app.run(host=settings.HOST, port=settings.PORT) | ||
else: | ||
app.run(host=settings.HOST, port=settings.PORT, auto_reload=True, debug=True) |
Oops, something went wrong.