dm-worker
> Worker
Last updated a year ago by yska .
ISC · Original npm · Tarball · package.json
$ cnpm install dm-worker 
SYNC missed versions from official npm registry.

dm-worker

Worker

Usage

  1. In project root create worker.js:

    const conf = require('nconf')
    require('dm-sharedb-server/nconf')
    
    const path = require('path')
    
    // full path to workerActions.js and workerInit.js
    process.env['WORKER_ACTIONS_PATH'] = path.join(process.cwd(), './build/workerActions.js')
    process.env['WORKER_INIT_PATH'] = path.join(process.cwd(), './build/workerInit.js')
    
    const TaskDispatcher = require('dm-worker')
    const dispatcher = new TaskDispatcher()
    
    dispatcher.start().catch((err) => {
      console.log('Error starting worker', err)
    })
    
  2. In project root create workerInit.js. Do any initializations here (plug in hooks, ORM, etc.). Since this file may be compiled by webpack, use global.DM_WORKER_INIT instead of module.exports:

    import 'dm-sharedb-server/nconf'
    import ShareDB from 'sharedb'
    import richText from 'rich-text'
    import Racer from 'racer'
    import derbyAr from 'derby-ar'
    import ormEntities from './model'
    import shareDbHooks from 'sharedb-hooks'
    import hooks from './server/hooks'
    
    let init = global.DM_WORKER_INIT = function (backend) {
      // Register rich-text type in ShareDB
      ShareDB.types.register(richText.type)
    
      // Init ORM
      Racer.use(derbyAr)
      Racer.use(ormEntities)
      shareDbHooks(backend)
      hooks(backend)
    }
    
  3. In project root create workerActions.js. Put your tasks here (name of functions are the name of tasks). Since this file may be compiled by webpack, use global.DM_WORKER_ACTIONS instead of module.exports:

    let ACTIONS = global.DM_WORKER_ACTIONS = {}
    
    ACTIONS.test = function (model, task, done) {
      console.log('>> Start test task', task.id)
      setTimeout(() => {
        console.log('>> Finish test task', task.id)
        done()
      }, 5000)
    }
    
  4. Add worker, workerInit, workerActions to webpack.config.js of dm-react-webpack:

    module.exports = {   
      // ...
    
      backendApps: {
        server: path.join(__dirname, 'server'),
        worker: path.join(__dirname, 'worker'),
        workerActions: path.join(__dirname, 'workerActions'),
        workerInit: path.join(__dirname, 'workerInit')     
      }
    
      // ...   
    }
    

MIT Licence

Copyright (c) 2019 Decision Mapper

Current Tags

  • 4.6.3                                ...           latest (a year ago)

41 Versions

  • 4.6.3                                ...           a year ago
  • 4.6.2                                ...           a year ago
  • 4.6.1                                ...           a year ago
  • 4.6.0                                ...           2 years ago
  • 4.5.2                                ...           2 years ago
  • 4.5.1                                ...           2 years ago
  • 4.5.0                                ...           2 years ago
  • 4.4.2                                ...           2 years ago
  • 4.4.1                                ...           2 years ago
  • 4.4.0                                ...           2 years ago
  • 4.3.1                                ...           3 years ago
  • 4.3.0                                ...           3 years ago
  • 4.2.2                                ...           3 years ago
  • 4.2.1                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 2.2.5                                ...           3 years ago
  • 2.2.4                                ...           3 years ago
  • 2.2.3                                ...           3 years ago
  • 4.1.1                                ...           3 years ago
  • 2.2.2                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.2                                ...           3 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.0.6                                ...           3 years ago
  • 3.0.5                                ...           3 years ago
  • 3.0.4                                ...           3 years ago
  • 3.0.3                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.2.1                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 2
Dependencies (4)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |