Created
May 28, 2012 07:20
-
-
Save longfin/2817829 to your computer and use it in GitHub Desktop.
2012-05-29
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
@admin.route('/stores/<place:place>/pdf') | |
def pdf_creation_request(place): | |
pdf_stream = place.get_pdf() | |
headers = {} | |
headers["Content-Disposition"] = u'attachment; filename="{0}.pdf"' \ | |
.format(place.name).encode("utf-8") | |
headers["Content-Type"] = "application/pdf" | |
headers["Cache-Control"] = "no-cache" | |
return Response(pdf_stream, headers=headers) |
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
# task | |
@task | |
def pdf_creation_task(place_id): | |
place = Place.query.get(place_id) | |
pdf_stream = place.get_pdf() | |
key = upload_to_s3(pdf_stream, "{0}.pdf".format(place.name), | |
{'Content-Type': 'application/pdf'}) | |
place.pdf_archive = key.url | |
# handler | |
@admin.route('/stores/<place:place>/pdf') | |
def pdf_creation_request(place): | |
pdf_creation_task.delay(place.id) | |
return jsonify(dict(result='success')) |
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
2012-05-18T13:46:26+00:00 heroku[web.1]: Error R14 (Memory quota exceeded) |
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
# task | |
@task | |
def pdf_creation_task(place_id): | |
place = Place.query.get(place_id) | |
result = [] | |
for pdf_chunk in place.get_pdf_chunks(250): | |
result.append(pdf_partial_creation_task.delay(pdf_chunk).get()) | |
zipped_stream = zip_stream(result) | |
key = upload_to_s3(zipped_stream, "{0}.zip".format(place.name), | |
{'Content-Type': 'application/x-zip'}) | |
place.pdf_archive = key.url | |
@task | |
def pdf_partial_creation_task(pdf_chunk): | |
pdf_stream = pdf_chunk.get_pdf() | |
key = upload_to_s3(pdf_stream, "{0}.pdf".format(place.name), | |
{'Content-Type': 'application/pdf'}) | |
return key.url |
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
@task | |
def pdf_creation_task(place_id): | |
place = Place.query.get(place_id) | |
creation_chord = chord([pdf_partial_creation_task.subtask((pdf_chunk)) \ | |
for pdf_chunk in place.get_pdf_chunks(250)]) | |
creation_chords(pdf_archive_task.subtask(place_id=place_id)) | |
@task | |
def pdf_partial_creation_task(pdf_chunk): | |
pdf_stream = pdf_chunk.get_pdf() | |
key = upload_to_s3(pdf_stream, "{0}.pdf".format(place.name), | |
{'Content-Type': 'application/pdf'}) | |
return key.url | |
@task | |
def pdf_archive_task(urls, place_id): | |
place = Place.query.get(place_id) | |
zipped_stream = zip_stream(urls) | |
key = upload_to_s3(zipped_stream, "{0}.zip".format(place.name), | |
{'Content-Type': 'application/x-zip'}) | |
place.pdf_archive = key.url |
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
def scale_worker(size): | |
if hasattr(config, "HEROKU_API_KEY"): | |
try: | |
cloud = heroku.from_key(config.HEROKU_API_KEY) | |
app = cloud.apps[config.HEROKU_APP_NAME] | |
worker = app.processes["worker"] | |
worker.scale(size) | |
except KeyError: | |
pass |
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
@task | |
def pdf_creation_task(place_id): | |
place = Place.query.get(place_id) | |
creation_chord = chord([pdf_partial_creation_task.subtask((pdf_chunk)) \ | |
for pdf_chunk in place.get_pdf_chunks(250)]) | |
creation_chord(pdf_archive_task.subtask(place_id=place_id)) | |
# scale up worker... | |
scale_worker('+{0}'.format(len(creation_chord.tasks))) | |
@task | |
def pdf_partial_creation_task(pdf_chunk): | |
pdf_stream = pdf_chunk.get_pdf() | |
key = upload_to_s3(pdf_stream, "{0}.pdf".format(place.name), | |
{'Content-Type': 'application/pdf'}) | |
return key.url | |
@task | |
def pdf_archive_task(urls, place_id): | |
place = Place.query.get(place_id) | |
zipped_stream = zip_stream(urls) | |
key = upload_to_s3(zipped_stream, "{0}.zip".format(place.name), | |
{'Content-Type': 'application/x-zip'}) | |
place.pdf_archive = key.url | |
# scale down worker... | |
scale_worker('-{0}'.format(len(urls))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment