File size: 1,629 Bytes
2dc9347
 
 
 
 
 
 
 
 
 
 
 
 
 
c42190b
2dc9347
 
c42190b
 
2dc9347
 
1457d21
 
 
2dc9347
1457d21
 
 
 
 
2dc9347
 
 
c42190b
 
 
2dc9347
c42190b
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
This script is used to wrap all generation methods together.

todo:
    A worker keeps running on the server. Monitor the Amazon SQS. Once receive a new message, do the following:
        Download the corresponding configuration files on S3.
        Change Task status from Pending to Running.
        Call `generator_wrapper` and wait for the outputs.
        If `generator_wrapper` returns results:
            evaluate the results; compile it; upload results to S3 ... Change Task status from Running to Completed.
            If anything goes wrong, raise Error.
        If `generator_wrapper` returns nothing or Timeout, or raise any error:
            Change Task status from Running to Failed.
'''
import os.path

from auto_backgrounds import generate_draft
import json, time
from utils.file_operations import make_archive


GENERATOR_MAPPING = {"fake": None,  # a fake generator
                     "draft": generate_draft # generate academic paper
                     }

def generator_wrapper(config):
    generator = GENERATOR_MAPPING[config["generator"]]

    
def generator_wrapper_from_json(path_to_config_json):
    # Read configuration file and call corresponding function
    with open(path_to_config_json, "r", encoding='utf-8') as f:
        config = json.load(f)
    print("Configuration:", config)
    # generator = GENERATOR_MAPPING.get(config["generator"])
    generator = None
    if generator is None:
        # generate a fake ZIP file and upload
        time.sleep(150)
        zip_path = os.path.splitext(path_to_config_json)[0]+".zip"
        return make_archive(path_to_config_json, zip_path)