Commit 868631c4 authored by Elia Ponzio's avatar Elia Ponzio
Browse files

Project structure

parent b5ea5bbb
......@@ -44,3 +44,7 @@ deactivate
```
docker-compose up -d
```
from django_celery_beat.models import PeriodicTask, IntervalSchedule
schedule, created = IntervalSchedule.objects.get_or_create(every=10,period=IntervalSchedule.SECONDS,)
PeriodicTask.objects.create(interval=schedule,name='hello_world',task='cynomys.tasks.example',)
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CynomysConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'cynomys'
import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('cynomys')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
from django.db import models
# Create your models here.
def helloworld():
print("Oh Hai world! ")
from django.test import TestCase
# Create your tests here.
"""cynomys URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
]
from django.shortcuts import render
# Create your views here.
......@@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cynomys.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
......
"""
ASGI config for cynomys project.
ASGI config for project project.
It exposes the ASGI callable as a module-level variable named ``application``.
......@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cynomys.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
application = get_asgi_application()
"""
Django settings for cynomys project.
Django settings for project project.
Generated by 'django-admin startproject' using Django 3.2.4.
......@@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-ujvg=re12hol9(+tr6z+ist@p%z(pb+xj6jxv6#a6^c0j##2x6'
SECRET_KEY = 'django-insecure-3)js=tgt0gjmckfqxwzpik6ou*e1vae(d8a8v-#$-ti(g-$!b#'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
......@@ -29,16 +29,23 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
DJANGO_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
THIRD_PARTY_APPS = (
'django_celery_beat',
]
)
LOCAL_APPS = (
'cynomys',
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
......@@ -50,7 +57,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'cynomys.urls'
ROOT_URLCONF = 'project.urls'
TEMPLATES = [
{
......@@ -68,7 +75,7 @@ TEMPLATES = [
},
]
WSGI_APPLICATION = 'cynomys.wsgi.application'
WSGI_APPLICATION = 'project.wsgi.application'
# Database
......@@ -124,3 +131,7 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Celery settings
CELERY_BROKER_URL = "redis://127.0.0.1:6379/0"
CELERY_RESULT_BACKEND = "redis://127.0.0.1:6379/0"
"""project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('cynomys.urls')),
]
"""
WSGI config for cynomys project.
WSGI config for project project.
It exposes the WSGI callable as a module-level variable named ``application``.
......@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cynomys.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
application = get_wsgi_application()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment