@@ -42,6 +42,41 @@ def add_arguments(self, parser):
42
42
help = "Handle sending and receiving of Asynchronous MDNs." ,
43
43
)
44
44
45
+ def retry (self , retry_msg ):
46
+ # Increase the retry count
47
+ if not retry_msg .retries :
48
+ retry_msg .retries = 1
49
+ else :
50
+ retry_msg .retries += 1
51
+
52
+ # if max retries has exceeded then mark message status as error
53
+ if retry_msg .retries > settings .MAX_RETRIES :
54
+ if retry_msg .status == "P" :
55
+ retry_msg .detailed_status = (
56
+ "Failed to receive asynchronous MDN within the threshold limit."
57
+ )
58
+ elif retry_msg .status == "R" :
59
+ retry_msg .detailed_status = "Retry count exceeded the limit."
60
+
61
+ retry_msg .status = "E"
62
+ retry_msg .save ()
63
+ return
64
+
65
+ self .stdout .write ("Retry send the message with ID %s" % retry_msg .message_id )
66
+
67
+ # Build and resend the AS2 message
68
+ as2message = AS2Message (
69
+ sender = retry_msg .organization .as2org ,
70
+ receiver = retry_msg .partner .as2partner ,
71
+ )
72
+ as2message .build (
73
+ retry_msg .payload .read (),
74
+ filename = os .path .basename (retry_msg .payload .name ),
75
+ subject = retry_msg .partner .subject ,
76
+ content_type = retry_msg .partner .content_type ,
77
+ )
78
+ retry_msg .send_message (as2message .headers , as2message .content )
79
+
45
80
def handle (self , * args , ** options ):
46
81
47
82
if options ["retry" ]:
@@ -50,35 +85,7 @@ def handle(self, *args, **options):
50
85
failed_msgs = Message .objects .filter (status = "R" , direction = "OUT" )
51
86
52
87
for failed_msg in failed_msgs :
53
-
54
- # Increase the retry count
55
- if not failed_msg .retries :
56
- failed_msg .retries = 1
57
- else :
58
- failed_msg .retries += 1
59
-
60
- # if max retries has exceeded then mark message status as error
61
- if failed_msg .retries > settings .MAX_RETRIES :
62
- failed_msg .status = "E"
63
- failed_msg .save ()
64
- continue
65
-
66
- self .stdout .write (
67
- "Retry send the message with ID %s" % failed_msg .message_id
68
- )
69
-
70
- # Build and resend the AS2 message
71
- as2message = AS2Message (
72
- sender = failed_msg .organization .as2org ,
73
- receiver = failed_msg .partner .as2partner ,
74
- )
75
- as2message .build (
76
- failed_msg .payload .read (),
77
- filename = os .path .basename (failed_msg .payload .name ),
78
- subject = failed_msg .partner .subject ,
79
- content_type = failed_msg .partner .content_type ,
80
- )
81
- failed_msg .send_message (as2message .headers , as2message .content )
88
+ self .retry (failed_msg )
82
89
83
90
self .stdout .write ("Processed all failed outbound messages" )
84
91
@@ -135,13 +142,9 @@ def handle(self, *args, **options):
135
142
status = "P" , direction = "OUT" , timestamp__lt = time_threshold
136
143
)
137
144
138
- # Mark these messages as erred
145
+ # Retry sending the message if not MDN received.
139
146
for pending_msg in out_pending_msgs :
140
- pending_msg .status = "E"
141
- pending_msg .detailed_status = (
142
- "Failed to receive asynchronous MDN within the " "threshold limit."
143
- )
144
- pending_msg .save ()
147
+ self .retry (pending_msg )
145
148
146
149
self .stdout .write (u"Successfully processed all pending mdns." )
147
150
0 commit comments