NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


class FetchOrderIDAPIView(APIView):
def post(self, request):
try:
if not is_valid_token(request):
return Response({'error': 'Unauthorized'}, status=status.HTTP_401_UNAUTHORIZED)

order_id = request.query_params.get('order_id')
status_param = request.query_params.get('status')
print("This is working!!!!!!!!!!!!")

if not order_id:
return Response({'error': 'Invalid request, order_id not provided'}, status=status.HTTP_400_BAD_REQUEST)

# Construct URLs
url_order_detail = reverse('FetchOrderDetailAPIView')
absolute_url_order_detail = self.request.build_absolute_uri(url_order_detail)
print("working2222222222222222222222222222222")
url_filter_drivers = reverse('FilterDrivers')
absolute_url_filter_drivers = self.request.build_absolute_uri(url_filter_drivers)

# Handle status update logic
order_id_instance = OrderID.objects.filter(order_id=order_id).first()
if status_param is not None:
if not order_id_instance:
return Response({'error': 'Order ID not found'}, status=status.HTTP_404_NOT_FOUND)

if order_id_instance.status == 1:
return Response({'message': f'Data for order ID {order_id} not retrieved yet so status cannot be updated'}, status=status.HTTP_200_OK)
# Update status
OrderDetail.objects.filter(order_id=order_id_instance).update(status=status_param)
print("zsccccczZcxzc")
# Chain Celery tasks to execute sequentially
task_chain = chain(
call_order_detail_api1.s(absolute_url_order_detail, order_id),
call_filter_drivers_api1.s(absolute_url_filter_drivers, order_id)
)
result = task_chain.apply_async()
print("this is working3333333")
return Response({
"message": "Status updated successfully",
"order_id": order_id,
"task_chain_id": result.id, # Use result.id to get the task chain ID
}, status=status.HTTP_200_OK)

else:
# Handle order creation and trigger background tasks
order_id_obj, created = OrderID.objects.get_or_create(order_id=order_id)
if created:
order_id_obj.status = 1
order_id_obj.save()

# Chain Celery tasks to ensure sequential execution
task_chain = chain(
call_order_detail_api1.s(absolute_url_order_detail, order_id), # s() keeps arguments fixed
call_filter_drivers_api1.si(absolute_url_filter_drivers, order_id) # si() ensures no input from previous task
)
result = task_chain.apply_async()
print("running-----------------")
return Response({
'message': 'OrderID created and background tasks initiated',
'order_id': order_id,
'task_chain_id': result.id, # Use result.id to get the task chain ID
}, status=status.HTTP_201_CREATED)

except Exception as e:
logger.error("An error occurred: %s", str(e)) # Log the error
return Response({'error': 'An error occurred while processing the request'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.