Package: zenaton
Easy Asynchronous Jobs Manager for DevelopersExplore the docs »Website·Examples in Python·Tutorial in PythonZenaton library for PythonZenatonhelps developers to easily run, monitor and orchestrate background jobs on your workers without managing a queuing system. In addition to this, a monitoring dashboard shows you in real-time tasks executions and helps you to handle errors.The Zenaton library for Python lets you code and launch tasks using Zenaton platform, as well as write workflows as code. You can sign up for an account onZenatonand go through thetutorial in python.RequirementsThis package has been tested with Python 3.5.Python DocumentationYou can find all details onZenaton's website.Table of contentsZenaton library for PythonRequirementsPython DocumentationGetting startedInstallationInstall the Zenaton AgentInstall the libraryFramework integrationQuick startClient InitializationExecuting a background jobOrchestrating background jobsUsing workflowsGetting helpTheorical ExamplesReal-life ExamplesContributingLicenseCode of ConductGetting startedInstallationInstall the Zenaton AgentTo install the Zenaton agent, run the following command:curlhttps://install.zenaton.com/|shThen, you need your agent to listen to your application.
To do this, you need yourApplication IDandAPI Token.
You can find both onyour Zenaton account.zenatonlisten--app_id=YourApplicationId--api_token=YourApiToken--app_env=YourApplicationEnv--boot=boot.pyInstall the libraryTo add the latest version of the library to your project, run the following command:pipinstallzenatonFramework integrationIf you are usingDjango, please refer to our dedicated documentation to get started:Getting started with DjangoQuick startClient InitializationTo start, you need to initialize the client. To do this, you need yourApplication IDandAPI Token.
You can find both onyour Zenaton account.Then, initialize your Zenaton client:fromzenaton.clientimportClientClient(your_app_id,your_api_token,your_app_env)Executing a background jobA background job in Zenaton is a class implementing theZenaton.abstracts.task.Taskinterface.Let's start by implementing a first task printing something, and returning a value:importrandomfromzenaton.abstracts.taskimportTaskfromzenaton.traits.zenatonableimportZenatonableclassHelloWorldTask(Task,Zenatonable):defhandle(self):print('Hello World\n')returnrandom.randint(0,1)Now, when you want to run this task as a background job, you need to do the following:HelloWorldTask().dispatch()That's all you need to get started. With this, you can run many background jobs.
However, the real power of Zenaton is to be able to orchestrate these jobs. The next section will introduce you to job orchestration.Orchestrating background jobsJob orchestration is what allows you to write complex business workflows in a simple way.
You can execute jobs sequentially, in parallel, conditionally based on the result of a previous job,
and you can even use loops to repeat some tasks.We wrote about some use-cases of job orchestration, you can take a look atthese articlesto see how people use job orchestration.Using workflowsA workflow in Zenaton is a class implementing theZenaton.abstracts.workflow.Workflowinterface.We will implement a very simple workflow:First, it will execute theHelloWorldtask.
The result of the first task will be used to make a condition using anifstatement.
When the returned value will be greater than0, we will execute a second task namedFinalTask.
Otherwise, we won't do anything else.One important thing to remember is that your workflow implementationmustbe idempotent.
You can read more about that in ourdocumentation.The implementation looks like this:fromtasks.hello_world_taskimportHelloWorldTaskfromtasks.final_taskimportFinalTaskfromzenaton.abstracts.workflowimportWorkflowfromzenaton.traits.zenatonableimportZenatonableclassMyFirstWorkflow(Workflow,Zenatonable):defhandle(self):n=HelloWorldTask().execute()ifn>0:FinalTask().execute()Now that your workflow is implemented, you can execute it by calling thedispatchmethod:MyFirstWorkflow().dispatch()If you really want to run this example, you will need to implement theFinalTasktask.There are many more features usable in workflows in order to get the orchestration done right. You can learn more
in ourdocumentation.Getting helpNeed help? Feel free to contact us by chat onZenaton.Found a bug?You can open aGitHub issue.Theorical ExamplesPython examples repoReal-life ExamplesTriggering An Email After 3 Days of Cold Weather(Medium Article,Source Code)ContributingBug reports and pull requests are welcome on GitHubhere. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to theContributor Covenantcode of conduct.TestingTo test your changes before sending a pull request, first install the tests requirements:pipinstall'.[test]'Then run PyTest:pytestLicenseThe package is available as open source under the terms of theMIT License.Code of ConductEveryone interacting in the zenaton-Python project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow thecode of conduct.Changelog[0.4.2] - 2019-10-03AddedAddedcustom_idargument for workflow schedule.Dispatch of tasks and workflows are now done using the API instead of a local agent.Pause, Resume and Kill workflows are now done using the API instead of a local agent.Send event to workflow is now done using the API instead of a local agent.Find workflow is now done using the API instead of a local agent.[0.4.1] - 2019-09-25AddedAdded aintent_idproperty when dispatching workflows and tasks, sending events to workflows, and
pausing/resuming/killing workflows.Execution context for tasks and workflowsOptionalon_error_retry_delaymethod handling task failures and specifying
how many seconds to wait before retrying.[0.4.0] - 2019-08-26AddedAdded aintent_idproperty when dispatching workflows and tasks, sending events to workflows, and
pausing/resuming/killing workflows.Added scheduling:schedule(cron)[0.3.4] - 2019-07-01AddedRun tests in a continuous integration flow.No need for credentials when this lib is running in a Zenaton agent except if dispatching a
sub-job.[0.3.3] - 2019-06-25FixedFix a typo in client.py that prevents correct executions of versions[0.3.2] - 2019-06-21FixedCallingday_of_monthon a wait task now waits for to wait for the next day having the requested day number, even if that means waiting for next month. (i.e calling Wait().day_of_month(31) on February, 2nd will wait for March, 31st)Fixed Wait task behavior in some edge casesEncodes HTTP params before sending requestAddedAddedevent_dataproperty when sending event.[0.3.1] - 2019-04-26FixedFixedMANIFEST.infile not included files required bysetup.py.[0.3.0] - 2019-03-25AddedCallingdispatchon tasks now allows to process tasks asynchronouslyFixedFixed Wait task behavior in some edge cases
Encodes HTTP params before sending request[0.2.5] - 2018/10/17Object Serialization (including circular structures)[0.2.4] - 2018/09/26Enhanced WithDuration & WithTimestamp classes[0.2.3] - 2018/09/21Minor enhancements (including the workflow find() method)[0.2.2] - 2018/09/19New version scheme management[0.2.1] - 2018/09/17Reorganized modules[0.2.0] - 2018/09/14Full rewriting of the package