DEV Community

Cover image for Wrapping up my first Kestra flow
Amara Graham
Amara Graham

Posted on

Wrapping up my first Kestra flow

We've reach the end of the lovely saga of learning this has been creating my "first flow" in Kestra. So let's walkthrough what I did and what you can do.

I got it all to fit in a nice, clean topology!

Workflow topology, left to right

And here's a complete gist so we don't have to fight formatting and spacing issues:

Why is my trigger at the top?

I want to be able to easily see what triggers this workflow without scrolling to the bottom of the YAML file. For me, this is a "best practice" I'll continue to do. Your triggers may get added to the bottom, but order doesn't matter and you can move them.

Why use the HTTP Request plugin and not the GitHub plugin?

- id: get_issues
    type: io.kestra.plugin.core.http.Request
    uri:  "https://api.github.com/orgs/kestra-io/issues?filter=assigned&state=closed&since={{ now() | dateAdd(-5, 'DAYS') | date(\"yyyy-MM-dd'T'07:00:00-06:00\") }}"
    method: GET
    headers:
      Authorization: "Bearer {{ secret('CLASSIC_GITHUB') }}"
      Accept: application/vnd.github+json
      X-GitHub-Api-Version: 2022-11-28
Enter fullscreen mode Exit fullscreen mode

As of writing this post, the GitHub plugin returns .ion files and I didn't want to work with files with such a (relatively) small anticipated dataset. I just wanted JSON, which the HTTP Request plugin gives me easily.

Expressions and filters

This remains my favorite expression I've crafted so far:

"Now, but five days ago, and formatted"

{{ now() | dateAdd(-5, 'DAYS') | date(\"yyyy-MM-dd'T'07:00:00-06:00\") }}
Enter fullscreen mode Exit fullscreen mode

I would have like to create something a bit "smarter" here and detect the first working day of the week or the Monday of that week but I kind of made an assumption I would run this on Fridays only.

ForEach

You'll notice I left the returns in both ForEach blocks. I didn't really have a creative idea for this information but I did want to use this as an opportunity to play around with the context within a ForEach.

As I mentioned in a previous blog, my company's Google Calendar settings prevent me from seeing any of the more interesting calendar information, and my browser(?) settings seem to prevent the returned link from grabbing focus on my calendar. Any meeting link I click just sends me to the current time, which doesn't really do anything for me.

New Blueprints for you to use!

I created two Blueprints based off my first flow that you can use as a starting point, one for Confluence and one for Notion.

Both are cleaned up from my original flow and don't include random logs and outputs.

You'll need to plug in your Confluence or Notion instance info, like the API tokens, page ids, etc. I've also adjusted them to save you from character escaping hell with the Slack plugin by using messageText instead of payload. messageText will handle markdown for you.

It also just looks cleaner:

- id: send_to_slack
    type: io.kestra.plugin.slack.SlackIncomingWebhook
    url: "{{ secret('SLACK_WEBHOOK') }}"
    messageText: "You went to {{ kv('meetings_today') }} meetings and closed {{ kv('issues_today') }} PR(s) or issue(s) on the Kestra org!"
Enter fullscreen mode Exit fullscreen mode

By the way, if you have to choose, I would pick the Notion plugin for the easier experience. Not having to pass back the version number exactly incremented by 1 is faster and easier, particularly if you may want to manually add info to supplement what's getting passed in via your workflow. I get that Confluence wants to keep track of version history, but this was one of those annoying UX gotchas for me while I was testing.

How do I use Blueprints?

There are a few ways to do this depending where you are and how many browsers or tabs you have opened.

  • Copy my gist above and add it to your flow code editor. It's nearly a Blueprint anyway.
  • Access Blueprints directly in a panel adjacent to your flow code editor and click copy, then add to your flow code editor.
  • Click the "Blueprints" tab on the left-side menu then Flow Blueprints and click the "Use" button. This will automatically create a new flow with the Blueprint.
  • Find the Blueprint on the Blueprints website page and click the "Copy source code" button, then add to your flow code editor.

So, now what?

I guess I can officially declare my "first flow" with Kestra complete! It's been refined and refactored quite a bit, and while it doesn't do exactly what I hoped it would do, it was a great learning experience that I'm happy to share with you.

What should I tackle next? What do you want to learn about Kestra?

Photo by Tobias Carlsson on Unsplash

Top comments (0)