Triggering An Email After 3 Days of Cold Weather: An Example of Elegant Workflow Coding with Zenaton for Python

Yann Bury
Zenaton
Published in
3 min readNov 21, 2018

The Context

Coding, running, monitoring and maintaining business workflows can be a real pain. At Zenaton, we are building a suite of tools allowing you to flawlessly run automated processes. All the infrastructure, persistence and configuration are handled for you. You can learn more here:

Marketing Automation Example

Let’s look at how to code a business workflow in Python with a marketing automation example.

Let’s say you are a local travel agency that wants to send an email campaign for a tropical destination. Of course, you’ll want to automatically send it at the right time to have the greatest possible impact.

For example, you might want to send it when the temperature in your clients’ hometown is below 40°F ⛸ for three days in a row, giving you a better chance that they’ll book a trip to the tropics🌴.

Let’s code it with Zenaton!

First, let’s code the two main tasks this workflow includes: checking the weather and sending the email campaign:

Tasks’ definition

To write a Zenaton Task, just subclass Task and Zenatonable. Then implement a handlemethod that contains the task’s required actions.

In this article we don’t show the full implementation of the tasks. Our objective here is only to show you Zenaton’s usage. You can find the full, working implementation of the example here! You will need an OpenWeatherMap account and a Gmail address to run the workflow.

So let’s write the actual workflow orchestration part, where the business logic is defined:

To write a Zenaton workflow, just subclass Workflow and Zenatonable. Then implement a handlemethod that contains the workflow structure and calls the tasks you defined earlier.

The workflow will run for days (eg. 30) days, and trigger the email campaign if the temperature is below min_temp (eg. 40) °F for min_rep (eg. 3) days in a row.

Launch

You should have a server with a Zenaton Agent installed and configured with a boot file where you import your TemperatureCampaignWorkflow file (see our examples).

To launch this workflow, you then just execute this script:

TemperatureCampaignWorkflow(30, 40, 3).dispatch()

That’s it! Your automated marketing campaign is scheduled 💪.

At this stage, it’s important to emphasize a few points:

  • The code inTemperatureCampaignWorkflow seems to run for up to 30 days, but it’s not the case. Zenaton uses this code to orchestrate tasks (TaskCheckTemperature, TaskSendEmail and Wait) but it does not mean that a python thread is running on your workers for up to 30 days.
  • You do not have to (data)store any state, set up any cron, install any queuing system… it just works 😀

This is just a basic example. Zenaton provides you with tools to easily handle errors & retries, monitor tasks and much more! 🚀

Want that much more?

You can install Zenaton and start coding your own workflows now! We have a really 🔥 interactive tutorial, here.

You can also play around with the full implementation of this example and modify it to fit your needs.

Our library is also available in PHP, Node, Ruby & Go!

And if you have any questions or comments, please send me an email at yann@zenaton.com, chat with us here (lower right of the screen), or comment below 👇.

--

--