@flatfile/plugin-job-handler

中文文档
0.8.1发布于 2024/12/20ISCTypeScriptESM + CJS近 30 天下载 37.1万

A plugin for handling Flatfile Jobs.

原始使用文档

The @flatfile/plugin-job-handler package is a plugin designed to streamline handling Flatfile Jobs, which are a large unit of work performed asynchronously on a resource such as a file, Workbook, or Sheet.

Event Type: listener.on('job:ready')

Parameters

job - string - (required)

The job parameter is applied as a filter when listening for job:ready.

handler - function - (required)

The handler parameter is a callback where you execute your code. It accepts two arguments: event and tick.

  • event: Represents the FlatfileEvent, giving context to the handler.
  • tick: A function that can be used to update Job progress. It accepts two parameters:
    • progress: A number between 0 and 100 indicating the progress percentage.
    • message: An optional descriptive string.

Invoking the tick function returns a promise that resolves to a JobResponse object. However, using the tick function is optional.

opts.debug - boolean - default: false

The debug parameter is used to enable debug logging for the plugin.

Usage

The jobHandler plugin manages Flatfile Jobs. It listens for the job:ready event and screens it based on the job parameter.

When a job:ready event occurs:

  • The handler callback is triggered with the FlatfileEvent and an optional tick function.
  • This tick function, if used, updates the Job's progress.
  • The handler may yield a promise that culminates in a JobResponse object, allowing for a customized successful Job status.

Install

npm i @flatfile/plugin-job-handler

Import

import { jobHandler } from "@flatfile/plugin-job-handler";

Replace "domain:operation" with the domain and operation you want to listen for.

listener.js

listener.use(
  jobHandler("domain:operation", async (event, tick) => {
    try {
      // your code here...
      await tick(50, "Halfway there!"); // update Job progress
      // ...continue your code...
      await tick(75, "Three quarters there!"); // update Job progress
      // ...continue your code...
      return {
        outcome: {
          message: "Job complete",
        },
      };
    } catch (error) {
      throw error; // will fail the Job
    }
  })
);

版本与发布记录

@flatfile/plugin-job-handler 共发布 29 个版本,首次发布于 2023/08/31;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.8.1latest2024/12/201.9 年前
0.8.02024/11/082 年前
0.7.02024/10/302 年前
0.6.12024/10/032 年前
0.6.02024/09/242 年前
0.5.52024/09/042 年前

关于 @flatfile/plugin-job-handler 的常见问题

@flatfile/plugin-job-handler 是什么?

A plugin for handling Flatfile Jobs.

如何安装 @flatfile/plugin-job-handler?

在项目目录运行 npm install @flatfile/plugin-job-handler,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@flatfile/api(^1.9.19)、@flatfile/listener(^1.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flatfile/plugin-job-handler 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flatfile/plugin-job-handler 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flatfile/plugin-job-handler 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flatfile/plugin-job-handler 可以商用吗?

@flatfile/plugin-job-handler 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flatfile/plugin-job-handler 的下载量有多少?

根据 npm 官方下载统计,@flatfile/plugin-job-handler 在 2026/10/15 – 2026/11/13 这 30 天内被下载 371,355 次,日均约 12,379 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flatfile/plugin-job-handler 还在维护吗?

最新版本 0.8.1 发布于 2024/12/20(1.9 年前);至今共发布 29 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。