Exemplo n.º 1
0
def submit_code(user, project, code):
    """ Submit code on behalf of a user on a particular project

    :param models.User user: The user
    :param models.Project project: The project
    :param str code: The code to submit. If the file is a directory, then zips it up and
        submits it. If the file is a regular file, submits as is.
    """
    with NamedTemporaryDirectory() as tmpdir:
        token = uuid.uuid4()
        submission = models.Submission(user.id, project.id, token)
        archive_name = os.path.join(tmpdir, submission.submission_key)
        if os.path.isdir(code):
            archive = shutil.make_archive(code, "zip", archive_name)
        elif code.endswith(".zip"):
            archive = code
        else:
            shutil.copy(code, tmpdir)
            archive = shutil.make_archive(tmpdir, "zip", archive_name)

        storage.push_archive(archive)

    payload = {"submission_key": submission.submission_key, "token": token}

    worker = IronWorker()
    task = Task(code_name=project.project_key, payload=payload, timeout=TIMEOUT)
    response = worker.queue(task)
    return response
Exemplo n.º 2
0
def update_all_images(request):
    from iron_worker import IronWorker, Task
    worker = IronWorker()

    response_text = "ID\tURL\n"

    for img in Image.objects.filter(is_enabled=True).filter(in_s3=False):
        payload = {
            'image_id': img.id,
            'image_url': img.large_url,
        }
        t = Task(code_name='resize_image', payload=payload)
        worker.queue(task=t)
        response_text += str(img.id) + '\t' + img.large_url + '\n'

    return HttpResponse(response_text + 'Success. OK',
                        content_type='text/plain')
Exemplo n.º 3
0
def main():
    payload = IronWorker.payload()

    args = payload.get('args')

    aws_id = payload.get('aws-access-id')
    aws_secret = payload.get('aws-secret-key')

    cmd = ['python', 'main.py']

    if not args:
        raise Exception('args is missing')

    cmd.extend(args.split(' '))

    if not (aws_id and aws_secret):
        raise Exception('missing argument. aws-access-id and aws-secret-key are required')

    os.environ['AWS_ACCESS_KEY_ID'] = aws_id
    os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret
    subprocess.call(cmd)
Exemplo n.º 4
0
from iron_worker import IronWorker
worker = IronWorker()
task = worker.queue(code_name="startup")
print(task)
Exemplo n.º 5
0
def get_worker_cache():
    mq_env = config.loader.load().get('MQ_ENV', {})
    iron_env = {"project_id": mq_env['PROJECT'], "token": mq_env['TOKEN']}
    worker = IronWorker(**iron_env)
    cache = IronCache(**iron_env)
    return worker, cache
Exemplo n.º 6
0
 def __init__(self, conn_id='iron_worker_default'):
     conn = self.get_connection(conn_id)
     self.worker = IronWorker(project_id=conn.login, token=conn.password)