2023-12-03
Goal
Fix Celery implementation into the DIMMiN App so we can add timezone functionality to the Taskmaster App.
Notes
Timezone Functionality / Midnight Reset
I asked ChatGPT what the problem was and it nailed it right away. The Procfile had set up a Celery Beat which acts as a scheduler (something to tell when to execute a shared task) but hadn't actually set up a worker to execute that task. Therefore, I needed to add another worker dyno back to the procfile via the
worker: celery -A config worker --loglevel=info
Now shared tasks can actually be executed by the Celery Worker on the schedule set by the Celery Beat.
After playing around with the reset_tasks_at_midnight
task, I was able to finally implement and confirm the functionality of the midnight reset to the task app! Yay! For now this does everything I need it to, but I'll add some potential improvements to the actual Taskmaster App Notes to add more functionality in the UI. Since I can already do everything I need to do here (and with pgadmin to get the long-term historical data) I will come back to this when I need to.
And Now.... IT'S TIME for HitHub!!
After learning a lot more about Django and how it works, I think it would actually make a great Backend for the HitHub App. On this project I'd like to make better use of Docker and try to be more disciplined about how to use Staging and Production environments (which means I will need to make use of Heroku Pipelines and better use of Git).
HitHub Backend - Getting Started
We already have everything set up on my Local Version to get started, at least except for Docker. I'll start following Django For Professionals, starting on chapter 2 to get that installed.
Therefore, I decided to follow and write up a quick Docker Installation Guide to install it. Then I needed to Dockerize the HitHub App.
I made a Python Virtual Environment in a test folder via the command
python -m venv .venv
to create the ch2
venv. then I had to activate the venv by using the commands
$ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
$ .venv/bin/activate
Then I could install Django within my venv via
pip install django
Then I started a new Django project with the following lines:
django-admin startproject django_project .
python manage.py migrate
python manage.py runserver
And lo and behold I had my project up and running! I then made a pages app and got that set up just as a test. Then after creating a requirements.txt
file by running the following:
pip freeze > requirements.txt
I was ready to view the image in Docker.
Connecting to Docker
I needed to establish a Docker Image that would create a Docker Container so I could actually Dockerize this toy example. To do all this docker stuff, we need to create a Dockerfile.
I used the Dockerfile referenced in the book, which was:
# Pull Base Image
FROM python:3.10.5-slim-bullseye
# Set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR C:\Users\Billy\Desktop\django_for_professionals
# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# Copy project
COPY . .
Results
- Learned that Celery Beat schedulers need Celery Workers to execute their commands
- Added midnight resets per user via Celery
- Started to learn about Docker
Next Time
- Finish up setting up the HitHub App based on following the guide in Django For Professionals