manager: add accessor to report state (#34235)

This commit is contained in:
Benjamin Dauvergne 2019-06-22 22:27:10 +02:00
parent b50cd0c63f
commit e1838eb731
4 changed files with 26 additions and 12 deletions

View File

@ -56,8 +56,14 @@
<tbody>
{% for report in reports %}
<tr data-uuid="{{ report.uuid }}">
<td class="created">{% if report.state != report.STATE_RUNNING %}<a href="{% url "a2-manager-users-import-report" import_uuid=user_import.uuid report_uuid=report.uuid %}">{{ report.created }}</a>{% else %}{{ report.created }}{% endif %}</td>
<td class="state"><span>{{ report.state_display }}</span> {% if report.state == report.STATE_ERROR %}"{{ report.exception }}"{% endif %} {% if not report.is_running %}!failed before finishing!{% endif %}</td>
<td class="created">
{% if report.state != report.STATE_RUNNING %}
<a href="{% url "a2-manager-users-import-report" import_uuid=user_import.uuid report_uuid=report.uuid %}">{{ report.created }}</a>
{% else %}
{{ report.created }}
{% endif %}
</td>
<td class="state">{{ report.state_display }}</td>
<td class="applied">{% if not report.simulate %}<span class="icon-check"></span>{% endif %}</td>
<td class="delete-action">{% if report.simulate %}<form method="post" id="delete-form-{{ report.uuid }}">{% csrf_token %}<button name="delete" value="{{ report.uuid }}">{% trans "Delete" %}</button></form>{% endif %}</td>
</tr>

View File

@ -61,7 +61,7 @@
{% endblock %}
{% block main %}
<h2>{{ report_title }} - {{ report.created }} - {{ report.state }}</h2>
<h2>{{ report_title }} - {{ report.created }} - {{ report.state_display }}</h2>
{% if report.exception %}
<p>{% trans "Exception:" %} {{ report.exception}}</p>
{% endif %}

View File

@ -152,6 +152,22 @@ class Report(object):
data = pickle.load(fd)
return data
@property
def state(self):
state = self.data['state']
if state == self.STATE_RUNNING and not self.is_running:
state = self.STATE_ERROR
return state
@property
def is_running(self):
try:
pid = self.pid
tid = self.tid
return os.path.exists('/proc/%s/task/%s/' % (pid, tid))
except AttributeError:
return False
@property
def state_display(self):
state = self.data['state']
@ -224,14 +240,6 @@ class Report(object):
t.start()
return t
def is_running(self):
try:
pid = self.pid
tid = self.tid
return os.path.exists('/proc/%s/task/%s/' % (pid, tid))
except AttributeError:
return False
def __getattr__(self, name):
try:
return self.data[name]

View File

@ -271,7 +271,7 @@ x,x,x,x'''.encode(encoding),
def wait_finished():
new_resp = response.click('Users Import')
if new_resp.pyquery('tr[data-uuid="%s"] td.state span' % uuid).text() == 'Finished':
if new_resp.pyquery('tr[data-uuid="%s"] td.state' % uuid).text() == 'Finished':
return new_resp
simulate = reports[0]