Giter Club home page Giter Club logo

controlled-fetch's Introduction

Controlled fetch

自用辣鸡爬虫基础设施

  • 采用 cluster / Promise 实现多进程并行并发

支持执行参数附加文件

  node index.js  \
  --callbackPath 'PATH_OF_YOUR_FILE' \ 
  --taskPath 'PATH_OF_YOUR_FILE' \
  --reducerPath 'PATH_OF_YOUR_FILE'

文件说明(所有文件均为导出对象)

  • 文件单次执行:task.js callback.js
  • 文件多次执行(建议使用纯函数):reducer.js config.js
  • config.js: 请直接参阅文件
  • /custom/reducer.js:
module.exports = function(task):Promise {
  // (Task)=>Promise 用于处理每次传入的task,返回值必须为Promise
  // Promise.resolve将会被打印在控制台,当前子进程将会被杀死
};
  • /custom/task.js:
module.exports = [
  // <Any> 用于定义每次传入reducer的值
]
  • /custom/callback.js:
module.exports = {
  every:function(result,worker) {
    //(Result,Worker)=>Any,  完成 **每次** 任务中resolve之后的值,如果有非null返回值将会被塞入最终结果,worker为执行任务的子进程
  },
  error:function(err,worker) {
    //(Error,Worker)=>Any,  完成 **每次** 任务中reject之后的值,如果有非null返回值将会被塞入最终结果,,worker为执行任务的子进程
  },
  all:function(result:Array,errors:Array) {
    //([Result],[Error])=>Any  完成 **所有** 任务之后的回调(与every调用顺序一致),[Result]与[Error]均为空则不调用
  },
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.