Skip to content

BaseTask

This file defines the BaseTask class, which serves as the base class for all tasks in the @sodacore/core library. It provides a logger and empty lifecycle methods (init, run) intended to be overridden by subclasses.


Features

  • Logging: Provides a protected logger property for use in derived tasks.
  • Lifecycle Hooks: Defines init and run methods for task lifecycle management, intended to be overridden by subclasses.

Usage

typescript
import BaseTask from './base/task';

class MyTask extends BaseTask {
	async init() {
		this.logger.info('Initializing MyTask');
		// Custom initialization logic
	}

	async run() {
		this.logger.info('Running MyTask');
		// Custom task logic
	}
}

API

Properties

  • logger: An injected instance of the Logger class, available to subclasses.

Methods

async init(): Promise<void>

Lifecycle hook for initialization. Intended to be overridden by subclasses.

async run(): Promise<void>

Lifecycle hook for running the task. Intended to be overridden by subclasses. Called each time the task is executed based on its schedule.


Notes

  • Extend this class for all tasks to ensure consistent lifecycle management and logging.
  • The class uses dependency injection for the logger.

Released under the Apache-2.0 License.