Skip to content

Commit

Permalink
For the application cache worker so it won't hold up the main thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaine Schmeisser committed Aug 27, 2016
1 parent b397c7d commit d7a47e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
21 changes: 12 additions & 9 deletions appCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ const Finder = require('./lib/finder')
const fs = require('fs')
const path = require('path')

const finder = new Finder({
includePath: directories.appPath,
excludePath: directories.excludePath,
excludeName: directories.excludeName,
})

module.exports = (pluginContext) => {
function setup (pluginContext) {
const { cwd } = pluginContext
const appPath = path.join(cwd, 'data', 'applications.json')
return (env = {}) => {
const appPath = path.join('data', 'applications.json')
const finder = new Finder({
includePath: directories.appPath,
excludePath: directories.excludePath,
excludeName: directories.excludeName,
})
return function run () {
return finder.deepFind().then((files) => {
return files.filter((file) => {
return file.isApp()
Expand All @@ -29,3 +28,7 @@ module.exports = (pluginContext) => {
})
}
}

const cwd = __dirname

setup({ cwd })()
13 changes: 13 additions & 0 deletions appCacheManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fork = require('child_process').fork
const path = require('path')

module.exports = (pluginContext) => {
const { cwd } = pluginContext
const appCacheProcess = path.join(cwd, 'appCache.js')
return () => {
const runner = fork(appCacheProcess, {cwd})
return new Promise((resolve) => {
runner.on('exit', resolve)
})
}
}
4 changes: 2 additions & 2 deletions zazu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
{
id: 'AppCache',
type: 'ServiceScript',
script: 'appCache.js',
interval: 30000,
script: 'appCacheManager.js',
interval: 30 * 1000,
},
],
input: [
Expand Down

0 comments on commit d7a47e4

Please sign in to comment.