Package: cowait
cowaitCowait is a framework for creating containerized distributed applications with asynchronous Python. Containerized functions, calledTasks, can run locally in Docker or on remote Kubernetes clusters. The intention is to build a novel type of workflow engine that offers maximum flexibility while also requiring minimal setup and configuration. Because of the loose definition of what a Task could be, and the integration with Docker & Kubernetes, Cowait can be used to easily build many types of distributed applications.Check out the documentation athttps://cowait.io/docs/quick-start/NoticeCowait is still in fairly early development. We invite you to try it out and gladly accept your feedback and contributions, but please be aware that breaking API changes may be introduced.CommunityJoin the Cowait development Slack channel!Get your invite athttps://slack.cowait.ioGetting StartedRequirementsdockerpython 3.6+Installation$pipinstallcowaitTask DevelopmentFirst TaskWrite a task.Tasks can be written as decorated functions or subclasses ofcowait.Task. The easiest way is to write a decorated function:# hello.pyfromcowaitimporttask@taskasyncdefHello():print('Hello World')Build a task imageAll files within the current directory is bundled into a docker image.In the same folder ashello.py, run:$cowaitbuildRun it locallyTo run a task, pass the name of the module import name tocowait run. Since our task code lives inhello.py, the module name will behello. In the same folder ashello.py, run:$cowaitrunhelloNoteshellosupplied tocowait runis the python module name. This module should contain exactlyonetask class. Modules can be single python files or subdirectories with__init__.pyfiles.The actual function/class name of the task does not matter when running from the CLI, only when importing and executing tasks from python.Subtasks, Arguments & Return ValuesTasks can execute subtasks by importing and calling asynchronously using theawaitkeyword. Subtasks accept named arguments and return results, much like regular functions.Suppose we have aSquaretask that squares an integer.# square.pyfromcowaitimporttask@taskasyncdefSquare(number:int)->int:returnnumber**2We can import it to another task and execute it:# main.pyfromcowaitimporttaskfromsquareimportSquare@taskasyncdefMainTask():value=22squared=awaitSquare(number=22)print(f'{value}squared is{squared}!')Task ContextsA task context is a directory containing acowait.ymlconfiguration file. This directory will act as the root of a project, and everything within this folder is copied into the resulting docker image during the build step. If you have not created acowait.ymlfile, the current working directory (when executingcowait build) will be used.** Example Task Context **/var/stuff/my_cowait_project
   src/
     library.py
   cowait.yml
   requirements.txt
   task1.py
   task2.pyIn this case,/var/stuff/my_cowait_projectwill be the context directory.Pushing Task ImagesBefore you can run tasks on a Kubernetes cluster, they must be pushed to a docker registry that is accessible from the cluster. To do this, you must define a proper image name in the context configuration file.version:1cowait:image:docker.io/username/cowait-taskOnce the full image name has been configured, you can push the image usingcowait push:$cowaitpushCluster DeploymentRequiurementsConfigured kubernetes cluster context.Docker registry accessible from the cluster.First, ensure that the image has been pushed to your docker registry.$ cowait pushKubernetes ConfigurationBefore you can run tasks on a kubernetes cluster, you need a service account with permissions to create/list pods. A sample configuration is provided ink8setup.yml, which will allow any pods owned by the default service account to create, list and destroy other pods.For detailed information about running on Kubernetes, see thedocumentation.Running TasksTo run tasks on a remote cluster, pass the cluster name using the--clusteroption tocowait run.Cowait comes with a predefined cluster calledkuberneteswhich always refers to your default configured cluster (the one returned by$ kubectl config current-context).$cowaitrundocker.io/username/cowait-task--clusterkubernetesDevelopmentRequirementsdockerpython 3.6+poetry (recommended)InstallationClone repository$ python3 -m pip install -e .Changes to thecowait/directory require a rebuild of the base image. You can do this with the provided helper script in the root of the repository:$./build.shNote:Tasks will have to rebuilt withcowait buildfor the changes to take effect.Generate DocumentationYou can generate documentation (from docstrings) for Cowait to the /docs folder usingpdoc3(defined in Poetry as a dev dependency):$pdoc3--skip-errors--html--output-dirdocs/htmlcowait