I recently followed the Django API tutorial. http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/
When I initiate a POST request my intent is that after inserting the record into database, launch a process. Example:
Will insert a new "server" record, return 201 to API client and behind the scenes I want to launch a process that will install and discover the server via some ssh/icmp. Where is the best place to put this code any tutorial or advise? How can I return a 201 and after that execute my discovery process. Is it better to monitor the db for new records and have a different process doing it?
@csrf_exempt def snippet_list(request): """ List all code snippets, or create a new snippet. """ if request.method == 'GET': snippets = Snippet.objects.all() serializer = SnippetSerializer(snippets, many=True) return JSONResponse(serializer.data) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SnippetSerializer(data=data) if serializer.is_valid(): serializer.save() <? is here?> return JSONResponse(serializer.data, status=201) return JSONResponse(serializer.errors, status=400)