Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/environment-variables/environment_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import asyncio
from typing import AsyncIterable

from yapapi import Golem, Task, WorkContext
from yapapi.log import enable_default_logger
from yapapi.payload import vm


async def worker(context: WorkContext, tasks: AsyncIterable[Task]):
async for task in tasks:
script = context.new_script()
future_result = script.run(
"/bin/sh", "-c", "echo ${TEST_VAR:=not captured}",
env={
"TEST_VAR": "captured",
}
)

yield script

task.accept_result(result=await future_result)


async def main():
package = await vm.repo(
image_hash="d646d7b93083d817846c2ae5c62c72ca0507782385a2e29291a3d376",
)

tasks = [Task(data=None)]

async with Golem(budget=1.0, subnet_tag="public") as golem:
async for completed in golem.execute_tasks(worker, tasks, payload=package):
print('Environ variable in current run was:', completed.result.stdout)


if __name__ == "__main__":
enable_default_logger(log_file="hello.log")

loop = asyncio.get_event_loop()
task = loop.create_task(main())
loop.run_until_complete(task)
4 changes: 2 additions & 2 deletions yapapi/script/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ def __init__(
def evaluate(self):
capture = {"stdout": self.stdout.to_dict(), "stderr": self.stderr.to_dict()}
return self._make_batch_command(
"run", entry_point=self.cmd, args=self.args, capture=capture
"run", entry_point=self.cmd, args=self.args, env=self.env, capture=capture
)

def __repr__(self):
return f"{super().__repr__()} {self.cmd} {self.args}"
return f"{super().__repr__()} {self.cmd} {self.args} {self.env}"


StorageEvent = Union[DownloadStarted, DownloadFinished]
Expand Down