# Submission flow This article will describe in execution flow of submission from the point of submission into web application to the point of evaluation of results from execution. Note that following text is simplified and should only show concepts which are used during execution. ## Web Application First thing user has to submit his/hers solution to web application which provides interface to upload multiple files and then submit them. More detailed description follows: 1. user upload file by file into prepared submit form 2. after uploading all files connected to assignment user clicks on submit button 3. Web Application send request to Web API that user wants to evaluate assignment with provided files ## Web API After user submits solution then web application has to hand over all needed information about submission to broker. Submit endpoint is extended with support of "cross-submitting" which means that user with high privileges (supervisor, administrator) can submit solution for user with lower privileges (student). More detailed description follows: 1. deadlines and count of submissions are checked 2. programming language of uploaded files is automatically detected 3. based on programming language proper job configuration file is obtained 4. submitted files from user and job configuration are uploaded to fileserver as archive 5. send message to broker that there is new submission 6. several information about new submission including websocket channel are sent back to user ## Broker Broker gets information about new submission from web api. At this point broker has to find suitable worker for execution of this particular submission. When worker is found and is jobless, then broker send detailed submission to worker to evaluation. More detailed description follows: 1. broker gets message from web api about new submission 2. based on information from web api, broker has to choose suitable worker which matches all submission criteria 1. if suitable worker is not found then broker notices Web API about this information and all execution stops 2. suitable worker is found 1. worker has no jobs at the moment, broker immediately sends job evaluation request to it 2. otherwise evaluation request is queued to this particular worker and waits until all previous jobs are done 3. broker sends prepared evaluation request to worker with all information which was obtained from web api ## Worker Worker gets request from broker to evaluate particular submission. Next step is to evaluate given submission and upload results to fileserver. After this worker only send broker that submission was evaluated. More detailed description follows: 1. worker gets evaluation request from broker 2. worker now has to do some initialization of directories and some internal structures for new incoming evaluation 3. users submission archive from given address from evaluation request is downloaded and decompressed 4. job configuration file is located and parsed into internal job structure 5. tasks which are present in configuration are loaded into tree like structure with dependencies and are divided into internal or external ones 1. internal tasks are tasks which has no defined limits and contains some internal action 2. external tasks have defined limits in configuration and are executed in sandbox 6. last step of initializing of job is to topologically sort tasks and prepare queue with right execution order 7. after that topologically sorted execution queue is processed 1. if execution of `inner` task fails worker will immediately stop execution and send back to broker 'internal error during execution' message 2. execution of `execution` or `evaluation` task fails then worker stops and send back to broker 'execution failed' message 8. when execution successfully ends results are collected from all executed tasks and written into yaml file 9. results yaml file alongside with content of job result folder is sent back to fileserver in compressed form 10. of course there has to be some cleaning after whole evaluation which will mostly delete content of temporarily created folders 11. last step of worker is to send back to broker message that execution successfully ended ## Broker Broker gets done message from worker and basically only mark submission as done in its internal structures. After that broker has to tell Web API that execution of particular job ended. More detailed description follows: 1. broker gets message from worker that execution of job ended 2. job execution on worker was successful 1. Web API is notified that job ended successfully 2. if there are some waiting jobs for worker than the first one is sent for execution 3. job execution on worker ended with internal error 1. if job ends with internal error than it is possible to reassign it to another worker 2. broker keeps track of job reassignments and if number of them reach some predefined constant, job is declared as failed 3. suitable worker different that the original one is picked and evaluation request is sent to it 4. job execution on worker failed 1. Web API is notified that execution of this particular job failed 2. again if there is waiting job for execution on worker than it is sent for execution ## Web API Web api is notified about job status from broker. After that api is deciding if evaluated submission will be evaluated immediately or on demand. But for the sake of simplicity we will consider only immediately evaluated results. More detailed description follows: 1. job arrived with successful evaluation status 1. results of evaluation are downloaded from fileserver where it was uploaded by worker and then unzipped 2. result yaml file is loaded and actual time and memory consumption are retrieved 3. overall results are computed and stored into database 2. job arrived as failed 1. job failure is saved into database alongside other reported errors 2 email is sent to ReCodEx administrator that job failed and cannot be properly executed ## Web Application Web application has only a simple work to do. It has to obtain results from web api. More detailed description follows: 1. web application sends request for results of particular submission 2. if results are available than they are sent back to web application and displayed to user