{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Worker script\n\nThis script is responsible for receiving pipeline configurations from BugDoc's algorithms.\nIt runs and evaluates the pipeline instances, and returns the result to BugDoc.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing necessary packages.\nWe load utility packages to open communication and store pipeline instances.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import ast\nimport sys\nimport traceback\nimport zmq\nfrom bugdoc.utils.utils import record_pipeline_run" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing pipeline engine API.\nHere we load the function that executes and evaluates a pipeline instance.\nPlease replace with your own API\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from my_api_example import execute_pipeline\n\n\nhost = 'localhost'\nreceive = '5557'\nsend = '5558'\n\ncontext = zmq.Context()\n\n# Socket to receive messages on\nreceiver = context.socket(zmq.PULL)\nreceiver.connect(\"tcp://{0}:{1}\".format(host, receive))\n\n# Socket to send messages to\nsender = context.socket(zmq.PUSH)\nsender.connect(\"tcp://{0}:{1}\".format(host, send))\n\n\n# Process tasks forever\nwhile True:\n data = receiver.recv_string()\n fields = data.split(\"|\")\n filename = fields[0]\n values = ast.literal_eval(fields[1])\n parameters = ast.literal_eval(fields[2])\n try:\n configuration = {\n parameters[i]: values[i]\n for i in range(len(parameters))\n }\n result = execute_pipeline(configuration) # Please replace this function call\n except:\n traceback.print_exc(file=sys.stdout)\n result = False\n \n record_pipeline_run(filename, values, parameters, result)\n values.append(result)\n sender.send_string(str(values))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.20" } }, "nbformat": 4, "nbformat_minor": 0 }