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
+
5
+ ## Base URL
6
+
7
+ For local development: `http://localhost:5000`
8
+ For production: Your HuggingFace space URL
9
+
10
+ ## Authentication
11
+
12
+ Most endpoints require authentication via JWT token. To authenticate:
13
+
14
+ 1. Get a token by calling the login endpoint
15
+ 2. Include the token in your requests in the `Authorization` header:
16
+ ```
17
+ Authorization: Bearer <your_jwt_token>
18
+ ```
19
+
20
+ ### Authentication Endpoints
21
+
22
+ #### Login
23
+
24
+ ```
25
+ POST /api/auth/login
26
+ ```
27
+
28
+ **Request Body:**
29
+ ```json
30
+ {
31
+ "email": "user@example.com",
32
+ "password": "your_password"
33
+ }
34
+ ```
35
+
36
+ **Response:**
37
+ ```json
38
+ {
39
+ "message": "Login successful",
40
+ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
41
+ "user": {
42
+ "_id": "60d21b4967d0d8992e610c85",
43
+ "email": "user@example.com",
44
+ "name": "John Doe",
45
+ "permissions": "Admin",
46
+ "position": "Officer",
47
+ "department_id": "60d21b4967d0d8992e610c85",
48
+ "logs": [],
49
+ "incidents": []
50
+ }
51
+ }
52
+ ```
53
+
54
+ #### Get Current User
55
+
56
+ ```
57
+ GET /api/auth/me
58
+ ```
59
+
60
+ **Response:**
61
+ ```json
62
+ {
63
+ "user": {
64
+ "_id": "60d21b4967d0d8992e610c85",
65
+ "email": "user@example.com",
66
+ "name": "John Doe",
67
+ "permissions": "Admin",
68
+ "position": "Officer",
69
+ "department_id": "60d21b4967d0d8992e610c85",
70
+ "logs": [],
71
+ "incidents": []
72
+ }
73
+ }
74
+ ```
75
+
76
+ #### Update Password
77
+
78
+ ```
79
+ PUT /api/auth/password
80
+ ```
81
+
82
+ **Request Body:**
83
+ ```json
84
+ {
85
+ "current_password": "your_current_password",
86
+ "new_password": "your_new_password"
87
+ }
88
+ ```
89
+
90
+ **Response:**
91
+ ```json
92
+ {
93
+ "message": "Password updated successfully"
94
+ }
95
+ ```
96
+
97
+ #### Update Profile
98
+
99
+ ```
100
+ PUT /api/auth/profile
101
+ ```
102
+
103
+ **Request Body:**
104
+ ```json
105
+ {
106
+ "name": "New Name",
107
+ "position": "New Position"
108
+ }
109
+ ```
110
+
111
+ **Response:**
112
+ ```json
113
+ {
114
+ "message": "Profile updated successfully",
115
+ "user": {
116
+ // Updated user object
117
+ }
118
+ }
119
+ ```
120
+
121
+ #### Reset Password (Admin Only)
122
+
123
+ ```
124
+ POST /api/auth/reset-password
125
+ ```
126
+
127
+ **Request Body:**
128
+ ```json
129
+ {
130
+ "user_id": "60d21b4967d0d8992e610c85",
131
+ "new_password": "new_password" // Optional, a random password will be generated if not provided
132
+ }
133
+ ```
134
+
135
+ **Response:**
136
+ ```json
137
+ {
138
+ "message": "Password reset successfully",
139
+ "user": {
140
+ // User object
141
+ },
142
+ "new_password": "random_password" // Included only if a random password was generated
143
+ }
144
+ ```
145
+
146
+ ## Department Endpoints
147
+
148
+ ### Create Department
149
+
150
+ ```
151
+ POST /api/departments
152
+ ```
153
+
154
+ **Request Body:**
155
+ ```json
156
+ {
157
+ "name": "Police Department",
158
+ "address": "123 Main St, City, State, ZIP",
159
+ "website": "https://example.com",
160
+ "admin_email": "admin@example.com",
161
+ "admin_name": "Admin User",
162
+ "admin_password": "admin_password",
163
+ "admin_position": "Administrator"
164
+ }
165
+ ```
166
+
167
+ **Response:**
168
+ ```json
169
+ {
170
+ "message": "Department and admin user created successfully",
171
+ "department": {
172
+ "_id": "60d21b4967d0d8992e610c85",
173
+ "name": "Police Department",
174
+ "address": "123 Main St, City, State, ZIP",
175
+ "website": "https://example.com",
176
+ "members": ["60d21b4967d0d8992e610c86"],
177
+ "workflows": []
178
+ },
179
+ "admin_user": {
180
+ "_id": "60d21b4967d0d8992e610c86",
181
+ "email": "admin@example.com",
182
+ "name": "Admin User",
183
+ "permissions": "Admin",
184
+ "position": "Administrator",
185
+ "department_id": "60d21b4967d0d8992e610c85"
186
+ }
187
+ }
188
+ ```
189
+
190
+ ### Get All Departments
191
+
192
+ ```
193
+ GET /api/departments
194
+ ```
195
+
196
+ **Response:**
197
+ ```json
198
+ {
199
+ "departments": [
200
+ {
201
+ "_id": "60d21b4967d0d8992e610c85",
202
+ "name": "Police Department",
203
+ "address": "123 Main St, City, State, ZIP",
204
+ "website": "https://example.com",
205
+ "members": ["60d21b4967d0d8992e610c86"],
206
+ "workflows": []
207
+ }
208
+ ]
209
+ }
210
+ ```
211
+
212
+ ### Get Department by ID
213
+
214
+ ```
215
+ GET /api/departments/:department_id
216
+ ```
217
+
218
+ **Response:**
219
+ ```json
220
+ {
221
+ "department": {
222
+ "_id": "60d21b4967d0d8992e610c85",
223
+ "name": "Police Department",
224
+ "address": "123 Main St, City, State, ZIP",
225
+ "website": "https://example.com",
226
+ "members": ["60d21b4967d0d8992e610c86"],
227
+ "workflows": []
228
+ }
229
+ }
230
+ ```
231
+
232
+ ### Update Department (Admin Only)
233
+
234
+ ```
235
+ PUT /api/departments/:department_id
236
+ ```
237
+
238
+ **Request Body:**
239
+ ```json
240
+ {
241
+ "name": "Updated Department Name",
242
+ "address": "New Address",
243
+ "website": "https://new-website.com"
244
+ }
245
+ ```
246
+
247
+ **Response:**
248
+ ```json
249
+ {
250
+ "message": "Department updated successfully",
251
+ "department": {
252
+ // Updated department object
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### Delete Department (Admin Only)
258
+
259
+ ```
260
+ DELETE /api/departments/:department_id
261
+ ```
262
+
263
+ **Response:**
264
+ ```json
265
+ {
266
+ "message": "Department and all its users deleted successfully"
267
+ }
268
+ ```
269
+
270
+ ### Get Department Members
271
+
272
+ ```
273
+ GET /api/departments/:department_id/members
274
+ ```
275
+
276
+ **Response:**
277
+ ```json
278
+ {
279
+ "members": [
280
+ {
281
+ "_id": "60d21b4967d0d8992e610c86",
282
+ "email": "admin@example.com",
283
+ "name": "Admin User",
284
+ "permissions": "Admin",
285
+ "position": "Administrator"
286
+ }
287
+ ]
288
+ }
289
+ ```
290
+
291
+ ### Add Member (Admin Only)
292
+
293
+ ```
294
+ POST /api/departments/:department_id/members
295
+ ```
296
+
297
+ **Request Body:**
298
+ ```json
299
+ {
300
+ "email": "new_member@example.com",
301
+ "name": "New Member",
302
+ "position": "Officer",
303
+ "permissions": "User"
304
+ }
305
+ ```
306
+
307
+ **Response:**
308
+ ```json
309
+ {
310
+ "message": "Member added successfully",
311
+ "user": {
312
+ // New user object
313
+ },
314
+ "raw_password": "random_password" // Password for the new user
315
+ }
316
+ ```
317
+
318
+ ### Add Members via CSV (Admin Only)
319
+
320
+ ```
321
+ POST /api/departments/:department_id/members/csv
322
+ ```
323
+
324
+ **Request:**
325
+ Multipart form data with a CSV file containing member information.
326
+
327
+ **Response:**
328
+ ```json
329
+ {
330
+ "message": "Processed 5 new users with 0 errors",
331
+ "new_users": [
332
+ // Array of new user objects, each containing a raw_password
333
+ ],
334
+ "errors": [
335
+ // Array of error messages, if any
336
+ ]
337
+ }
338
+ ```
339
+
340
+ ### Remove Member (Admin Only)
341
+
342
+ ```
343
+ DELETE /api/departments/:department_id/members/:user_id
344
+ ```
345
+
346
+ **Response:**
347
+ ```json
348
+ {
349
+ "message": "Member removed successfully"
350
+ }
351
+ ```
352
+
353
+ ### Update Member Permissions (Admin Only)
354
+
355
+ ```
356
+ PUT /api/departments/:department_id/members/:user_id/permissions
357
+ ```
358
+
359
+ **Request Body:**
360
+ ```json
361
+ {
362
+ "permissions": "Admin" // Or "User"
363
+ }
364
+ ```
365
+
366
+ **Response:**
367
+ ```json
368
+ {
369
+ "message": "Member permissions updated successfully",
370
+ "user": {
371
+ // Updated user object
372
+ }
373
+ }
374
+ ```
375
+
376
+ ## Workflow Endpoints
377
+
378
+ ### Get All Department Workflows
379
+
380
+ ```
381
+ GET /api/workflows
382
+ ```
383
+
384
+ **Response:**
385
+ ```json
386
+ {
387
+ "workflows": [
388
+ {
389
+ "_id": "60d21b4967d0d8992e610c87",
390
+ "title": "Traffic Violation Workflow",
391
+ "description": "Process for handling traffic violations",
392
+ "department_id": "60d21b4967d0d8992e610c85",
393
+ "data_requirements": [
394
+ {
395
+ "field": "license_plate",
396
+ "description": "Vehicle license plate number"
397
+ }
398
+ ],
399
+ "form_fields": [],
400
+ "raw_forms": []
401
+ }
402
+ ]
403
+ }
404
+ ```
405
+
406
+ ### Create Workflow (Admin Only)
407
+
408
+ ```
409
+ POST /api/workflows
410
+ ```
411
+
412
+ **Request Body:**
413
+ ```json
414
+ {
415
+ "title": "Traffic Violation Workflow",
416
+ "description": "Process for handling traffic violations",
417
+ "data_requirements": [
418
+ {
419
+ "field": "license_plate",
420
+ "description": "Vehicle license plate number"
421
+ }
422
+ ],
423
+ "form_fields": []
424
+ }
425
+ ```
426
+
427
+ **Response:**
428
+ ```json
429
+ {
430
+ "message": "Workflow created successfully",
431
+ "workflow": {
432
+ // New workflow object
433
+ }
434
+ }
435
+ ```
436
+
437
+ ### Get Workflow by ID
438
+
439
+ ```
440
+ GET /api/workflows/:workflow_id
441
+ ```
442
+
443
+ **Response:**
444
+ ```json
445
+ {
446
+ "workflow": {
447
+ "_id": "60d21b4967d0d8992e610c87",
448
+ "title": "Traffic Violation Workflow",
449
+ "description": "Process for handling traffic violations",
450
+ "department_id": "60d21b4967d0d8992e610c85",
451
+ "data_requirements": [
452
+ {
453
+ "field": "license_plate",
454
+ "description": "Vehicle license plate number"
455
+ }
456
+ ],
457
+ "form_fields": [],
458
+ "raw_forms": []
459
+ }
460
+ }
461
+ ```
462
+
463
+ ### Update Workflow (Admin Only)
464
+
465
+ ```
466
+ PUT /api/workflows/:workflow_id
467
+ ```
468
+
469
+ **Request Body:**
470
+ ```json
471
+ {
472
+ "title": "Updated Workflow Title",
473
+ "description": "Updated description",
474
+ "data_requirements": [
475
+ // Updated data requirements
476
+ ],
477
+ "form_fields": [
478
+ // Updated form fields
479
+ ]
480
+ }
481
+ ```
482
+
483
+ **Response:**
484
+ ```json
485
+ {
486
+ "message": "Workflow updated successfully",
487
+ "workflow": {
488
+ // Updated workflow object
489
+ }
490
+ }
491
+ ```
492
+
493
+ ### Delete Workflow (Admin Only)
494
+
495
+ ```
496
+ DELETE /api/workflows/:workflow_id
497
+ ```
498
+
499
+ **Response:**
500
+ ```json
501
+ {
502
+ "message": "Workflow deleted successfully"
503
+ }
504
+ ```
505
+
506
+ ### Add Data Requirement (Admin Only)
507
+
508
+ ```
509
+ POST /api/workflows/:workflow_id/data-requirements
510
+ ```
511
+
512
+ **Request Body:**
513
+ ```json
514
+ {
515
+ "field": "driver_license",
516
+ "description": "Driver's license number"
517
+ }
518
+ ```
519
+
520
+ **Response:**
521
+ ```json
522
+ {
523
+ "message": "Data requirement added successfully",
524
+ "workflow": {
525
+ // Updated workflow object
526
+ }
527
+ }
528
+ ```
529
+
530
+ ### Remove Data Requirement (Admin Only)
531
+
532
+ ```
533
+ DELETE /api/workflows/:workflow_id/data-requirements
534
+ ```
535
+
536
+ **Request Body:**
537
+ ```json
538
+ {
539
+ "index": 0
540
+ }
541
+ ```
542
+
543
+ **Response:**
544
+ ```json
545
+ {
546
+ "message": "Data requirement removed successfully",
547
+ "workflow": {
548
+ // Updated workflow object
549
+ }
550
+ }
551
+ ```
552
+
553
+ ### Upload Form (Admin Only)
554
+
555
+ ```
556
+ POST /api/workflows/:workflow_id/forms
557
+ ```
558
+
559
+ **Request:**
560
+ Multipart form data with a PDF file.
561
+
562
+ **Response:**
563
+ ```json
564
+ {
565
+ "message": "Form uploaded successfully",
566
+ "form_url": "https://res.cloudinary.com/...",
567
+ "workflow": {
568
+ // Updated workflow object
569
+ }
570
+ }
571
+ ```
572
+
573
+ ### Remove Form (Admin Only)
574
+
575
+ ```
576
+ DELETE /api/workflows/:workflow_id/forms
577
+ ```
578
+
579
+ **Request Body:**
580
+ ```json
581
+ {
582
+ "form_url": "https://res.cloudinary.com/..."
583
+ }
584
+ ```
585
+
586
+ **Response:**
587
+ ```json
588
+ {
589
+ "message": "Form removed successfully",
590
+ "workflow": {
591
+ // Updated workflow object
592
+ }
593
+ }
594
+ ```
595
+
596
+ ### Add Form Field (Admin Only)
597
+
598
+ ```
599
+ POST /api/workflows/:workflow_id/form-fields
600
+ ```
601
+
602
+ **Request Body:**
603
+ ```json
604
+ {
605
+ "position": {"x": 100, "y": 100},
606
+ "field_name": "license_plate"
607
+ }
608
+ ```
609
+
610
+ **Response:**
611
+ ```json
612
+ {
613
+ "message": "Form field added successfully",
614
+ "workflow": {
615
+ // Updated workflow object
616
+ }
617
+ }
618
+ ```
619
+
620
+ ### Remove Form Field (Admin Only)
621
+
622
+ ```
623
+ DELETE /api/workflows/:workflow_id/form-fields
624
+ ```
625
+
626
+ **Request Body:**
627
+ ```json
628
+ {
629
+ "index": 0
630
+ }
631
+ ```
632
+
633
+ **Response:**
634
+ ```json
635
+ {
636
+ "message": "Form field removed successfully",
637
+ "workflow": {
638
+ // Updated workflow object
639
+ }
640
+ }
641
+ ```
642
+
643
+ ## Log Endpoints
644
+
645
+ ### Upload Log
646
+
647
+ ```
648
+ POST /api/logs
649
+ ```
650
+
651
+ **Request:**
652
+ Multipart form data with:
653
+ - `file`: PDF file of the log
654
+ - `log_date`: Date in YYYY-MM-DD format
655
+
656
+ **Response:**
657
+ ```json
658
+ {
659
+ "message": "Log uploaded successfully and processing started",
660
+ "log": {
661
+ "_id": "60d21b4967d0d8992e610c88",
662
+ "user_id": "60d21b4967d0d8992e610c86",
663
+ "department_id": "60d21b4967d0d8992e610c85",
664
+ "log_date": "2023-05-15",
665
+ "log_file": "https://res.cloudinary.com/...",
666
+ "incidents": []
667
+ }
668
+ }
669
+ ```
670
+
671
+ ### Get User Logs
672
+
673
+ ```
674
+ GET /api/logs/user
675
+ ```
676
+
677
+ **Response:**
678
+ ```json
679
+ {
680
+ "logs": [
681
+ {
682
+ "_id": "60d21b4967d0d8992e610c88",
683
+ "user_id": "60d21b4967d0d8992e610c86",
684
+ "department_id": "60d21b4967d0d8992e610c85",
685
+ "log_date": "2023-05-15",
686
+ "log_file": "https://res.cloudinary.com/...",
687
+ "incidents": []
688
+ }
689
+ ]
690
+ }
691
+ ```
692
+
693
+ ### Get Department Logs (Admin Only)
694
+
695
+ ```
696
+ GET /api/logs/department
697
+ ```
698
+
699
+ **Response:**
700
+ ```json
701
+ {
702
+ "logs": [
703
+ // Array of all logs in the department
704
+ ]
705
+ }
706
+ ```
707
+
708
+ ### Get Logs by Date Range
709
+
710
+ ```
711
+ POST /api/logs/date-range
712
+ ```
713
+
714
+ **Request Body:**
715
+ ```json
716
+ {
717
+ "start_date": "2023-05-01",
718
+ "end_date": "2023-05-31"
719
+ }
720
+ ```
721
+
722
+ **Response:**
723
+ ```json
724
+ {
725
+ "logs": [
726
+ // Array of logs within the date range
727
+ ]
728
+ }
729
+ ```
730
+
731
+ ### Get Log by ID
732
+
733
+ ```
734
+ GET /api/logs/:log_id
735
+ ```
736
+
737
+ **Response:**
738
+ ```json
739
+ {
740
+ "log": {
741
+ "_id": "60d21b4967d0d8992e610c88",
742
+ "user_id": "60d21b4967d0d8992e610c86",
743
+ "department_id": "60d21b4967d0d8992e610c85",
744
+ "log_date": "2023-05-15",
745
+ "log_file": "https://res.cloudinary.com/...",
746
+ "incidents": []
747
+ }
748
+ }
749
+ ```
750
+
751
+ ### Delete Log
752
+
753
+ ```
754
+ DELETE /api/logs/:log_id
755
+ ```
756
+
757
+ **Response:**
758
+ ```json
759
+ {
760
+ "message": "Log and associated incidents deleted successfully"
761
+ }
762
+ ```
763
+
764
+ ## Incident Endpoints
765
+
766
+ ### Get User Incidents
767
+
768
+ ```
769
+ GET /api/incidents/user
770
+ ```
771
+
772
+ **Response:**
773
+ ```json
774
+ {
775
+ "incidents": [
776
+ {
777
+ "_id": "60d21b4967d0d8992e610c89",
778
+ "department_id": "60d21b4967d0d8992e610c85",
779
+ "user_id": "60d21b4967d0d8992e610c86",
780
+ "workflow_id": "60d21b4967d0d8992e610c87",
781
+ "description": "Traffic violation at Main St",
782
+ "date": "2023-05-15",
783
+ "log_id": "60d21b4967d0d8992e610c88",
784
+ "activity_text": "Observed vehicle speeding...",
785
+ "status": "completed",
786
+ "filled_forms": [],
787
+ "extracted_data": {
788
+ "license_plate": "ABC123"
789
+ }
790
+ }
791
+ ]
792
+ }
793
+ ```
794
+
795
+ ### Get Department Incidents (Admin Only)
796
+
797
+ ```
798
+ GET /api/incidents/department
799
+ ```
800
+
801
+ **Response:**
802
+ ```json
803
+ {
804
+ "incidents": [
805
+ // Array of all incidents in the department
806
+ ]
807
+ }
808
+ ```
809
+
810
+ ### Get Incidents by Date Range
811
+
812
+ ```
813
+ POST /api/incidents/date-range
814
+ ```
815
+
816
+ **Request Body:**
817
+ ```json
818
+ {
819
+ "start_date": "2023-05-01",
820
+ "end_date": "2023-05-31"
821
+ }
822
+ ```
823
+
824
+ **Response:**
825
+ ```json
826
+ {
827
+ "incidents": [
828
+ // Array of incidents within the date range
829
+ ]
830
+ }
831
+ ```
832
+
833
+ ### Get Workflow Incidents
834
+
835
+ ```
836
+ GET /api/incidents/workflow/:workflow_id
837
+ ```
838
+
839
+ **Response:**
840
+ ```json
841
+ {
842
+ "incidents": [
843
+ // Array of incidents for the specified workflow
844
+ ]
845
+ }
846
+ ```
847
+
848
+ ### Get Incident by ID
849
+
850
+ ```
851
+ GET /api/incidents/:incident_id
852
+ ```
853
+
854
+ **Response:**
855
+ ```json
856
+ {
857
+ "incident": {
858
+ "_id": "60d21b4967d0d8992e610c89",
859
+ "department_id": "60d21b4967d0d8992e610c85",
860
+ "user_id": "60d21b4967d0d8992e610c86",
861
+ "workflow_id": "60d21b4967d0d8992e610c87",
862
+ "description": "Traffic violation at Main St",
863
+ "date": "2023-05-15",
864
+ "log_id": "60d21b4967d0d8992e610c88",
865
+ "activity_text": "Observed vehicle speeding...",
866
+ "status": "completed",
867
+ "filled_forms": [],
868
+ "extracted_data": {
869
+ "license_plate": "ABC123"
870
+ }
871
+ }
872
+ }
873
+ ```
874
+
875
+ ### Delete Incident
876
+
877
+ ```
878
+ DELETE /api/incidents/:incident_id
879
+ ```
880
+
881
+ **Response:**
882
+ ```json
883
+ {
884
+ "message": "Incident deleted successfully"
885
+ }
886
+ ```
887
+
888
+ ### Reprocess Incident (Admin Only)
889
+
890
+ ```
891
+ POST /api/incidents/:incident_id/reprocess
892
+ ```
893
+
894
+ **Response:**
895
+ ```json
896
+ {
897
+ "message": "Incident reprocessing started",
898
+ "incident": {
899
+ // Updated incident object
900
+ }
901
+ }
902
+ ```
903
+
904
+ ## Utility Endpoints
905
+
906
+ ### Health Check
907
+
908
+ ```
909
+ GET /health
910
+ ```
911
+
912
+ **Response:**
913
+ ```json
914
+ {
915
+ "status": "healthy",
916
+ "mongo": "connected",
917
+ "env_vars": "ok",
918
+ "upload_dir": "/tmp/uploads",
919
+ "log_dir": "/tmp/logs"
920
+ }
921
+ ```
922
+
923
+ ### API Test
924
+
925
+ ```
926
+ GET /api/test
927
+ ```
928
+
929
+ **Response:**
930
+ ```json
931
+ {
932
+ "message": "API test successful",
933
+ "timestamp": "2023-05-15T12:00:00.000Z",
934
+ "environment": "development"
935
+ }
936
+ ```
celery_config.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ # Load environment variables
5
+ load_dotenv()
6
+
7
+ # Celery configuration with hosted Redis server
8
+ redis_password = os.environ.get('REDIS_PASSWORD')
9
+ # Make sure to set these environment variables with the correct values
10
+ redis_host = os.environ.get('REDIS_HOST')
11
+ redis_port = os.environ.get('REDIS_PORT', '6379')
12
+
13
+ # Validate that we have the host information
14
+ if not redis_host:
15
+ raise ValueError("REDIS_HOST environment variable must be set")
16
+
17
+ redis_url = f"redis://:{redis_password}@{redis_host}:{redis_port}/0"
18
+
19
+ broker_url = os.environ.get('REDIS_URL', redis_url)
20
+ result_backend = os.environ.get('REDIS_URL', redis_url)
21
+
22
+ # Task serialization format
23
+ task_serializer = 'json'
24
+ accept_content = ['json']
25
+ result_serializer = 'json'
26
+
27
+ # Enable UTC timezone
28
+ enable_utc = True
29
+
30
+ # Task execution settings
31
+ task_acks_late = True
32
+ task_reject_on_worker_lost = True
33
+ worker_max_tasks_per_child = 1000
34
+
35
+ # Task timeouts
36
+ task_time_limit = 600 # 10 minutes
37
+ task_soft_time_limit = 300 # 5 minutes
38
+
39
+ # Task routes
40
+ task_routes = {
41
+ 'utils.celery_tasks.process_log_document': {'queue': 'logs'},
42
+ 'utils.celery_tasks.process_incident_forms': {'queue': 'incidents'},
43
+ }
44
+
45
+ # Rate limits
46
+ task_annotations = {
47
+ 'utils.celery_tasks.process_log_document': {'rate_limit': '10/h'},
48
+ 'utils.celery_tasks.process_incident_forms': {'rate_limit': '20/h'},
49
+ }