Project

Profile

Help

Story #3442

Updated by bmbouter about 6 years ago

* This would be a single action 
 * I cannot specify the units specifically (all types). 
 * I can follow the progress of all cleanups. (Cleanups are asynchronous.) 
 * Call would be to DELETE /api/v3/orphans/. 

 h3. Technical Design 

 Create a function that when called will: 

 <pre><code class="python"> 
 @shared_task(base=UserFacingTask) 
 def orphan_cleanup(): 
     # This should contain all of the orphan code 
 </code></pre> 

 Then make a celery task that will never actually run, but will be intercepted by "<code>queue_reserve_task()</code>":https://github.com/pulp/pulp/blob/3.0-dev/pulpcore/pulpcore/tasking/tasks.py#L100. Something like: 

 <pre><code class="python"> 
     if task.name == "orphan_cleanup": 
         # loop forever while waiting for 0 reservations 
         while True: 
             if zero_reservations is True: 
                 try: 
                     orphan_cleanup() # this automatically handles transitioning the task to RUNNING 
                 except: 
                     orphan_cleanup.on_failure(...)    # we need to pass it the right args. This marks the task as failed. 
                 else: 
                     orphan_cleanup.on_success(...)    # we need to pass it the right args. This marks the task as successful. 
                 return 
 </code></pre> 

 h3. Cancellation 

 To ensure that task cancellation work as expected we should have the _queue_release_resource receive the task ID typically specified by the <code>inner_task_id</code>. This should be safe because _queue_release_resource has no side effects on the Task data because it does not inherit from UserFacingTask 

 To accomplish ^ we need to have a conditional path like: 
 <pre><code class="python"> 
 if task.name == "orphan_cleanup": 
         _queue_reserved_task.apply_async(task_id=inner_task_id, args=(task_name, inner_task_id, list(resources), args, 
                                                kwargs, options), 
                                          queue=RESOURCE_MANAGER_QUEUE) 
 else: 
         _queue_reserved_task.apply_async(args=(task_name, inner_task_id, list(resources), args, 
                                                kwargs, options), 
                                          queue=RESOURCE_MANAGER_QUEUE) 
 </code></pre> 

Back