Kelson Martins

Introducing [Go]modoro. A CLI tool written in golang for Pomodoro tracking

Introduction

Kelson

Kelson

Software engineer. Geek. Traveller. Wannabe athlete. Lifelong student. Works at IBM and hosts the @HardcodeCast.


LATEST POSTS

Binary Search Algorithms with Examples 07th June, 2022

Configuring Openshift Identity Providers 06th February, 2022

Programming

Introducing [Go]modoro. A CLI tool written in golang for Pomodoro tracking

Posted on .

 

A few years ago, I had a great time reading Cal Newport’s book entitled “Deep Work: Rules for Focused Success in a Distracted World”. The book emphasizes the importance of having focused and uninterrupted work and how this is key to achieve significant results in whatever tasks we put ourselves to perform. As a takeaway from the reading, I started once again to explore the utilization of the Pomodoro technique as a tool to enhance my focus on daily tasks that required such focused concentration.

Fast-forwarding a few years, I started recently a journey to learn Golang (given my involvement in Kubernetes Operators development), and as part of the learning experience, I wrote a tool that would help me learn the language while also being a tool that I would use it myself. With that being said, I am happy to present in this post the Gomodoro App.

What is the [Go]modoro app ?

[Go]modoro is a CLI application for those interested in the Pomodoro technique. The application can run Pomodoros from customized at different lengths (defaults to 25m), while also providing some metrics for traceability.

Features:

  • Uses SQLite for storing the local Pomodoro sessions.
  • Supports backup of the local database via Google Drive integration.
  • Supports synchronization via Cassandra database (powered by DataStax).
  • The current version supports Linux and Darwin.

You can find the installation on the project’s GitHub page, where this article focuses on providing details of its implementation.

Local Storage

SQLite is used for local storage, mainly via one table that has the following Struct representation:

type Gomodoro struct {
	Year           string
	Date           string
	StartTimestamp string
	EndTimestamp   string
	Minutes        int
	Category       string
	SubCategory    string
}

SQL interactions are powered via the go-sqlite3 library. All DB related operations such DB creation, update and selects are powered by this small yet powerful library.

Listing Entries

Using the gomodoro list feature will query the local SQLite database to present its results in your console

$ gomodoro list
ID: 207  2021-01-06 14:53:34     Category: coding        SubCategory: gomodoro feature x
ID: 206  2021-01-06 10:56:26     Category: coding
ID: 203  2021-01-06 08:33:04     Category: coding
ID: 202  2021-01-05 15:27:15     Category: coding        SubCategory: gomodoro feature y
ID: 201  2021-01-05 14:41:28     Category: coding
ID: 200  2021-01-05 11:37:45     Category: coding

The list feature by defaults prints to your console all entries for the last 30 days, and you can override this with the --days flag.

 Deleting Entries

You can delete entries via the gomodoro delete option. It expects the id of the Pomodoro entry. Alternatively, you can delete the latest entry with the id 0 as in: gomodoro delete --id 0

Further Details

You can find code details for the local storage feature here.

Remote Synchronization

One requirement I had in mind for the tool was for it to provide means for tracking the sessions across different workstations. To support that, the application uses a remote Cassandra database where entries are persisted remotely and synchronized across any workstation that has the application installed.

The service backing this feature is the DataStax Astra DB, whose free-tier provides up to 40GB of disk along with 30 million reads, 4.5 million writes every month.

DataStax does not provide a Golang native library for interacting with the service, and although there are other open-source libraries that should also do the work (such as this one), I decided to use the service REST API for the communication. DataStax documentation is spotless and there were absolutely no problems consuming it.

During the push, the application uses a simple primary key that supports well the synchronization feature which is PRIMARY KEY (year, date, start_timestamp), where during the synchronization there is no need to identify what was previously pushed to the Cassandra DB given that primary keys are unique. The simplest approach (although not the most performative one) is to push all the local entries given that the records that are already on the remote DB will be ignored because of the clash of primary keys.

During the read, all remote entries are pulled and the application will compare remote entries with local entries, aiming to only insert to the local SQLite database the entries that do not exist locally.

Ultimately, there is some work to be done aiming for a more performative approach to both push faster and pull faster, and I will provide an update once that comes into place.

 Google Drive Backup

Worried about losing the local database? Fear not. A feature that uses Goggle’s official go drive library is available that pushes your local SQLite database into a folder named gomodoro_backup  to your Google Drive account.

The implementation is fairly simple, where a plain copy of your database is persisted in the drive’s home folder, and we can use the database’s timestamp in an eventual database restore whenever needed.

The Cobra CLI Go Library

There are a few libraries available in Golang for the development of CLI tools, but none beat the Cobra library. As proof of this statement, some of the most used CLI tools use the library. These include podman, helm, kubectl and many others.

Some of the features powered by Cobra that you may notice while using the Gomodoro application include:

  • Automatic help generation for commands and flags.
  • Automatic help flag recognition of -h--help.
  • Automatically generated man page.
  • Intelligent suggestions (gomodoro dlete… did you mean gomodoro delete?)

The Gomodoro Session Progress

During a gomodoro session, you will notice a progress bar that slowly fills up to 100%. This is all thanks to this progress bar library developed by Erman İmer.

$ gomodoro run -c coding
Gomodoro Started: 11-07-2021 18:14:09
▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆                                    %30.0

Originally the gomodoro sessions were tracked in the terminal by a simple countdown timer that was updated every 5m in a descending fashion.. 25m… 20m……. 5m…. session completed.

This implementation was in place until I found out about this great library while reading through the golang subreddit, and that was the perfect visual enhancement this application needed.

Conclusion

Before you ask me, Yes! This own article is being written while a gomodoro session is in progress.

At the time of this writing, the following are my all-time metrics using the app:

$ gomodoro totals
[Go]modoros today:  4
[Go]modoros yesterday:  6
[Go]modoros this month:  22
[Go]modoros last month:  61
[Go]modoros all-time:  1216

These 1216 sessions translate to 30.400 minutes/506 hours, and these helped me extensively to have uninterrupted and focused sessions both at work and at side projects. More recently, these sessions were key during my preparation to complete the RedHat System Administrator and Kubernetes Application Developer certifications, and it will surely help me out in the future on my next endeavours.

If you are like me and enjoy having focused time to work on your tasks, give [Go]modoro a try, and I ensure it will help you as much as it helps me.

 

Kelson

Kelson

//iamkel.dev

Software engineer. Geek. Traveller. Wannabe athlete. Lifelong student. Works at IBM and hosts the @HardcodeCast.

Navigation