Skip to content

Commit

Permalink
Cleanup, bug fix, and test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
msavin committed Feb 28, 2018
1 parent 798cbe1 commit 3399a80
Show file tree
Hide file tree
Showing 28 changed files with 272 additions and 83 deletions.
8 changes: 4 additions & 4 deletions package/server/imports/actions/add/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Utilities } from '../../utilities'
import { processArguments } from './processArguments.js'
import { Utilities } from "../../utilities"
import { processArguments } from "./processArguments.js"

var add = function () {
// 0. Prepare variables
Expand All @@ -25,10 +25,10 @@ var add = function () {

// 5. Mission accomplished
if (typeof input.config.callback === "function") {
return input.config.callback(error, result);
input.config.callback(error, result);
}

return resut;
return result;
}

export { add }
22 changes: 11 additions & 11 deletions package/server/imports/actions/add/processArguments.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var configIsPresent = function (input) {
var lastItem = input[input.length - 1],
lastItemIsConfig = false,
reservedWords = ["in", "on", "priority", "date", "data", "callback"];

if (typeof lastItem === "object") {
reservedWords.forEach(function (word) {
if (lastItem[word]) {
lastItemIsConfig = true;
var checkConfig = function (input) {
var result = false,
lastArgument = input[input.length - 1],
keywords = ["in", "on", "priority", "date", "data", "callback"];

if (typeof lastArgument === "object") {
keywords.forEach(function (keyword) {
if (lastArgument[keyword]) {
result = true;
}
});
}

return lastItemIsConfig;
return result;
}

var processArguments = function (args) {
Expand All @@ -24,7 +24,7 @@ var processArguments = function (args) {
}()

output.config = function () {
if (configIsPresent(args)) {
if (checkConfig(args)) {
var config = args.pop();
return config;
} else {
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/cancel/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

var cancel = function (job, callback) {
var error,
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/clear/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

var clear = function (state, name, callback) {
action = {
Expand Down
4 changes: 2 additions & 2 deletions package/server/imports/actions/execute/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Utilities } from '../../utilities'
import { process } from './process.js'
import { Utilities } from "../../utilities"
import { process } from "./process.js"

var execute = function (job, callback) {
var jobDoc = Utilities.helpers.getJob(job, {
Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/actions/execute/process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Utilities } from '../../utilities'
import { toolbelt } from './toolbelt.js'
import { reschedule } from '../reschedule/'
import { Utilities } from "../../utilities"
import { toolbelt } from "./toolbelt.js"
import { reschedule } from "../reschedule/"

var process = function (doc, callback) {
// Goals:
Expand Down
12 changes: 6 additions & 6 deletions package/server/imports/actions/execute/toolbelt.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Utilities } from '../../utilities'
import { Operator } from '../../operator'
import { reschedule } from '../reschedule/'
import { replicate } from '../replicate/'
import { remove } from '../remove/'
import { Utilities } from "../../utilities"
import { Operator } from "../../operator"
import { reschedule } from "../reschedule/"
import { replicate } from "../replicate/"
import { remove } from "../remove/"

var toolbelt = function (jobDoc) {
this.document = jobDoc;
Expand Down Expand Up @@ -44,7 +44,7 @@ var toolbelt = function (jobDoc) {
}
}

return this.document.data.key || null;
return this.document.data[key] || null;
}

this.success = function (result) {
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/get/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

var get = function (input, verify, callback) {
var jobDoc = Utilities.helpers.getJob(input, {}, verify)
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/remove/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

var remove = function (job, callback) {
var error,
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/replicate/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

var replicate = function (job, config, callback) {
var error,
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/actions/reschedule/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utilities } from '../../utilities'
import { Utilities } from "../../utilities"

reschedule = function (job, config, callback) {
var error,
Expand Down
4 changes: 2 additions & 2 deletions package/server/imports/operator/dominator/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mongo } from 'meteor/mongo'
import { Utilities } from '../../utilities/'
import { Mongo } from "meteor/mongo"
import { Utilities } from "../../utilities/"

/*
Potential Optimization
Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/operator/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { queue } from './queue/'
import { dominator } from './dominator/'
import { manager } from './manager/'
import { queue } from "./queue/"
import { dominator } from "./dominator/"
import { manager } from "./manager/"

Operator = {
dominator: dominator,
Expand Down
12 changes: 6 additions & 6 deletions package/server/imports/operator/queue/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Utilities } from '../../utilities/'
import { execute } from '../../actions/execute';
import { dominator } from '../dominator';
import { Meteor } from "meteor/meteor"
import { Utilities } from "../../utilities/"
import { execute } from "../../actions/execute"
import { dominator } from "../dominator"

var queue = function (name) {
this.name = name;
Expand All @@ -15,7 +15,7 @@ queue.prototype.start = function () {
var self = this;

if (self.interval) {
Utilities.logger('Cannot start queue because it has already been started: ' + self.name);
Utilities.logger("Cannot start queue because it has already been started: " + self.name);
return;
}

Expand All @@ -27,7 +27,7 @@ queue.prototype.stop = function () {
var self = this;

if (!self.interval) {
Utilities.logger('Cannot stop queue because it has already been stopped: ' + self.name);
Utilities.logger("Cannot stop queue because it has already been stopped: " + self.name);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/startup/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor'
import { Utilities } from '../utilities/'
import { Operator } from '../operator/'
import { Meteor } from "meteor/meteor"
import { Utilities } from "../utilities/"
import { Operator } from "../operator/"

// 1. Wait 5 seconds for all the code to initialize
// 2. Start Jobs if autoStart is enabled
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/utilities/collection/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mongo } from 'meteor/mongo'
import { Mongo } from "meteor/mongo"

collection = new Mongo.Collection("jobs_data");

Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/utilities/config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Random } from 'meteor/random'
import { Random } from "meteor/random"

var config = {
started: false,
Expand Down
10 changes: 5 additions & 5 deletions package/server/imports/utilities/helpers/date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { number } from './number.js'
import { logger } from '../logger'
import { config } from '../config'
import { number } from "./number.js"
import { logger } from "../logger"
import { config } from "../config"

var date = function (input1, input2) {
var currentDate = config.getDate()
Expand Down Expand Up @@ -121,7 +121,7 @@ var date = function (input1, input2) {
// Run the magic (if possible ;)

if (typeof action === "object") {

Object.keys(action).forEach(function (key1) {
if (["in","on"].indexOf(key1) > -1) {
Object.keys(action[key1]).forEach(function (key2) {
Expand All @@ -142,7 +142,7 @@ var date = function (input1, input2) {

return currentDate;
} else {
console.log("invalid argument(s) date generator");
logger("Invalid argument(s) for date generator");
}
}

Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/utilities/helpers/generateDueDate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '../logger'
import { date } from './date.js'
import { config } from '../config'
import { logger } from "../logger"
import { config } from "../config"
import { date } from "./date.js"

generateDueDate = function (configObj) {
var due = config.getDate();
Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/utilities/helpers/generateJobDoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '../config'
import { generateDueDate } from './generateDueDate.js'
import { number } from './number.js'
import { config } from "../config"
import { generateDueDate } from "./generateDueDate.js"
import { number } from "./number.js"

var generateJobDoc = function (input) {
return {
Expand Down
6 changes: 3 additions & 3 deletions package/server/imports/utilities/helpers/getJob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { collection } from '../collection'
import { logger } from '../logger'
import { collection } from "../collection"
import { logger } from "../logger"

getJob = function (input, filter, verify) {
var jobDoc;
Expand Down Expand Up @@ -31,7 +31,7 @@ getJob = function (input, filter, verify) {
}
This could be done in the database, but:
- its probably faster to query by _id than anything else
- its probably faster to query with just _id
- we might be passing into a cached document into this function
*/

Expand Down
10 changes: 5 additions & 5 deletions package/server/imports/utilities/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { generateDueDate } from './generateDueDate.js'
import { generateJobDoc } from './generateJobDoc.js'
import { number } from './number.js'
import { date } from './date.js'
import { getJob } from './getJob.js'
import { generateDueDate } from "./generateDueDate.js"
import { generateJobDoc } from "./generateJobDoc.js"
import { number } from "./number.js"
import { date } from "./date.js"
import { getJob } from "./getJob.js"

var helpers = {
generateDueDate: generateDueDate,
Expand Down
17 changes: 7 additions & 10 deletions package/server/imports/utilities/helpers/number.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { logger } from "../logger"

var number = function (input, note) {
if (typeof input === "undefined") {
return 0;
Expand All @@ -9,19 +11,14 @@ var number = function (input, note) {

if (typeof input === "string") {
input = Number(input);

if (isNaN(input)) {
console.log("Jobs: invalid input for " + note || "number");
return 0
}
}

if (typeof input === "number") {
return input;
} else {
console.log("Jobs: invalid input for " + note || "number");
return 0;
if (isNaN(input)) {
input = 0;
logger(["Invalid input for " + note || "number", "therefore, it was set to 0"]);
}

return input;
}

export { number }
10 changes: 5 additions & 5 deletions package/server/imports/utilities/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from './config'
import { logger } from './logger'
import { helpers } from './helpers'
import { registry } from './registry'
import { collection } from './collection'
import { config } from "./config"
import { logger } from "./logger"
import { helpers } from "./helpers"
import { registry } from "./registry"
import { collection } from "./collection"

var Utilities = {
config: config,
Expand Down
2 changes: 1 addition & 1 deletion package/server/imports/utilities/logger/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config } from '../config'
import { config } from "../config"

var logger = function (messages) {
config.log(messages);
Expand Down
Loading

0 comments on commit 3399a80

Please sign in to comment.