Commit e3ab8f26 authored by Elia Ponzio's avatar Elia Ponzio
Browse files

finish ping task

parent 50d5e08e
from django.contrib import admin
from cynomys.models import Deltas
from cynomys.models import Delta
# Register your models here.
class DeltaAdmin(admin.ModelAdmin):
model = Deltas
model = Delta
list_display = ('task', 'success', 'timestamp', 'latest_check', 'return_value'), DeltaAdmin), DeltaAdmin)
# Generated by Django 3.2.4 on 2021-06-24 17:57
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('django_celery_beat', '0016_auto_20210624_1313'),
('cynomys', '0002_deltas_return_value'),
operations = [
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('timestamp', models.DateTimeField(editable=False)),
('success', models.BooleanField(blank=True, null=True)),
('latest_check', models.DateTimeField()),
('return_value', models.CharField(blank=True, max_length=100)),
('task', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_celery_beat.periodictask')),
from django.db import models
from django_celery_beat.models import PeriodicTask
from django.utils import timezone
# Create your models here.
class Deltas(models.Model):
class Delta(models.Model):
task = models.ForeignKey(PeriodicTask, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(editable=False)
success = models.BooleanField(null=True, blank=True)
latest_check = models.DateTimeField(auto_now=True)
latest_check = models.DateTimeField()
return_value = models.CharField(max_length=100, blank=True)
def save(self, *args, **kwargs):
''' On save, update timestamps '''
if not
self.timestamp =
self.latest_check =
return super(Delta, self).save(*args, **kwargs)
from celery import shared_task
from django_celery_beat.models import PeriodicTask
import subprocess
from django.utils import timezone
from django_celery_beat.models import PeriodicTask
from cynomys.models import Delta
def ping(host, timeout, **kwargs):
......@@ -12,5 +14,27 @@ def ping(host, timeout, **kwargs):
print("the parent task: " +
if response.returncode:
if response.returncode == 0:
return_value = "Success!"
obj, created = Delta.objects.get_or_create(task=parent_task, success=True,
if obj.success:
obj.success = True
return_value = "Failure to Ping!"
obj, created = Delta.objects.get_or_create(task=parent_task, success=False,
if not obj.success:
obj.success = False
print("Updated delta for " +
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