Пример #1
0
    async def worker(ctx: WorkContext, tasks):
        ctx.send_file("./scene.blend", "/golem/resource/scene.blend")
        async for task in tasks:
            frame = task.data
            ctx.begin()
            crops = [{
                "outfilebasename": "out",
                "borders_x": [0.0, 1.0],
                "borders_y": [0.0, 1.0]
            }]
            ctx.send_json(
                "/golem/work/params.json",
                {
                    "scene_file": "/golem/resource/scene.blend",
                    "resolution": (800, 600),
                    "use_compositing": False,
                    "crops": crops,
                    "samples": 100,
                    "frames": [frame],
                    "output_format": "PNG",
                    "RESOURCES_DIR": "/golem/resources",
                    "WORK_DIR": "/golem/work",
                    "OUTPUT_DIR": "/golem/output",
                },
            )
            ctx.run("/golem/entrypoints/run-blender.sh")
            ctx.download_file(f"/golem/output/out{frame:04d}.png",
                              f"output_{frame}.png")
            yield ctx.commit()
            # TODO: Check if job is valid
            # and reject by: task.reject_task(msg = 'invalid file')
            task.accept_task()

        ctx.log("no more frame to render")
    async def worker(ctx: WorkContext, tasks):
        ctx.send_file(
            "./lens.py",
            "/golem/work/lens.py",
        )
        async for task in tasks:
            feed = task.data
            ctx.send_json(
                "/golem/work/params.json",
                feed,
            )
            commands = (
                "python3 /golem/work/lens.py >> /golem/output/task-log 2>&1;")
            ctx.run("/bin/sh", "-c", commands)
            frame_start = feed["start_frame"]
            frame_end = feed["start_frame"] + len(feed["points"])
            frames = range(frame_start, frame_end)
            ctx.log(f"Downloading frames {frame_start}-{frame_end}...")
            for frame in frames:
                ctx.download_file(f"/golem/output/{frame}.png",
                                  f"out/{frame + 100}.png")
            output = f"task-log"
            ctx.download_file(f"/golem/output/task-log", f"out/{output}")
            yield ctx.commit()
            # TODO: Check if job results are valid
            # and reject by: task.reject_task(reason = 'invalid file')
            task.accept_task(result=output)

        ctx.log("no more frames to render")
Пример #3
0
 async def __worker_render_frame(self, ctx: WorkContext,
                                 tasks: [GeomandelTask]):
     """Creates a set of instructions for each subtask"""
     async for task in tasks:
         # Send subtask data as JSON to the remote execution environment.
         ctx.send_json(_TASK_INPUT_PATH, task.data.__dict__)
         # Run python script loading the data from JSON and executing the geomandel binary to generate the image.
         ctx.run(*_GEOMANDEL_COMMAND)
         # Download the output file.
         ctx.download_file(_TASK_OUTPUT_PATH, task.data.output_path)
         # Return a sequence of commands to be executed when remote node agrees to process a task.
         yield ctx.commit()
         # TODO: actual verification
         task.accept_task(result=task.data.output_path)