import { once } from 'lodash' ; import api from '../services/nus-api' ; import logger , { Logger } from '../services/logger' ; import { getCacheFactory , CombinedPersist , getFileSystemWriter } from '../services/io' ; import { Cache , Persist } from '../types/persist' ; import config from '../config' ; const useElasticSearch = process . env . NODE_ENV === 'production' ? true : ! ! config . elasticConfig ; const elasticConfigWarning = once ( ( ) => { logger . warn ( 'Data is not persisted to ElasticSearch because it is not configured' ) ; } ) ; /**
 * Base task class. Dependencies and components are instance properties
 * which can be overridden in tests with mocks.
 */ export default abstract class BaseTask { protected academicYear : string ; io : Persist ; protected getCache : < T > ( key : string , expiry ? : number ) => Cache < T > ; constructor ( academicYear ) { this . academicYear = academicYear ; if ( useElasticSearch ) { this . io = new CombinedPersist ( academicYear ) ; } else { elasticConfigWarning ( ) ; this . io = getFileSystemWriter ( academicYear ) ; } this . getCache = getCacheFactory ( academicYear ) ; } api = api ; protected rootLogger = logger ; logger : Logger = logger ; }