Skip to content

SHINO-01/Django-CRON

Repository files navigation

Django-CRON

Introduction

Django-CRON is a project aimed at setting up and running cron jobs in a Django application using Docker. This repository provides the necessary scripts and instructions to get your Django cron jobs up and running.

Features

  • Easy setup of virtual environments for both macOS/Linux and Windows
  • Docker integration for managing Django migrations and creating superusers
  • Instructions for running cron jobs within the Django application

Prerequisites

  • Python 3.x
  • Docker

Setup

Create a Virtual Environment

On macOS/Linux:

python3 -m venv env
source env/bin/activate

On Windows:

python -m venv env
env\Scripts\activate

Docker Setup:


docker compose up --build
//open another terminal and then:
docker exec -it cron_Django python manage.py makemigrations
docker exec -it cron_Django python manage.py migrate

Create Superuser:

docker exec -it cron_Django python manage.py createsuperuser

Setting up PostgreSQL

Go to http://localhost:5050/
Enter these credentials and press the Login button:
Email Address / Username: [email protected]
Password: admin123
Right click on Servers and then Register > Server
In General tab, enter Name: testCRON
In Connection tab, enter these details and click Save
Host name/address: cron_Postgres
Username: postUser
Password: password
Then go to Servers > testCRON > Databases > cron_db > Schemas > public > Tables
To view table click on View/Edit Data > All Rows

Running Cron Jobs

To run cron jobs, go to the manage.py directory and run these commands:

# Install dependencies
**run this from the root directory**
pip install -r requirements.txt

Change the CSV file path:(Defaults are:)

file_path = "C:/Users/User/Downloads/KayakTransactionReport.csv" output_file = "C:/Users/User/Downloads/ProcessedReport.csv"

Run cron jobs

cd cron_project python manage.py runcrons

Open Django shell

python manage.py shell

Import and run the cron job

from import_export.cron_jobs import FileProcessingCronJob

cron = FileProcessingCronJob() cron.do()

Exit the shell

exit()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •