Skip to content

Commit

Permalink
Adding names to tasks
Browse files Browse the repository at this point in the history
User can see and filter the class path
and function name which run inside the task.

closes: #2889
https://pulp.plan.io/issues/2889

Signed-off-by: Pavel Picka <ppicka@redhat.com>
  • Loading branch information
pavelpicka authored and daviddavis committed Jan 16, 2019
1 parent 331e587 commit 7fef6b7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
19 changes: 19 additions & 0 deletions pulpcore/app/migrations/0002_task_name.py
@@ -0,0 +1,19 @@
# Generated by Django 2.1.5 on 2019-01-14 11:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pulp_app', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='task',
name='name',
field=models.CharField(default='name', max_length=255),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions pulpcore/app/models/task.py
Expand Up @@ -255,6 +255,7 @@ class Task(Model):
Fields:
state (models.TextField): The state of the task
name (models.CharField): The name of the task
started_at (models.DateTimeField): The time the task started executing
finished_at (models.DateTimeField): The time the task finished executing
non_fatal_errors (pulpcore.app.fields.JSONField): Dictionary of non-fatal errors that
Expand All @@ -268,6 +269,7 @@ class Task(Model):
"""
job_id = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
state = models.TextField(choices=TASK_CHOICES)
name = models.CharField(max_length=255)

started_at = models.DateTimeField(null=True)
finished_at = models.DateTimeField(null=True)
Expand Down
11 changes: 7 additions & 4 deletions pulpcore/app/serializers/task.py
Expand Up @@ -40,6 +40,9 @@ class TaskSerializer(ModelSerializer):
" 'waiting', 'skipped', 'running', 'completed', 'failed' and 'canceled'."),
read_only=True
)
name = serializers.CharField(
help_text=_("The name of task.")
)
started_at = serializers.DateTimeField(
help_text=_("Timestamp of the when this task started execution."),
read_only=True
Expand Down Expand Up @@ -88,10 +91,10 @@ class TaskSerializer(ModelSerializer):

class Meta:
model = models.Task
fields = ModelSerializer.Meta.fields + ('job_id', 'state', 'started_at', 'finished_at',
'non_fatal_errors', 'error', 'worker', 'parent',
'spawned_tasks', 'progress_reports',
'created_resources')
fields = ModelSerializer.Meta.fields + ('job_id', 'state', 'name', 'started_at',
'finished_at', 'non_fatal_errors', 'error',
'worker', 'parent', 'spawned_tasks',
'progress_reports', 'created_resources')


class MinimalTaskSerializer(TaskSerializer):
Expand Down
2 changes: 2 additions & 0 deletions pulpcore/app/viewsets/task.py
Expand Up @@ -17,6 +17,7 @@
class TaskFilter(BaseFilterSet):
state = filters.CharFilter()
worker = HyperlinkRelatedFilter()
name = filters.CharFilter()
started_at = IsoDateTimeFilter(field_name='started_at')
finished_at = IsoDateTimeFilter(field_name='finished_at')
parent = HyperlinkRelatedFilter()
Expand All @@ -26,6 +27,7 @@ class Meta:
fields = {
'state': ['exact', 'in'],
'worker': ['exact', 'in'],
'name': ['contains'],
'started_at': DATETIME_FILTER_OPTIONS,
'finished_at': DATETIME_FILTER_OPTIONS,
'parent': ['exact']
Expand Down
3 changes: 2 additions & 1 deletion pulpcore/tasking/tasks.py
Expand Up @@ -185,7 +185,8 @@ def enqueue_with_reservation(func, resources, args=None, kwargs=None, options=No
if current_job:
current_task = Task.objects.get(job_id=current_job.id)
parent_kwarg['parent'] = current_task
Task.objects.create(job_id=inner_job_id, state=TASK_STATES.WAITING, **parent_kwarg)
Task.objects.create(job_id=inner_job_id, state=TASK_STATES.WAITING,
name=f'{func.__module__}.{func.__name__}', **parent_kwarg)
q = Queue('resource_manager', connection=redis_conn)
task_args = (func, inner_job_id, list(resources), args, kwargs, options)
q.enqueue(_queue_reserved_task, args=task_args, timeout=TASK_TIMEOUT)
Expand Down

0 comments on commit 7fef6b7

Please sign in to comment.