HOME BLOG

Archive for August, 2022

How to view the list of registered tasks in Celery

Posted on: August 27th, 2022 by Olu No Comments

Hi folks,

In this post I talk about a nice tip that could come in handy while working with Celery. It is how to get all registered Celery tasks. You can use code like:

from celery import current_app
all_task_names = current_app.tasks.keys()
all_tasks = current_app.tasks.values()
foo_task = current_app.tasks['tasks.foo']

all_task_classes = [type(task) for task in current_app.tasks.itervalues()]

The task registry is only populated as the modules containing tasks are imported. If you have not imported all modules you can do like the celery worker does, and import all configured task module sources:

current_app.loader.import_default_modules()

That’s all for now. Till next time, happy software development.

 

References

How to get all tasks and periodic tasks in Celery [duplicate]. https://stackoverflow.com/a/12652113

How to set environment variables on Docker containers via docker-compose file

Posted on: August 18th, 2022 by Olu No Comments

Hi folks,

In this post I briefly go over how to set environment variables in your docker container which is managed by a docker-compose.yaml file.

You can use the env_file flag. Suppose you set environment variables in a file .env, you can read environment variables into a container, service_name as follows:

services:
    service_name:
        container_name: service_name
        ...
        env_file:
          - .env

That’s all for now. Till next time, happy software development.

How to install Python 3.6 on MacOS 12 using pyenv

Posted on: August 17th, 2022 by Olu No Comments

Hi folks,

Here’s a quick note on how to install Python 3.6 on MacOS 12 using pyenv.

I needed to do this while workingon a legacy app. Note that Python 3.6 has reached its end-of-life so you should normally be using a more recent version of the langauge as a developer.

Here is the error I was getting:

python-build: use readline from homebrew
Installing Python-3.6.0...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.0.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/q9/s5s1hzrd6m1_0by3tx5j6sh40000gn/T/python-build.20220815235540.47954
Results logged to /var/folders/q9/s5s1hzrd6m1_0by3tx5j6sh40000gn/T/python-build.20220815235540.47954.log

Last 10 log lines:
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include   -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include   -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/olu/.pyenv/versions/3.6.0/openssl/include -I/Users/olu/.pyenv/versions/3.6.0/include  -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/olu/.pyenv/versions/3.6.0/openssl/include -I/Users/olu/.pyenv/versions/3.6.0/include   -DPy_BUILD_CORE  -c ./Modules/pwdmodule.c -o Modules/pwdmodule.o
./Modules/posixmodule.c:8146:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
./Modules/posixmodule.c:10340:5: warning: code will never be executed [-Wunreachable-code]
    Py_FatalError("abort() called from Python code didn't abort!");
    ^~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....

After a lot of research, a solution was found no StackOverflow as follows:

CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" 

LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib"

pyenv install --patch 3.6.13 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

Hopefully this helps others. Till next time, happy software development.

 

References

1. Problems installing python 3.6 with pyenv on Mac OS Big Sur. https://stackoverflow.com/a/68227540.

SonarQube – a tool for monitoring code quality

Posted on: August 6th, 2022 by Olu No Comments

Hi folks,

In this post I will talk about an interesting tool you can use to monitor the quality of your code base when doing software development. The tool is called SonarQube. SonarQube is an open-source platform created by SonarSource and helps with continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells and vulnerabilities. It supports 17 programming languages.

I really like SonarQube because it can help you write more secure and robust code. It’s web user interface is also quite intuitive to use. It highlights issues and gives suggestions on how to fix them, which is pretty helpful.

You can integrate SonarQube checks into your continuous integration pipeline to do code quality checks automatically when code is merged into certain branches or on pushing code into certain branches of your repository. You can set thresholds for various parameters like bugs, vulnerabilities that can be present in a build before failing the build.

There is a community edition of the software, which is free. There are also other paid versions e.g. Developer, Enterprise and Data Center editions.

Thus, if your team really cares about monitoring code quality, I highly recommend SonarQube. That’s all for now. Till next time, happy software development.

References

SonarQube. Wikipedia. https://en.wikipedia.org/wiki/SonarQube.

Dowloads | SonarQube. https://www.sonarqube.org/downloads/.