npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@micl/task

v0.1.18

Published

micl task

Readme

@micl/task

npm version npm downloads license

Micl 项目的任务管理客户端,提供任务注册、创建、状态查询和队列轮询等功能,与任务中心服务进行交互。

📦 安装

npm install @micl/task
# or
pnpm add @micl/task
# or
yarn add @micl/task

📚 模块导出

| 导出项 | 类型 | 描述 | |--------|------|------| | taskCenterClient | TaskCenterClient | 任务中心客户端单例实例 |

🎯 使用示例

基本使用

import { taskCenterClient } from '@micl/task';
import { TASK_STATUS_ENUM } from '@micl/constant';

// 设置任务中心基础 URL
taskCenterClient.setBaseUrl('http://task-center:3000');

// 注册任务
const result = await taskCenterClient.register({
  taskId: 'task-123',
  taskName: 'Sample Task',
  priority: 'high'
}, {
  headers: { 'Authorization': 'Bearer token' }
});

// 创建任务
const task = await taskCenterClient.create({
  taskId: 'task-123',
  params: { /* 任务参数 */ }
}, {
  headers: { 'Authorization': 'Bearer token' }
});

// 查询任务状态
const status = await taskCenterClient.status('task-123', {
  headers: { 'Authorization': 'Bearer token' }
});

队列轮询

import { taskCenterClient } from '@micl/task';
import { TASK_STATUS_ENUM } from '@micl/constant';

// 轮询任务状态直到完成或失败
try {
  await taskCenterClient.queueTask(
    'task-123',
    {
      interval: 1000,      // 轮询间隔(毫秒)
      maxWait: 60000,      // 最大等待时间(毫秒)
      headers: { 'Authorization': 'Bearer token' }
    },
    (status) => {
      // 状态回调
      console.log('任务状态:', status.status);
      console.log('进度:', status.progress);
      console.log('消息:', status.message);

      // 根据状态执行不同操作
      switch (status.status) {
        case TASK_STATUS_ENUM.Completed:
          console.log('任务完成!');
          break;
        case TASK_STATUS_ENUM.Failed:
          console.log('任务失败!');
          break;
        case TASK_STATUS_ENUM.Pending:
          console.log('任务等待中...');
          break;
      }
    }
  );
} catch (error) {
  console.error('轮询超时:', error.message);
}

🛠 API 参考

TaskCenterClient

方法

| 方法 | 描述 | 参数 | 返回值 | |------|------|------|--------| | register(data, options) | 注册任务 | data: any, options: TaskOptions | Promise<any> | | create(data, options) | 创建任务 | data: any, options: TaskOptions | Promise<any> | | status(taskId, options) | 查询任务状态 | taskId: string \| number, options: TaskOptions | Promise<any> | | queueTask(taskId, options, callback) | 轮询任务状态 | taskId: string \| number, options: TaskOptions, callback: Function | Promise<boolean> |

配置选项

interface TaskOptions {
  /** 轮询间隔(毫秒),默认 500 */
  interval?: number;
  /** 最大等待时间(毫秒),默认 24小时 */
  maxWait?: number;
  /** 请求头 */
  headers?: Record<string, string>;
}

📁 项目结构

task/
├── core.ts           # 核心客户端实现
├── index.ts          # 模块导出
├── package.json      # 包配置
├── rollup.config.js  # 构建配置
└── yarn.lock         # 依赖锁文件

🛠 开发

构建

# 进入 task 目录
cd task

# 构建项目
yarn build

# 或使用 npm
npm run build

代码质量

# 代码检查
yarn lint

# 代码格式化
yarn format

🤝 贡献

欢迎提交 Issue 和 Pull Request 来完善这个模块。

📄 许可证

本项目采用 ISC 许可证 - 查看 LICENSE 文件了解详情。

📞 支持

如有问题或建议,请提交 Issue 或联系维护者。


@micl/task - 任务管理客户端,简化任务流程 🚀