CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-workerpool

Offload tasks to a pool of workers on node.js and in the browser

Overall
score

95%

Overview
Eval results
Files

task.mdevals/scenario-2/

Image Processing Pool Manager

Build a configurable pool manager for processing image data in parallel. The system should create worker pools with specific configurations and retrieve information about pool state.

Requirements

Create a module that provides functionality for managing worker pools with different configurations:

  1. Create a worker pool with specific configuration options:

    • Set minimum number of workers that should always be available
    • Set maximum number of workers allowed in the pool
    • Limit the maximum number of tasks that can be queued
    • Specify the worker type (auto, web, process, or thread)
  2. Retrieve pool statistics including:

    • Total workers in the pool
    • Number of busy workers
    • Number of idle workers
    • Pending tasks in queue
    • Currently executing tasks
  3. Properly terminate the pool when processing is complete

Implementation

@generates

API

/**
 * Creates and configures a worker pool
 *
 * @param {Object} config - Pool configuration
 * @param {number} config.minWorkers - Minimum number of workers
 * @param {number} config.maxWorkers - Maximum number of workers
 * @param {number} config.maxQueueSize - Maximum queued tasks
 * @param {string} config.workerType - Worker type ('auto', 'web', 'process', 'thread')
 * @returns {Object} The configured worker pool
 */
function createPool(config) {
  // IMPLEMENTATION HERE
}

/**
 * Gets current statistics from the pool
 *
 * @param {Object} pool - The worker pool
 * @returns {Object} Statistics including totalWorkers, busyWorkers, idleWorkers, pendingTasks, activeTasks
 */
function getPoolStats(pool) {
  // IMPLEMENTATION HERE
}

/**
 * Terminates the worker pool
 *
 * @param {Object} pool - The worker pool to terminate
 * @param {boolean} force - Whether to force immediate termination
 * @returns {Promise} Resolves when pool is terminated
 */
function terminatePool(pool, force = false) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createPool,
  getPoolStats,
  terminatePool
};

Test Cases

  • Creating a pool with minWorkers=2, maxWorkers=4 configures correctly and stats show at least 2 workers initially @test
  • Creating a pool with maxQueueSize=10 limits the queue size @test
  • Getting pool stats returns an object with totalWorkers, busyWorkers, idleWorkers, pendingTasks, and activeTasks properties @test
  • Terminating a pool successfully shuts down all workers @test

Dependencies { .dependencies }

workerpool { .dependency }

Provides worker pool functionality for parallel task processing.

Install with Tessl CLI

npx tessl i tessl/npm-workerpool

tile.json