Move model update actions to view rather than task, fixing #19

This commit is contained in:
Kumi 2019-02-24 13:08:32 +00:00
parent 9a6279d080
commit 8e16370769
2 changed files with 5 additions and 7 deletions

View file

@ -14,9 +14,6 @@ import datetime
@shared_task
def mkfirmware(device, path):
if device.firmware and device.firmware > device.model.firmware and device.firmware > device.changed and glob.glob("%s/%s.bin" % (path, device.id)):
return True
BEFORE = os.getcwd()
DEVICEDIR = "/opt/vpnmanager/device-config/%i/" % device.model.id
SRCDIR = "/opt/vpnmanager/imagebuilder/%i/" % device.model.id
@ -87,8 +84,6 @@ def mkfirmware(device, path):
os.system("rm -rf " + SRCDIR + "/files/")
os.system("rm " + SRCDIR + "/bin/targets/ar71xx/generic/*")
device.firmware = datetime.datetime.now()
device.save()
return True
except Exception as e:

View file

@ -75,12 +75,13 @@ def update(request):
device = get_object_or_404(Device, secret=request.POST.get("secret", ""))
try:
if not mkfirmware.delay(device, FWDIR).get(timeout=300):
if not mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300):
return HttpResponse(status=503)
except TimeoutError:
return HttpResponse(status=503)
sigUpdateDevice(device.serial, None, False)
device.firmware = datetime.datetime.now()
device.update = False
device.save()
@ -311,11 +312,13 @@ def getconfig(request, device_id):
FWDIR = "/opt/vpnmanager/images/"
device = get_object_or_404(Device, id=device_id)
files = glob.glob("%s/%s.bin" % (FWDIR, device_id))
if not mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300):
if not ((files and datetime.datetime.fromtimestamp(os.path.getmtime(files[0]), timezone.get_current_timezone()) > device.model.firmware) or mkfirmware.apply_async((device, FWDIR), serializer='pickle').get(timeout=300)):
return HttpResponse(status=503)
sigUpdateDevice(device.serial, None, False)
device.firmware = datetime.datetime.now()
device.update = False
device.save()