-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add queue and start one-time mapping pipeline.
- Loading branch information
1 parent
1ade58d
commit df016de
Showing
5 changed files
with
116 additions
and
7 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
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 |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -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()) | ||
|
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,5 @@ | ||
queue: | ||
- name: map-queue | ||
mode: push | ||
max_concurrent_requests: 5 | ||
rate: 1/s |
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,9 @@ | ||
runtime: python27 | ||
api_version: 1 | ||
threadsafe: true | ||
module: worker | ||
|
||
handlers: | ||
- url: /.* | ||
script: run.app | ||
login: admin |