def delete_crawl_job(request, job_id): if request.method == 'DELETE': try: mongo_connection = MongoConnection() json_data = mongo_connection.get_items("jobs", {'unique_id': job_id}) if len(json_data) == 0: return JsonResponse({'Error': 'Requested job id' + str(job_id) + 'does not exists'}, status=400) # this should be a interval or cron job celery_task_name = "" if len(json_data) > 1: for obj in json_data: if 'celery_task_name' in obj: celery_task_name = obj['celery_task_name'] break delete_count = 0 if json_data[0]['schedule_category'] == INSTANT: delete_count = mongo_connection.delete_items("jobs", {'unique_id': job_id}) else: # delete scheduled task from django beat if not celery_task_name: celery_task_name = json_data[0]['celery_task_name'] delete_schedule_job(celery_task_name) delete_count = mongo_connection.delete_items("jobs", {'unique_id': job_id}) if delete_count == 0: return JsonResponse({'Error': 'Delete action failed for the job_id: ' + str(job_id)}, status=400) except Exception as e: return JsonResponse({'Error': 'Error while deleting the job from the database, ' + str(e)}, status=400) return JsonResponse({'Status': "SUCCESS", 'Message': 'Crawl job deleted successfully'})
def delete_crawl_task(request, task_id): if request.method == 'DELETE': try: mongo_connection = MongoConnection() delete_count = mongo_connection.delete_items("jobs", {'task_id': task_id}) if delete_count == 0: return JsonResponse({'Error': 'Delete action failed for the task_id: ' + str(task_id)}, status=400) except Exception as e: return JsonResponse({'Error': 'Error while deleting the job from the database, ' + str(e)}, status=400) return JsonResponse({'Status': "SUCCESS", 'Message': 'Crawl job deleted successfully'})