import { Injectable } from '@nestjs/common' ; import { concatMap , map , Observable } from 'rxjs' ; import { drive_v3 } from 'googleapis' ; import { CronProcessTable } from '../tables/cron-process.table' ; import { getCronProcessCompleted , getCronProcessRunning , } from '../cron-processes/cron-process-state.functions' ; import { CronProcessStateUpdateProvider } from './cron-process-state-update.provider' ; import { EntityDeleteProvider } from './entity-delete.provider' ; import { EntityPublishProvider } from './entity-publish.provider' ; import { ImageUpdateNewProvider } from './image-update-new.provider' ; @ Injectable ( ) export class CronProcessRunProvider { private runningCronProcess = false ; constructor ( private readonly cronProcessStateUpdateProvider , private readonly entityDeleteProvider , private readonly entityPublishProvider , private readonly imageUpdateNewProvider ) { } get isRunningCronProcess ( ) : boolean { return this . runningCronProcess ; } set isRunningCronProcess ( runningCronProcess ) { this . runningCronProcess = runningCronProcess ; } deleteEntity$ ( cronProcessTable ) { return this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessRunning ( ) ) . pipe ( concatMap ( ( ) => this . entityDeleteProvider . deleteEntity$ ( cronProcessTable . entityId ) ) , concatMap ( ( ) => this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessCompleted ( ) ) ) , map ( ( ) => { this . isRunningCronProcess = false ; return undefined ; } ) ) ; } publishEntity$ ( cronProcessTable ) { return this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessRunning ( ) ) . pipe ( concatMap ( ( ) => this . entityPublishProvider . publishEntity$ ( cronProcessTable . entityId , cronProcessTable . postSocialMedia ) ) , concatMap ( ( ) => this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessCompleted ( ) ) ) , map ( ( ) => { this . isRunningCronProcess = false ; return undefined ; } ) ) ; } updateNewImages$ ( googleDrive , cronProcessTable ) { return this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessRunning ( ) ) . pipe ( concatMap ( ( ) => this . imageUpdateNewProvider . updateNewImages$ ( googleDrive , cronProcessTable . entityId ) ) , concatMap ( ( ) => this . cronProcessStateUpdateProvider . updateCronProcess$ ( cronProcessTable , getCronProcessCompleted ( ) ) ) , map ( ( ) => { this . isRunningCronProcess = false ; return undefined ; } ) ) ; } }