Refactor upgrade websocket progress, so "anyone" can join in to see

now while an upgrade is executing, anyone with permission can "view"
the upgrade and see the same progress the executor is seeing
This commit is contained in:
Lance Edgar 2022-08-20 18:55:33 -05:00
parent 18cec49a86
commit e93063a344
3 changed files with 204 additions and 127 deletions

View file

@ -1063,6 +1063,8 @@ class MasterView(View):
'instance_deletable': self.deletable_instance(instance),
'form': form,
}
if self.executable:
context['instance_executable'] = self.executable_instance(instance)
if hasattr(form, 'make_deform_form'):
context['dform'] = form.make_deform_form()
@ -1784,6 +1786,14 @@ class MasterView(View):
elif importer.allow_create:
return importer.create_object(key, host_data)
def executable_instance(self, instance):
"""
Returns boolean indicating whether or not the given instance
can be considered "executable". Returns ``True`` by default;
override as necessary.
"""
return True
def execute(self):
"""
Execute an object.

View file

@ -475,6 +475,13 @@ class UpgradeView(MasterView):
# key = '{}.execute'.format(self.get_grid_key())
# return SessionProgress(self.request, key, session_type='file')
def executable_instance(self, upgrade):
if upgrade.executed:
return False
if upgrade.status_code != self.enum.UPGRADE_STATUS_PENDING:
return False
return True
def execute_instance(self, upgrade, user, progress=None, **kwargs):
app = self.get_rattail_app()
session = app.get_session(upgrade)