mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Use pre_execute signal to specify started vs queued
This commit is contained in:
parent
a90dd2ad1e
commit
bd995089a8
@ -39,7 +39,7 @@
|
||||
</th>
|
||||
<th scope="col" i18n>Name</th>
|
||||
<th scope="col" class="d-none d-lg-table-cell" i18n>Created</th>
|
||||
<th scope="col" class="d-none d-lg-table-cell" *ngIf="activeTab != 'incomplete'" i18n>Results</th>
|
||||
<th scope="col" class="d-none d-lg-table-cell" *ngIf="activeTab != 'started' && activeTab != 'queued'" i18n>Results</th>
|
||||
<th scope="col" class="d-table-cell d-lg-none" i18n>Info</th>
|
||||
<th scope="col" i18n>Actions</th>
|
||||
</tr>
|
||||
@ -104,10 +104,16 @@
|
||||
<ng-container [ngTemplateOutlet]="tasksTemplate" [ngTemplateOutletContext]="{tasks:tasksService.completedFileTasks}"></ng-container>
|
||||
</ng-template>
|
||||
</li>
|
||||
<li ngbNavItem="incomplete">
|
||||
<a ngbNavLink i18n>Incomplete <span *ngIf="tasksService.incompleteFileTasks.length > 0" class="badge bg-secondary ms-1">{{tasksService.incompleteFileTasks.length}}</span></a>
|
||||
<li ngbNavItem="started">
|
||||
<a ngbNavLink i18n>Started <span *ngIf="tasksService.startedFileTasks.length > 0" class="badge bg-secondary ms-1">{{tasksService.startedFileTasks.length}}</span></a>
|
||||
<ng-template ngbNavContent>
|
||||
<ng-container [ngTemplateOutlet]="tasksTemplate" [ngTemplateOutletContext]="{tasks:tasksService.incompleteFileTasks}"></ng-container>
|
||||
<ng-container [ngTemplateOutlet]="tasksTemplate" [ngTemplateOutletContext]="{tasks:tasksService.startedFileTasks}"></ng-container>
|
||||
</ng-template>
|
||||
</li>
|
||||
<li ngbNavItem="queued">
|
||||
<a ngbNavLink i18n>Queued <span *ngIf="tasksService.queuedFileTasks.length > 0" class="badge bg-secondary ms-1">{{tasksService.queuedFileTasks.length}}</span></a>
|
||||
<ng-template ngbNavContent>
|
||||
<ng-container [ngTemplateOutlet]="tasksTemplate" [ngTemplateOutletContext]="{tasks:tasksService.queuedFileTasks}"></ng-container>
|
||||
</ng-template>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -77,8 +77,11 @@ export class TasksComponent implements OnInit, OnDestroy {
|
||||
get currentTasks(): PaperlessTask[] {
|
||||
let tasks: PaperlessTask[]
|
||||
switch (this.activeTab) {
|
||||
case 'incomplete':
|
||||
tasks = this.tasksService.incompleteFileTasks
|
||||
case 'queued':
|
||||
tasks = this.tasksService.queuedFileTasks
|
||||
break
|
||||
case 'started':
|
||||
tasks = this.tasksService.startedFileTasks
|
||||
break
|
||||
case 'completed':
|
||||
tasks = this.tasksService.completedFileTasks
|
||||
|
@ -6,7 +6,8 @@ export enum PaperlessTaskType {
|
||||
}
|
||||
|
||||
export enum PaperlessTaskStatus {
|
||||
Incomplete = 'incomplete',
|
||||
Queued = 'queued',
|
||||
Started = 'started',
|
||||
Complete = 'complete',
|
||||
Failed = 'failed',
|
||||
Unknown = 'unknown',
|
||||
@ -25,5 +26,7 @@ export interface PaperlessTask extends ObjectWithId {
|
||||
|
||||
created: Date
|
||||
|
||||
started?: Date
|
||||
|
||||
result: string
|
||||
}
|
||||
|
@ -26,10 +26,12 @@ export class TasksService {
|
||||
return this.fileTasks.slice(0)
|
||||
}
|
||||
|
||||
public get incompleteFileTasks(): PaperlessTask[] {
|
||||
return this.fileTasks.filter(
|
||||
(t) => t.status == PaperlessTaskStatus.Incomplete
|
||||
)
|
||||
public get queuedFileTasks(): PaperlessTask[] {
|
||||
return this.fileTasks.filter((t) => t.status == PaperlessTaskStatus.Queued)
|
||||
}
|
||||
|
||||
public get startedFileTasks(): PaperlessTask[] {
|
||||
return this.fileTasks.filter((t) => t.status == PaperlessTaskStatus.Started)
|
||||
}
|
||||
|
||||
public get completedFileTasks(): PaperlessTask[] {
|
||||
|
@ -15,6 +15,7 @@ def init_paperless_tasks(apps, schema_editor):
|
||||
task_id=task.id,
|
||||
name=task.name,
|
||||
created=task.started,
|
||||
started=task.started,
|
||||
acknowledged=True,
|
||||
)
|
||||
task.paperlesstask = paperlesstask
|
||||
@ -45,9 +46,11 @@ class Migration(migrations.Migration):
|
||||
("name", models.CharField(max_length=256)),
|
||||
(
|
||||
"created",
|
||||
models.DateTimeField(
|
||||
auto_now=True, db_index=True, verbose_name="created"
|
||||
),
|
||||
models.DateTimeField(auto_now=True, verbose_name="created"),
|
||||
),
|
||||
(
|
||||
"started",
|
||||
models.DateTimeField(verbose_name="started"),
|
||||
),
|
||||
("acknowledged", models.BooleanField(default=False)),
|
||||
(
|
||||
|
@ -507,7 +507,8 @@ class PaperlessTask(models.Model):
|
||||
|
||||
task_id = models.CharField(max_length=128)
|
||||
name = models.CharField(max_length=256)
|
||||
created = models.DateTimeField(_("created"), auto_now=True, db_index=True)
|
||||
created = models.DateTimeField(_("created"), auto_now=True)
|
||||
started = models.DateTimeField(_("started"))
|
||||
attempted_task = models.OneToOneField(
|
||||
Task,
|
||||
on_delete=models.CASCADE,
|
||||
|
@ -622,7 +622,10 @@ class TasksViewSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_status(self, obj):
|
||||
if obj.attempted_task is None:
|
||||
return "incomplete"
|
||||
if obj.started:
|
||||
return "started"
|
||||
else:
|
||||
return "queued"
|
||||
elif obj.attempted_task.success:
|
||||
return "complete"
|
||||
elif not obj.attempted_task.success:
|
||||
|
@ -514,12 +514,24 @@ def init_paperless_task(sender, task, **kwargs):
|
||||
paperless_task.save()
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=django_q.tasks.Task)
|
||||
def update_paperless_task(sender, instance, **kwargs):
|
||||
@receiver(django_q.signals.pre_execute)
|
||||
def paperless_task_started(sender, task, **kwargs):
|
||||
print(task)
|
||||
try:
|
||||
if instance.func == "documents.tasks.consume_file":
|
||||
paperless_task = PaperlessTask.objects.get(task_id=instance.id)
|
||||
paperless_task.attempted_task = instance
|
||||
if task["func"] == "documents.tasks.consume_file":
|
||||
paperless_task = PaperlessTask.objects.get(task_id=task["id"])
|
||||
paperless_task.started = timezone.now()
|
||||
paperless_task.save()
|
||||
except PaperlessTask.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=django_q.tasks.Task)
|
||||
def update_paperless_task(sender, task, **kwargs):
|
||||
try:
|
||||
if task.func == "documents.tasks.consume_file":
|
||||
paperless_task = PaperlessTask.objects.get(task_id=task.id)
|
||||
paperless_task.attempted_task = task
|
||||
paperless_task.save()
|
||||
except PaperlessTask.DoesNotExist:
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user