Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ebextensions/03_django.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ container_commands:
command: "python manage.py collectstatic --noinput"
leader_only: true
02_createsu:
command: "manage.py createsu"
command: "python manage.py createsu || true"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't change this

leader_only: true
4 changes: 4 additions & 0 deletions =24.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: packaging in /home/jules/.local/lib/python3.10/site-packages (16.8)
Requirement already satisfied: pyparsing in /home/jules/.local/lib/python3.10/site-packages (from packaging) (2.2.0)
Requirement already satisfied: six in /home/jules/.local/lib/python3.10/site-packages (from packaging) (1.10.0)
4 changes: 4 additions & 0 deletions ebdjango/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# 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',)
2 changes: 1 addition & 1 deletion ebdjango/_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ebdjango.settings')

app = Celery('ebdjango')
app.config_from_object('django.conf:settings')
app.config_from_object('django.conf:settings', namespace='CELERY')

# This line will tell Celery to autodiscover all your tasks.py that are in your app folders
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
8 changes: 5 additions & 3 deletions ebdjango/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django_celery_beat',
'django_celery_results',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Expand Down Expand Up @@ -119,9 +121,9 @@
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_TIMEZONE = TIME_ZONE # Recommended for Celery 5.x
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler' # Updated scheduler
CELERY_RESULT_BACKEND = 'django-db' # Updated result backend
CELERY_SEND_EVENTS = False


Expand Down
5 changes: 5 additions & 0 deletions ebdjango/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from celery import shared_task

@shared_task
def add(x, y):
return x + y
65 changes: 65 additions & 0 deletions ebdjango/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from django.test import TestCase, Client
from django.urls import reverse
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove test file


class AdminViewTests(TestCase):
def test_admin_login_page_loads(self):
"""
Test that the admin login page loads correctly.
It might return 200 if already somehow authenticated by default test client setup,
or 302 if it redirects to a login page.
"""
client = Client()
# Try fetching the admin login URL.
# If LOGIN_URL is customized, this might need adjustment,
# but /admin/login/ is common, or /admin/ will redirect to it.
try:
admin_url = reverse('admin:index')
except Exception:
# Fallback if 'admin:index' is not found (e.g. admin not fully set up for URL reversing)
admin_url = '/admin/'

response = client.get(admin_url)
self.assertIn(
response.status_code,
[200, 302],
f"Admin page ({admin_url}) returned {response.status_code}, expected 200 or 302."
)

class CeleryTaskTests(TestCase):
def test_add_task_importable_and_callable(self):
"""
Test that the sample 'add' task can be imported and is callable.
"""
try:
from .tasks import add
self.assertTrue(callable(add), "Add task 'add' should be callable.")
except ImportError:
self.fail("Could not import task 'add' from ebdjango.tasks.")
except Exception as e:
self.fail(f"An unexpected error occurred during task import/check: {e}")

def test_add_task_basic_execution(self):
"""
A very basic test of the add task's execution logic.
Note: This runs the task synchronously in the test process, not via a Celery worker.
"""
try:
from .tasks import add
result = add.delay(3, 5) # Using .delay() to simulate Celery call style
# For testing purposes with CELERY_TASK_ALWAYS_EAGER=True (often set for tests),
# .delay() might execute synchronously and return an EagerResult.
# If not eager, this would return an AsyncResult.
# We'll check if the result has a 'get' method to fetch the actual return value.
if hasattr(result, 'get'):
# Timeout for safety, though eager tasks should be immediate.
self.assertEqual(result.get(timeout=10), 8, "Task 'add(3, 5)' should return 8.")
else:
# Fallback for when task isn't eager and we just have an AsyncResult
# This part of the test would be more complex in a real scenario
# requiring worker setup or mocking. For now, we just check it didn't fail.
self.assertIsNotNone(result.id, "Task 'add' should return an AsyncResult with an ID.")

except ImportError:
self.fail("Could not import task 'add' from ebdjango.tasks.")
except Exception as e:
self.fail(f"An unexpected error occurred during task execution test: {e}")
8 changes: 4 additions & 4 deletions ebdjango/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
1. Import the include() function: from django.urls import include, re_path
2. Add a URL to urlpatterns: re_path(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.urls import re_path
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
re_path(r'^admin/', admin.site.urls),
]
34 changes: 16 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
amqp==1.4.9
anyjson==0.3.3
amqp>=5.1.1,<6.0.0 # Updated for Celery
appdirs==1.4.3
awsebcli==3.10.1
awsebcli==3.10.1 # Reverted to original
backports.ssl-match-hostname==3.5.0.1
billiard==3.3.0.23
billiard>=4.2.0,<5.0 # Updated for Celery
blessed==1.14.2
botocore==1.5.39
celery==3.1.25
botocore==1.5.39 # Reverted to original
celery[django]>=5.3,<5.4 # Updated as per task
cement==2.8.2
colorama==0.3.7
Django==1.11
-e git+https://github.com/celery/django-celery@5910af77382b249b2ba9b2fe7d3f7f57151ffe74#egg=django_celery
Django>=4.2,<4.3 # Updated as per task
docker-py==1.7.2
dockerpty==0.4.1
docopt==0.6.2
docutils==0.13.1
jmespath==0.9.2
kombu==3.0.37
packaging==16.8
kombu>=5.3.0,<6.0 # Updated for Celery
packaging==16.8 # Reverted to original
pathspec==0.5.0
psycopg2==2.7.1
pyparsing==2.2.0
python-dateutil==2.6.0
pytz==2017.2
PyYAML==3.12
requests==2.9.1
psycopg2-binary<3.0 # Updated psycopg2 to binary
pyparsing==2.2.0 # Reverted to original
python-dateutil>=2.8.2,<3.0.0 # Updated for Celery/botocore
pytz==2017.2 # Reverted to original
PyYAML==3.12 # Reverted to original
requests==2.9.1 # Reverted to original
semantic-version==2.5.0
six==1.10.0
six==1.10.0 # Reverted to original
tabulate==0.7.5
termcolor==1.1.0
wcwidth==0.1.7
websocket-client==0.40.0
# colorama==0.3.7 will be pulled by awsebcli==3.10.1
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9