Skip to content

Commit

Permalink
- Code format now follo original traipack .editorconfig format
Browse files Browse the repository at this point in the history
- Added Task class (for future compatibility)
- Improved KueService
  • Loading branch information
LobeTia committed Nov 26, 2016
1 parent 4134387 commit 7d50e6d
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 58 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ jspm_packages

# Optional REPL history
.node_repl_history
LICENSE
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Mattia Lobertini <[email protected]> <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ Define tasks in `api.tasks`. Tasks are run by kue.
const Task = require("trailpack-kue").Task

module.exports = class HelloWorldTask extends Task {
contructor(){
super()
contructor(app){
super(app)
}

run(job, done) {
run(job, done, app) {
console.log("Hello ", job.data.name);
done();
}
Expand Down
35 changes: 19 additions & 16 deletions api/services/KueService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ const Kue = require("kue");
* @description TODO document Service
*/
module.exports = class KueService extends Service {
init() {
const config = this.app.config.kue;
init() {
const config = this.app.config.kue;

this.kueInstance = Kue.createQueue();
this.tasks = {}
this.kueInstance = Kue.createQueue();
this.tasks = {}

const tasks = Object.keys(config.tasks)
tasks.forEach(task => {
this.addTask(task, config.tasks[task])
})
}
const tasks = Object.keys(config.tasks)
tasks.forEach(task => {
this.addTask(task, config.tasks[task])
})
}

addTask(name, task) {
let _task = new this.app.api.tasks[task.controller]
this.kueInstance.process(name, _task.run)
}
addTask(name, task) {
let app = this.app
let _task = new this.app.api.tasks[task.controller](app)
this.kueInstance.process(name, function(data, done) {
_task.run(data, done, app);
})
}

addJob(name, obj){
return this.kueInstance.createJob(name, obj)
}
addJob(name, obj) {
return this.kueInstance.createJob(name, obj)
}
};
66 changes: 33 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ const lib = require("./lib");

module.exports = class KueTrailpack extends Trailpack {

/**
* TODO document method
*/
validate() {
if (!this.app.config.kue) throw new Error("config.kue not defined")
if (!this.app.config.kue.tasks) throw new Error("config.kue.tasks not defined")
if (!this.app.config.kue.webui) throw new Error("config.kue.webui not defined")
}

/**
* TODO document method
*/
configure() {

}

/**
* TODO document method
*/
initialize() {
this.app.on("trails:ready", () => {
this.app.services.KueService.init();
})
return Promise.resolve();
}

constructor(app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
/**
* TODO document method
*/
validate() {
if (!this.app.config.kue) throw new Error("config.kue not defined")
if (!this.app.config.kue.tasks) throw new Error("config.kue.tasks not defined")
if (!this.app.config.kue.webui) throw new Error("config.kue.webui not defined")
}

/**
* TODO document method
*/
configure() {

}

/**
* TODO document method
*/
initialize() {
this.app.on("trails:ready", () => {
this.app.services.KueService.init();
})
return Promise.resolve();
}

constructor(app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
}

module.exports.Task = lib.Task
5 changes: 2 additions & 3 deletions lib/Task.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

module.exports = class Task {
constructor() {

}
constructor() {
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"main": "index.js",
"keywords": [
"trails",
"trailsj",
"kue",
"trailpack",
"trails",
"trailsj",
"trailjs"
],
"dependencies": {
Expand Down

0 comments on commit 7d50e6d

Please sign in to comment.