Project

Profile

Help

Issue #3252

Updated by amacdona@redhat.com about 6 years ago

In #3074, we show that importer.sync and publisher.publish (on the models) cause circular import problems. Here I propose that these functions should become tasks provided by the plugin. This make sense because: 
 # The plugin API needs to expose the tasking system for complex copy 
 # sync and publish are purely plugin activities, and are entirely run in a task 

 I'll present this following the path of a request using PulpFile as an example. 

 Currently, pulpcore defines an Importer and Publisher master ViewSet, which is the parent of the plugin's detail viewset, FileImporter and FilePublisher. The pulpcore ImporterViewSet and PublisherViewSet define sync and publish endpoints, which deploy a generic sync task, calls sync on the model. Instead, the detail ViewSets should deploy their own sync tasks. 

 <pre><code class="python"> # TODO fill out with real code 
 class FileImporterViewSet(): 
     @detail_route("sync") 
     def sync(self): 
         async_result = pulp_file.tasks.sync.apply_async_with_reservation(...) 
         return OperationPostponed(async_result) 
 </code></pre> 


 

 This will give the plugin writers the ability to add extra POST body arguments and perform synchronous validation. The task that is deployed is also written by the plugin writer, so they have absolute control over the entire life of the request. This is what is already expected for features like rich copy. 

 The sync logic on the plugins would be moved to a task, but would stay relatively the same. 
 <pre><code class="python"> 

 @working_directory_task  
 def sync(importer_pk): 
     importer = models.FileImporter.objects.get(importer_pk) # Note, no cast() necessary the plugin knows which type 
     synchronizer = Synchronizer(old_version, new_version).run() 

 </code></pre> 

 Currently, the generic sync task also sets the working directory. This could be done by a new pulpcore decorator @working_directory_task, which would be part of the plugin API. 

 Similarly, the FilePublisherViewSet would deploy pulp_file.tasks.publish, 

 POST /v3/importers/file/123456789/sync/ repository=repository_href 
 POST /v3/publishers/file/123456789/publish/ repository_version=repository_version

Back