Commit 50d5e08e authored by Elia Ponzio's avatar Elia Ponzio
Browse files

Re-structure tasks

parent b85f57d7
# 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 celery import shared_task
from django_celery_beat.models import PeriodicTask
import subprocess
@shared_task
def ping(host, timeout, **kwargs):
response = subprocess.run(["ping", "-c", "1", "-w", timeout, host])
print("ping from " + host + " with return value: " + str(response.returncode))
parent_task = PeriodicTask.objects.get(id=kwargs['task_id'])
print("the parent task: " + parent_task.name)
if response.returncode:
pass
def helloworld():
print("Oh Hai world! ")
# 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',)
......@@ -7,7 +7,7 @@ import subprocess
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('cynomys')
app = Celery('project')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
......@@ -16,7 +16,7 @@ app = Celery('cynomys')
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
app.autodiscover_tasks(['cynomys.tasks',])
@app.task(bind=True)
......@@ -28,15 +28,6 @@ def debug_task(self):
def helloworld():
print("Oh Hai world!")
@app.task()
def ping(host, timeout):
response = subprocess.run(["ping", "-c", "1", "-w", timeout, host])
print("ping from " + host + " with return value: " + str(response.returncode))
if response.returncode:
pass
@app.task()
def http_check():
......
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