kopia lustrzana https://github.com/osm2vectortiles/osm2vectortiles
Read jobs from sqs
rodzic
0934a6ed82
commit
b6e538ba40
|
@ -17,8 +17,11 @@ Options:
|
|||
--tm2source=<tm2source> Directory of tm2source
|
||||
"""
|
||||
import subprocess
|
||||
import os
|
||||
import os.path
|
||||
import json
|
||||
|
||||
import boto.sqs
|
||||
from docopt import docopt
|
||||
|
||||
|
||||
|
@ -58,6 +61,47 @@ def export_local(tilelive_command):
|
|||
cmd=tilelive_command)
|
||||
|
||||
|
||||
def connect_job_queue(queue_name):
|
||||
conn = boto.sqs.connect_to_region(
|
||||
region_name=os.getenv('AWS_REGION', 'eu-central-1'),
|
||||
aws_access_key_id=os.environ['AWS_ACCESS_KEY'],
|
||||
aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY']
|
||||
)
|
||||
queue = conn.get_queue(queue_name)
|
||||
return queue
|
||||
|
||||
|
||||
def export_remote(tm2source, sqs_queue, render_scheme):
|
||||
timeout = int(os.getenv('JOB_TIMEOUT', 15 * 60))
|
||||
queue = connect_job_queue(sqs_queue)
|
||||
|
||||
while True:
|
||||
message = queue.read(visibility_timeout=timeout)
|
||||
print(message)
|
||||
if message:
|
||||
body = json.loads(message.get_body())
|
||||
print(body)
|
||||
|
||||
bounds = body['bounds']
|
||||
bbox = '{} {} {} {}'.format(
|
||||
bounds[0][0], bounds[0][1],
|
||||
bounds[1][0], bounds[1][1]
|
||||
)
|
||||
mbtiles_file = '{}_{}.mbtiles'.format(body['x'], body['y'])
|
||||
|
||||
tilelive_command = create_tilelive_command(
|
||||
tm2source,
|
||||
mbtiles_file,
|
||||
bbox,
|
||||
body['min_zoom'],
|
||||
body['max_zoom'],
|
||||
render_scheme
|
||||
)
|
||||
export_local(tilelive_command)
|
||||
print("Executed job and exportet to " + mbtiles_file)
|
||||
queue.delete_message(message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
arguments = docopt(__doc__, version='0.1')
|
||||
print(arguments)
|
||||
|
@ -71,3 +115,10 @@ if __name__ == '__main__':
|
|||
arguments['--render_scheme']
|
||||
)
|
||||
export_local(tilelive_command)
|
||||
|
||||
if arguments.get('remote'):
|
||||
export_remote(
|
||||
arguments['--tm2source'],
|
||||
arguments['<sqs_queue>'],
|
||||
arguments['--render_scheme']
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue