diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -338,3 +338,51 @@ int job_build_path(char *filename, unsig { return 0; } + + +int downloadTar(char *url, char *destinationPath){ + // Prepare to download the job tar if it isn't present + struct stat buffer; + int fstatus = stat(destinationPath, &buffer); + if(fstatus == -1) + { + // Download the Tar + if( curlget(url, destinationPath) == 0){ + fprintf(stderr, "Job data retrieved successfully\n"); + free(url); + return 0; + } + else { + fprintf(stderr, "Downloading job data from %s failed. Check your network connection.\n",url); + free(url); + return 1; // Eventually make a retry loop + } + } + else{ + fprintf(stderr, "Tar already exists! Download cancelled.\n"); + return 2; + } +} + + +int uploadOutput(char *pathtoOutput, char *urltoOutput){ + if( !curlpost(pathtoOutput, urltoOutput)) // Uploads output + { + fprintf(stderr,"Upload successful, removing old output...\n"); + remove(pathtoOutput); // Delete the file after its uploaded + return 0; + } + else + { + fprintf(stderr,"Upload failed. Check your network connection. Retrying upload...\n"); + int tries=1; + while(tries<=10 && curlpost(pathtoOutput, urltoOutput)) + { + fprintf(stderr, "Upload failed. Trying again in 10 seconds... (attempt %d of 10)\n", tries); + tries++; + sleep(10); + } + return 1; // Upload failed after multiple tries + // @FUTURE: Keep track of files that we were unable to upload, and upload them later + } +}