Commit 85a02fce authored by Jerico Moeyersons 's avatar Jerico Moeyersons 🏘
Browse files

major bugfixes - application is now working

parent a477aef4
File added
This diff is collapsed.
......@@ -11,7 +11,7 @@ import exceptions
WORKER_URL = 'http://worker-'
DEFAULT_NETWORK = 'mandelbrot'
DEFAULT_NETWORK = 'mandelbrot-creator_mandelbrot'
WORKER_IMAGE_NAME = 'worker'
class Kernel(object):
......@@ -35,7 +35,7 @@ class Kernel(object):
# TODO: delete previous workers
for i in range(number):
for i in range(int(number)):
# Try to start a container with the process
try:
# Start a new container with the plugin process.
......@@ -71,7 +71,7 @@ class Kernel(object):
def start_worker(self, worker=None):
if worker is None:
url = "http://" + str(self.workers[self.next_worker].name)
url = "http://" + str(self.workers[self.next_worker].name) + "/start"
self.__set_next_worker()
else:
# TODO: check if worker exists
......@@ -96,23 +96,26 @@ class Kernel(object):
return True
def multiple_start(self, number):
if not self.active:
if number < self.workers:
with concurrent.futures.ThreadPoolExecutor(max_workers=number) as executor:
executor.submit(self.start_worker, self)
'''for i in range(1, number+1):
thread = Thread(target = start_worker, args = (i, ))
threads.append(thread)
thread.start()
for index, thread in enumerate(threads):
logging.info("Main : before joining thread %d.", index)
thread.join()
logging.info("Main : thread %d done", index)'''
else:
with concurrent.futures.ThreadPoolExecutor(max_workers=self.workers) as executor:
executor.submit(self.start_worker, self)
message = "All workers started and finished..."
if not self.active:
code = http.HTTPStatus.OK.value
message = "All workers started and finished..."
print("Before the with statement)")
with concurrent.futures.ThreadPoolExecutor(max_workers=len(self.workers)) as executor:
task = {executor.submit(self.start_worker): i for i in range(int(number))}
print("tasks set")
print(task)
for future in concurrent.futures.as_completed(task):
url = task[future]
print(url)
try:
print("before getting data")
data = future.result()
print(data)
except Exception as exc:
message = ('%r generated an exception: %s' % (url, exc))
code = http.HTTPStatus.INTERNAL_SERVER_ERROR.value
else:
print('OK')
return (message, code)
else:
code = http.HTTPStatus.IM_A_TEAPOT.value
......@@ -120,7 +123,7 @@ class Kernel(object):
return (message, code)
def __set_next_worker(self):
if self.next_worker == length(self.workers)-1:
self.next_worker = 1
if self.next_worker == len(self.workers)-1:
self.next_worker = 0
else:
self.next_worker += 1
Metadata-Version: 1.0
Name: mandelbrot-creator
Version: 1.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
setup.py
mandelbrot_creator.egg-info/PKG-INFO
mandelbrot_creator.egg-info/SOURCES.txt
mandelbrot_creator.egg-info/dependency_links.txt
mandelbrot_creator.egg-info/entry_points.txt
mandelbrot_creator.egg-info/requires.txt
mandelbrot_creator.egg-info/top_level.txt
\ No newline at end of file
[console_scripts]
mandelbrot-creator=mandelbrot_creator:cli
\ No newline at end of file
Click
requests
docker
docker-compose
......@@ -4,12 +4,12 @@ services:
api:
container_name: api
build:
context: ./API
context: ./api
dockerfile: Dockerfile
ports:
- "8080:80"
- "8000:80"
volumes:
- "./API/:/usr/api/"
- "./api/:/usr/api/"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- mandelbrot
......
......@@ -34,9 +34,13 @@ kernel = Kernel()
def info():
return 'This is the worker service'
@app.route('/start', methods=['POST'])
@app.route('/start', methods=['GET', 'POST'])
def start_worker():
# GET handler
if request.method == "GET":
return kernel.start()
# POST handler
if request.method == "POST":
# Parse payload
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment