Coder Social home page Coder Social logo

codex's Introduction

code-execution-engine

An API which executes codes in a sandbox environment ๐Ÿ™€๐Ÿคฏ.

Leave a star if U like it ๐Ÿ˜€


Architecture


Running the API


Prerequisites

Docker and docker compose should be installed in the system

Step 1 :

Clone the repo

Step 2 : building the images

sudo docker-compose build

Step 3 : running the images

sudo docker-compose up

Step 4 : Testing if its working

If its running on localhost then ping the server using

  • On terminal:

      curl http://localhost:9090/
    

    We will get a response saying Hello from Titan-Engine with status code 200.

  • On browser :

    paste the url http://localhost:9090/ and see the response.

  • On Postman : (recommended)

    Sending a json post request to http://localhost:9090/submit

    It is a c++ script which takes 2 input and print's it.

    {
    "src": "\n\n#include<bits/stdc++.h>\n\nusing namespace std ;\n\nint main()\n{\n    int a ;\n    cin >> a ;\n\n    cout << \"The first number is \" << a << endl ;\n    \n    int b ;\n    cin >> b ;\n    \n    cout << \"The second number is \" << b << endl ;\n\n    cout << \"Hello from cpp\" <<endl ;\n\n    // while(1)\n    // {\n    //     cout << 1 << endl ;\n    // }\n    return 0;\n}\n\n",
    "stdin": "48\n95",
    "lang": "cpp",
    "timeout": "5"
    }

    we will get a response like

      http://localhost:900/results/Test646d62525e1b09171058
    

    Run this response in postman or browser


Yay Its working ๐Ÿ˜Ž๐Ÿ˜Ž๐Ÿ‘Œ๐Ÿ‘



Understanding post request and responses

Post

src contains the scripts in raw formate.

stdin contains the inputs in raw formate.

lang the programming language.

timeout number of seconds the program will run.(Max 5 sec)



Response

we will get a response like

http://localhost:900/results/Test646d62525e1b09171058

Run this response in postman or browser

output The output of the script

status status of the output

stderr error in code

submission_id the unique submission id




Different types of status:


"status": "Invalid Request"

If the field in post request is empty then it will show invalid request


"status":"Queued"

If the request is in waiting stage i.e. in queue.


"status":"Processing"

If the script is running


"status":"Runtime Error"

If the exec command fails for some reason in worker nodes


"status":"Failed"

Causes due to compilation error or runtime error.


"status":"Successful"

Everything is OK




PORT 8080 and PORT 9090

The docker-compose exposes 2 ports

https The port 8080 uses self signed ssl certificate.

http The port 9090 can be used for debugging.





The End

codex's People

Contributors

maheshaila01 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.