mirror of
https://github.com/bugsink/bugsink.git
synced 2026-01-06 13:20:20 -06:00
celery: basic config (quickstart); alerts startapp
I've checked that this celery config actually works (also with TASK_ALWAYS_EAGER=False)
This commit is contained in:
0
alerts/__init__.py
Normal file
0
alerts/__init__.py
Normal file
3
alerts/admin.py
Normal file
3
alerts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
alerts/apps.py
Normal file
6
alerts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AlertsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'alerts'
|
||||
0
alerts/migrations/__init__.py
Normal file
0
alerts/migrations/__init__.py
Normal file
3
alerts/models.py
Normal file
3
alerts/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
6
alerts/tasks.py
Normal file
6
alerts/tasks.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from celery import shared_task
|
||||
|
||||
|
||||
@shared_task
|
||||
def add(x, y):
|
||||
return x + y
|
||||
3
alerts/tests.py
Normal file
3
alerts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
alerts/views.py
Normal file
3
alerts/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -0,0 +1,4 @@
|
||||
# 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',)
|
||||
|
||||
20
bugsink/celery.py
Normal file
20
bugsink/celery.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bugsink.settings')
|
||||
|
||||
app = Celery('bugsink')
|
||||
|
||||
# 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, ignore_result=True)
|
||||
def debug_task(self):
|
||||
print(f'Request: {self.request!r}')
|
||||
@@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
||||
'ingest',
|
||||
'issues',
|
||||
'events',
|
||||
'alerts',
|
||||
|
||||
'performance',
|
||||
]
|
||||
@@ -137,6 +138,12 @@ STATICFILES_DIRS = [
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
||||
# Generic CELERY settings (i.e. no expected config per-installation)
|
||||
|
||||
CELERY_IGNORE_RESULT = True # we don't use the "result" part of celery
|
||||
CELERY_BROKER_CONNECTION_TIMEOUT = 2.5 # long enough for glitches, short enough to get notified about real problems
|
||||
|
||||
|
||||
# ###################### SERVER-MODE SETTINGS #################
|
||||
|
||||
BUGSINK_DIGEST_IMMEDIATELY = True
|
||||
@@ -157,3 +164,7 @@ if SENTRY_DSN is not None:
|
||||
)
|
||||
|
||||
BASE_URL = "http://glitchtip:9000" # no trailing slash
|
||||
|
||||
|
||||
CELERY_BROKER_URL = 'amqp://bugsink:bugsink@localhost/'
|
||||
CELERY_TASK_ALWAYS_EAGER = True
|
||||
|
||||
@@ -70,7 +70,7 @@ class BaseIngestAPIView(APIView):
|
||||
# before proceeding because it may be useful for debugging errors in the digest process.
|
||||
ingested_event = cls.ingest_event(now, event_data, request, project)
|
||||
if settings.BUGSINK_DIGEST_IMMEDIATELY:
|
||||
cls.digest_event(ingested_event, event_data)
|
||||
cls.digest_event(ingested_event, event_data, alerter_foo)
|
||||
|
||||
@classmethod
|
||||
def ingest_event(cls, now, event_data, request, project):
|
||||
|
||||
@@ -4,3 +4,4 @@ djangorestframework==3.14.*
|
||||
django-tailwind==3.6.*
|
||||
jsonschema==4.19.*
|
||||
semver==3.0.*
|
||||
Celery[librabbitmq]
|
||||
|
||||
Reference in New Issue
Block a user