Make tox lin environment workable
This commit is contained in:
parent
90528fcd70
commit
4962633c64
|
@ -15,6 +15,7 @@ from sqlalchemy import Column, Integer, String, Float
|
|||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Fractal(Base):
|
||||
__tablename__ = 'fractals'
|
||||
|
||||
|
|
|
@ -35,10 +35,12 @@ def initialize_logging():
|
|||
def parse_command_line_arguments():
|
||||
"""Parse the command line arguments."""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
parser.add_argument("--database-url", type=str, help="database connection URL",
|
||||
default="mysql://tutorial:secretsecret@localhost:3306/tutorial")
|
||||
parser.add_argument(
|
||||
"--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
parser.add_argument(
|
||||
"--database-url", type=str, help="database connection URL",
|
||||
default="mysql://tutorial:secretsecret@localhost:3306/tutorial")
|
||||
parser.add_argument("--max-height", type=int, default=1024,
|
||||
help="The maximum height of the generate image.")
|
||||
parser.add_argument("--max-width", type=int, default=1024,
|
||||
|
@ -100,6 +102,7 @@ def generate_task(args):
|
|||
'yb': yb
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
initialize_logging()
|
||||
args = parse_command_line_arguments()
|
||||
|
@ -118,20 +121,27 @@ def main():
|
|||
random.seed()
|
||||
number = random.randint(args.min_tasks, args.max_tasks)
|
||||
logging.info("generating %d task(s)" % number)
|
||||
for i in xrange(0,number):
|
||||
for i in xrange(0, number):
|
||||
task = generate_task(args)
|
||||
fractal = models.Fractal(uuid=task['uuid'], width=task['width'],
|
||||
height=task['height'], xa=task['xa'],
|
||||
xb=task['xb'], ya=task['ya'], yb=task['yb'],
|
||||
iterations=task['iterations'])
|
||||
fractal = models.Fractal(
|
||||
uuid=task['uuid'],
|
||||
width=task['width'],
|
||||
height=task['height'],
|
||||
xa=task['xa'],
|
||||
xb=task['xb'],
|
||||
ya=task['ya'],
|
||||
yb=task['yb'],
|
||||
iterations=task['iterations'])
|
||||
session.add(fractal)
|
||||
session.commit()
|
||||
logging.info("generated task: %s" % task)
|
||||
with producers[connection].acquire(block=True) as producer:
|
||||
producer.publish(task, serializer='pickle',
|
||||
exchange=queues.task_exchange,
|
||||
declare=[queues.task_exchange],
|
||||
routing_key='tasks')
|
||||
producer.publish(
|
||||
task,
|
||||
serializer='pickle',
|
||||
exchange=queues.task_exchange,
|
||||
declare=[queues.task_exchange],
|
||||
routing_key='tasks')
|
||||
|
||||
pause = random.uniform(args.min_pause, args.max_pause)
|
||||
logging.info("sleeping for %f seconds" % pause)
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from kombu import Exchange, Queue
|
||||
from kombu import Exchange
|
||||
from kombu import Queue
|
||||
|
||||
task_exchange = Exchange('tasks', type='direct')
|
||||
task_queues = [Queue('tasks', task_exchange, routing_key='tasks')]
|
||||
|
|
|
@ -16,11 +16,10 @@
|
|||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from kombu.mixins import ConsumerMixin
|
||||
import kombu
|
||||
from kombu.mixins import ConsumerMixin
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
@ -38,7 +37,6 @@ class Tracker(ConsumerMixin):
|
|||
maker = sessionmaker(bind=engine)
|
||||
self.session = maker()
|
||||
|
||||
|
||||
def get_consumers(self, Consumer, channel):
|
||||
return [Consumer(queues=queues.result_queues,
|
||||
accept=['pickle', 'json'],
|
||||
|
@ -49,11 +47,12 @@ class Tracker(ConsumerMixin):
|
|||
logging.info("elapsed time %f seconds" % body['duration'])
|
||||
logging.info("checksum %s" % body['checksum'])
|
||||
try:
|
||||
fractal = self.session.query(models.Fractal).filter(models.Fractal.uuid == str(body['uuid'])).one()
|
||||
fractal = self.session.query(models.Fractal).filter(
|
||||
models.Fractal.uuid == str(body['uuid'])).one()
|
||||
fractal.duration = body['duration']
|
||||
fractal.checksum = body['checksum']
|
||||
self.session.commit()
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
message.ack()
|
||||
|
||||
|
@ -65,10 +64,12 @@ def initialize_logging():
|
|||
def parse_command_line_arguments():
|
||||
"""Parse the command line arguments."""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
parser.add_argument("--database-url", type=str, help="database connection URL",
|
||||
default="mysql://tutorial:secretsecret@localhost:3306/tutorial")
|
||||
parser.add_argument(
|
||||
"--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
parser.add_argument(
|
||||
"--database-url", type=str, help="database connection URL",
|
||||
default="mysql://tutorial:secretsecret@localhost:3306/tutorial")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
|
|
@ -23,13 +23,14 @@ import random
|
|||
import sys
|
||||
import time
|
||||
|
||||
from kombu.mixins import ConsumerMixin
|
||||
import kombu
|
||||
from kombu.mixins import ConsumerMixin
|
||||
from kombu.pools import producers
|
||||
|
||||
import queues
|
||||
|
||||
class JuliaSet:
|
||||
|
||||
class JuliaSet(object):
|
||||
|
||||
def __init__(self, width, height, xa=-2.0, xb=2.0, ya=-1.5, yb=1.5,
|
||||
iterations=255):
|
||||
|
@ -99,7 +100,8 @@ class Worker(ConsumerMixin):
|
|||
logging.info("task %s processed in %f seconds" %
|
||||
(body['uuid'], elapsed_time))
|
||||
juliaset.save(filename)
|
||||
logging.info("saved result of task %s to file %s" % (body['uuid'], filename))
|
||||
logging.info("saved result of task %s to file %s" %
|
||||
(body['uuid'], filename))
|
||||
checksum = hashlib.sha256(open(filename, 'rb').read()).hexdigest()
|
||||
result = {
|
||||
'uuid': body['uuid'],
|
||||
|
@ -123,10 +125,12 @@ def initialize_logging():
|
|||
def parse_command_line_arguments():
|
||||
"""Parse the command line arguments."""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--target", type=str, help="Target directory",
|
||||
default="/home/vagrant")
|
||||
parser.add_argument("--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
parser.add_argument(
|
||||
"--target", type=str, help="Target directory",
|
||||
default="/home/vagrant")
|
||||
parser.add_argument(
|
||||
"--amqp-url", type=str, help="AMQP connection URL",
|
||||
default="amqp://tutorial:secretsecret@localhost:5672//")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
hacking
|
||||
pbr>=0.6,!=0.7,<1.0
|
||||
tox
|
||||
|
|
Loading…
Reference in New Issue