File

src/app/shared/services/task-wrapper.service.ts

Index

Methods

Constructor

constructor(notificationService: NotificationService, summaryService: SummaryService, taskMessageService: TaskMessageService, taskManagerService: TaskManagerService)
Parameters :
Name Type Optional
notificationService NotificationService No
summaryService SummaryService No
taskMessageService TaskMessageService No
taskManagerService TaskManagerService No

Methods

_handleExecutingTasks
_handleExecutingTasks(task: FinishedTask)
Parameters :
Name Type Optional
task FinishedTask No
Returns : void
wrapTaskAroundCall
wrapTaskAroundCall(undefined: literal type)
Parameters :
Name Type Optional
literal type No
Returns : any
import { Injectable } from '@angular/core';

import { Observable, Subscriber } from 'rxjs';

import { NotificationType } from '../enum/notification-type.enum';
import { ExecutingTask } from '../models/executing-task';
import { FinishedTask } from '../models/finished-task';
import { NotificationService } from './notification.service';
import { ServicesModule } from './services.module';
import { SummaryService } from './summary.service';
import { TaskManagerService } from './task-manager.service';
import { TaskMessageService } from './task-message.service';

@Injectable({
  providedIn: ServicesModule
})
export class TaskWrapperService {
  constructor(
    private notificationService: NotificationService,
    private summaryService: SummaryService,
    private taskMessageService: TaskMessageService,
    private taskManagerService: TaskManagerService
  ) {}

  wrapTaskAroundCall({ task, call }: { task: FinishedTask; call: Observable<any> }) {
    return new Observable((observer: Subscriber<any>) => {
      call.subscribe(
        (resp) => {
          if (resp.status === 202) {
            this._handleExecutingTasks(task);
          } else {
            this.summaryService.refresh();
            task.success = true;
            this.notificationService.notifyTask(task);
          }
        },
        (resp) => {
          task.success = false;
          task.exception = resp.error;
          observer.error(resp);
        },
        () => {
          observer.complete();
        }
      );
    });
  }

  _handleExecutingTasks(task: FinishedTask) {
    this.notificationService.show(
      NotificationType.info,
      this.taskMessageService.getRunningTitle(task)
    );

    const executingTask = new ExecutingTask(task.name, task.metadata);
    this.summaryService.addRunningTask(executingTask);

    this.taskManagerService.subscribe(
      executingTask.name,
      executingTask.metadata,
      (asyncTask: FinishedTask) => {
        this.notificationService.notifyTask(asyncTask);
      }
    );
  }
}

result-matching ""

    No results matching ""