This repository was archived by the owner on Aug 9, 2024. It is now read-only.
File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 37
37
38
38
from fedimg .config import PROCESS_COUNT , STATUS_FILTER
39
39
from fedimg .utils import get_rawxz_urls , get_value_from_dict
40
+ from fedimg .utils import cancel_stale_conversion_tasks
40
41
41
42
_log = logging .getLogger (__name__ )
42
43
@@ -80,6 +81,8 @@ def consume(self, msg):
80
81
_log .debug ('%s is not valid status' % msg_info ['status' ])
81
82
return
82
83
84
+ cancel_stale_conversion_tasks ()
85
+
83
86
location = msg_info ['location' ]
84
87
compose_id = msg_info ['compose_id' ]
85
88
try :
Original file line number Diff line number Diff line change 26
26
import logging
27
27
_log = logging .getLogger (__name__ )
28
28
29
+ import datetime
29
30
import functools
30
31
import os
31
32
import re
@@ -199,3 +200,39 @@ def get_image_name_from_ami_name_for_fedmsg(image_name):
199
200
image_name = name_vt_region .rsplit ('-' , 4 )[:- 4 ][0 ]
200
201
201
202
return image_name
203
+
204
+
205
+ def cancel_stale_conversion_tasks ():
206
+ _log .info ("Preparing to cancel conversion tasks" )
207
+ output , error , retcode = external_run_command ([
208
+ 'euca-describe-conversion-tasks --region us-east-1 | grep active' ,
209
+ ])
210
+
211
+ if retcode != 0 :
212
+ return False
213
+
214
+ tasks = output .split ('\n ' )[1 :- 1 ]
215
+
216
+ for task in tasks :
217
+ expiration_datetime = datetime .datetime .strptime (
218
+ task .split ()[5 ],
219
+ '%Y-%m-%dT%H:%M:%Sz'
220
+ )
221
+ import_vol_task_id = task .split ()[3 ]
222
+
223
+ start_datetime = expiration_datetime - datetime .timedelta (days = 7 )
224
+ now_datetime = datetime .datetime .now ()
225
+
226
+ delta_time = now_datetime - start_datetime
227
+
228
+ if delta_time .total_seconds () >= 86400 :
229
+ _log .info ('This is a stale task. Canceling %r' % import_vol_task_id )
230
+ output , error , retcode = external_run_command ([
231
+ 'euca-cancel-conversion-task --region us-east-1' ,
232
+ import_vol_task_id
233
+ ])
234
+
235
+ if retcode != 0 :
236
+ _log .info ('Could not cancel the task %r' % import_vol_task_id )
237
+
238
+ return True
You can’t perform that action at this time.
0 commit comments