Specialized components
Background processing
Task server application
19 min
overview the task server application is the central coordinator of the ir engine's background processing system it serves as the foundation for managing and executing various automated tasks that run behind the scenes these tasks include collecting analytics data, monitoring system events, performing scheduled maintenance, and other operations that don't require direct user interaction by centralizing the initialization and management of background tasks, the task server ensures reliable execution of critical background operations purpose and functionality background tasks are essential for many aspects of a production application collecting and analyzing usage data monitoring system health and performance performing scheduled maintenance operations processing queued operations asynchronously generating reports and notifications the task server application provides the infrastructure to handle these operations by initialization setting up necessary connections to databases, message queues, and other services configuration loading and managing application settings task management launching and coordinating background tasks resource provision providing tasks with access to shared resources and services monitoring ensuring tasks are running properly and handling errors implementation entry point src/index ts the application starts with the index ts file, which serves as the entry point // src/index ts // import the configuration loader import { updateappconfig } from '@ir engine/server core/src/updateappconfig'; // main initialization function const init = async () => { // load application configurations await updateappconfig(); // dynamically import the start function const { start } = await import(' /start'); // start the task server start(); }; // execute the initialization init(); this file imports the configuration management function defines an asynchronous initialization function loads application configurations imports and calls the main start function executes the initialization process main application src/start ts the start ts file contains the core logic for setting up and starting the task server // src/start ts import { application } from '@ir engine/server core/declarations'; import { servermode } from '@ir engine/server core/src/serverstate'; import { createfeatherskoaapp } from '@ir engine/server core/src/createapp'; import multilogger from '@ir engine/server core/src/serverlogger'; // import task modules import collectanalytics from ' /collect analytics'; import collectevents from ' /collect events'; const logger = multilogger child({ component 'taskserver' }); // main function to start the task server export const start = async () promise\<application> => { // create the application instance with task server mode const app = await createfeatherskoaapp(servermode task); // initialize and start background tasks collectanalytics(app); collectevents(app); logger info('task server running '); // start a small http server for health checks const port = 5050; await app listen(port); logger info('task server listening on port ' + port); return app; }; this function creates the application instance using createfeatherskoaapp with servermode task initializes the analytics collection task initializes the event collection task starts a small http server for health checks and monitoring returns the configured application instance key components the task server relies on several important components createfeatherskoaapp this function from the server core package creates the application instance // simplified concept const app = await createfeatherskoaapp(servermode task); this function creates a feathersjs application (a framework for real time applications) configures it with koa (a web framework) sets up connections to databases, redis, and other services initializes authentication and authorization configures logging and error handling returns the fully configured application instance task modules the task server initializes specific task modules // initialize analytics collection collectanalytics(app); // initialize event collection collectevents(app); each task module is a function that takes the application instance as a parameter sets up its specific functionality may configure periodic execution handles its own error cases uses the application's services and connections initialization flow the complete initialization sequence follows these steps sequencediagram participant user as system startup participant indexts as src/index ts (init) participant appconfig as configuration loader participant startts as src/start ts (start) participant coreapp as featherskoaapp participant analyticstask as analytics collector participant eventstask as event collector user >>indexts start application indexts >>appconfig updateappconfig() appconfig >>indexts configurations loaded indexts >>startts import and call start() startts >>coreapp createfeatherskoaapp(servermode task) note over coreapp set up connections (db, redis, etc ) coreapp >>startts application instance created startts >>analyticstask collectanalytics(app) startts >>eventstask collectevents(app) startts >>coreapp app listen(port) coreapp >>startts server listening startts >>indexts task server running this diagram illustrates the system starts the application configuration is loaded the main start function is called the application instance is created with necessary connections task modules are initialized a small http server is started for monitoring the task server is now running and executing background tasks integration with other components the task server integrates with several other components of the background processing system application configuration management the task server uses the configuration management system to load settings await updateappconfig(); this loads configuration from various sources (environment variables, configuration files, etc ) and makes them available to the application more details are covered in application configuration management docid\ gda6wkedhqbb57jc6 9yc analytics data collector the task server initializes the analytics collection task collectanalytics(app); this task periodically collects and processes analytics data about system usage more details are covered in analytics data collector docid 83etf0hxkaf m fi8cha9 kubernetes event collector the task server initializes the event collection task collectevents(app); this task monitors and processes events from the kubernetes cluster more details are covered in kubernetes event collector docid\ gfdlk sf1elkjnrh5i8ab service interaction layer the task server provides tasks with access to services through the application instance // example of how a task might use services const analyticsservice = app service('analytics'); const results = await analyticsservice find({ query { processed false } }); this allows tasks to interact with databases, message queues, and other services more details are covered in service interaction layer docid\ v5bybxvnqt1wgdfxrkjiu deployment considerations the task server is designed to be deployed in a kubernetes environment it's packaged as a docker container it can be deployed as a kubernetes deployment it's typically configured with a single replica (as tasks should only run once) it requires access to shared resources like databases and redis it can be monitored through its http endpoint a simplified kubernetes deployment might look like apiversion apps/v1 kind deployment metadata name ir engine taskserver spec replicas 1 selector matchlabels app ir engine taskserver template metadata labels app ir engine taskserver spec containers \ name taskserver image ir engine/taskserver\ latest env \ name node env value production resources limits cpu "1" memory "1gi" requests cpu "0 5" memory "512mi" next steps with an understanding of the task server application's role and implementation, the next chapter explores how configuration is managed to provide the task server and its tasks with the settings they need to operate next application configuration management docid\ gda6wkedhqbb57jc6 9yc