Skip to content

Commit

Permalink
add queue and start one-time mapping pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielecook committed Dec 2, 2016
1 parent 1ade58d commit df016de
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ script:

deploy:
provider: gae
version: version-1-0-5
version: version-1-0-6
project: andersen-lab
keyfile: client-secret.json
on: master
Expand Down
3 changes: 0 additions & 3 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ threadsafe: yes

# Handlers define how to route requests to your application.
handlers:
- url: /order/.*
secure: always
script: run.app
- url: /.*
script: run.app # a WSGI application in the main module's global scope

Expand Down
104 changes: 101 additions & 3 deletions cendr/cegwas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,107 @@
from werkzeug.contrib.atom import AtomFeed
from urlparse import urljoin

import string
import random

def id_generator(size = 4, chars = string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))

from google.appengine.api import taskqueue

def create_mapping_instance(report_slug, trait_slug):
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
from googleapiclient import discovery
compute = discovery.build('compute', 'v1', credentials=credentials)

# Get latest CeNDR mapping image
image_response = compute.images().getFromFamily(project='andersen-lab',
family = 'cendr').execute()
source_disk_image = image_response['selfLink']

#startup_script = open(
# os.path.join(
# os.path.dirname(__file__), 'startup-script.sh'), 'r').read()
startup_script = '#! /bin/bash\n\nsleep 10s && gcloud -q compute instances delete --zone=us-central1-a `hostname`'

config = {
'name': 'cendr-mapping-submission-' + id_generator(4),
'zone': 'projects/andersen-lab/zones/us-central1-a',
'machineType': "zones/us-central1-a/machineTypes/n1-standard-1",
'tags': {
"items": ['cendr-mapping']
},
# Specify the boot disk and the image to use as a source.
'disks': [
{
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': source_disk_image,
'diskType': "projects/andersen-lab/zones/us-central1-a/diskTypes/pd-standard",
'diskSizeGb': "10"
}
}
],

# Specify a network interface with NAT to access the public
# internet.
'networkInterfaces': [{
'network': 'projects/andersen-lab/global/networks/default',
'accessConfigs': [
{
"name": "External NAT",
"type": "ONE_TO_ONE_NAT"
}
]
}],

# Allow the instance to access cloud storage and logging.
'serviceAccounts': [{
'email': '[email protected]',
'scopes': [
'https://www.googleapis.com/auth/devstorage.read_write',
'https://www.googleapis.com/auth/logging.write',
'https://www.googleapis.com/auth/compute'
]
}],

# Metadata is readable from the instance and allows you to
# pass configuration from deployment scripts to instances.
'metadata': {
'items': [{
# Startup script is automatically executed by the
# instance upon startup.
'key': 'startup-script',
'value': startup_script
}, {
'key': 'report_slug',
'value': report_slug
},
{
'key': 'trait_slug',
'value': trait_slug
}]
}
}

return compute.instances().insert(
project='andersen-lab',
zone='us-central1-a',
body=config).execute()


@app.route("/launch_instance", methods=['POST'])
def task_test():
print "Great"

def create_task():
task = taskqueue.add(queue_name = 'map-queue', url='/launch_instance')
#queue = taskqueue.Queue(name='map-queue')
#queue.add_async(task)


def make_external(url):
return urljoin(request.url_root, url)

Expand All @@ -33,9 +134,6 @@ def sortedfiles(path):
def main():
page_title = "Caenorhabditis elegans Natural Diversity Resource"
files = sortedfiles("cendr/static/content/news/")
print(files)
#files.reverse()
# latest mappings
latest_mappings = list(report.filter(report.release == 0, trait.status == "complete").join(trait).order_by(
trait.submission_complete.desc()).limit(5).select(report, trait).distinct().dicts().execute())
return render_template('home.html', **locals())
Expand Down
5 changes: 5 additions & 0 deletions queue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
queue:
- name: map-queue
mode: push
max_concurrent_requests: 5
rate: 1/s
9 changes: 9 additions & 0 deletions worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
runtime: python27
api_version: 1
threadsafe: true
module: worker

handlers:
- url: /.*
script: run.app
login: admin

0 comments on commit df016de

Please sign in to comment.