Stardew Valley

Stardew Valley was a great experience as a game. The chillout nature of planting your own turnips, water them and then harvesting in order to sell and get money to buy more seeds and plant, water, harvest, sell again.

It’s just relaxing. After a few hours you realize you can get swords and venture into caves to get ores (because stone and wood can only get you so far). Then you gather materials to build a barn and get your first farm animals. These animals produce even more materials for you. With these you can go ahead and make cheese, omelettes or fabric.

All this is happening while I use the remaining time in my days to clean out my farm and put some more buildings in. A better barn, a silo, a greenhouse…

Read More

How not to make async task tests

Before moving to Dramatiq I used to use Celery. And when it came to unit testing the first thing I added to my code was:


At the time I thought this was the best way. But after a lot of trial and error (and mainly because of Dramatiq, which I couldn’t find an eager mode) I found out that the eager mindset is wrong when it comes to unit testing.

By using eager mode I was treating my async tasks as sync and the views or methods that call those tasks need to run successfully without the async task.

So, in my opinion the best way to test this is to do something like (django with rest framework):

Read More

Dramatiq: alternative to Celery

Ever since I started doing web development async tasks were a thing. You can’t send an email synchronously and risk leaving the suer hanging. The solution was Celery. I used celery in a lot of projects. Simple websites to full single page applications.

But celery started to feel bulky, heavy and slugish. One of the major problems I’ve had with celery is the sheer complexity of the code. It’s impossible to dig into it.

When I heard about Dramatiq I was very intrigued. It promisses things that Celery never had (like prioritization of tasks) and probably will never have. After trying it out I can say that it is really good. Declaring and sending tasks is as easy as ever, having only to annotate a method and calling task.send.

Dramatiq also has middlewares so you can enable and disable features really easily (like error reporting, message retries, prioritization and so on).

import dramatiq
def count_words(url):
    response = requests.get(url)
    count = len(response.text.split(" "))
    print(f"There are {count} words at {url!r}.")

Read More