Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed concurrency hanging #430

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/jake.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (!global.jake) {
global.jake = new EventEmitter();

let fs = require('fs');
let chalk = require('chalk');
let pc = require('picocolors');
let taskNs = require('./task');
let Task = taskNs.Task;
let FileTask = taskNs.FileTask;
Expand Down Expand Up @@ -151,14 +151,14 @@ if (!global.jake) {
}

//name = '\033[32m' + p + '\033[39m ';
name = chalk.green(p);
name = pc.green(p);

descr = task.description;
if (descr) {
descr = chalk.gray('# ' + descr);
descr = pc.gray('# ' + descr);

// Create padding-string with calculated length
padding = (new Array(maxTaskNameLength - p.length - taskParams.length + 4)).join(' ');
padding = ' '.repeat(maxTaskNameLength - p.length - taskParams.length + 4);

console.log('jake ' + name + taskParams + padding + descr);
}
Expand Down Expand Up @@ -236,7 +236,8 @@ if (!global.jake) {

// FIXME: Should only need to add a new entry for the current
// task-definition, not reparse the entire structure
jake.parseAllTasks();
if (!jake.is_no_parse_all)
jake.parseAllTasks();

return task;
};
Expand Down
2 changes: 2 additions & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let utils = require('./utils');
const JAKELIB_FILE_PAT = /\.jake$|\.js$/;
const SUPPORTED_EXTENSIONS = {
'js': null,
'cjs': null,
'mjs': null,
'coffee': function () {
try {
let cs = require('coffeescript');
Expand Down
31 changes: 22 additions & 9 deletions lib/task/task.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let EventEmitter = require('events').EventEmitter;
let async = require('async');
let chalk = require('chalk');
let pc = require('picocolors');
// 'rule' module is required at the bottom because circular deps

// Used for task value, so better not to use
Expand Down Expand Up @@ -227,10 +227,14 @@ class Task extends EventEmitter {
self.handlePrereqDone(prereq);
}
else {
prereq.once('_done', () => {
this.handlePrereqDone(prereq);
prereq.removeAllListeners('_done');
});
let arr = prereq.listeners('_done');
if (!arr.length)
{
prereq.once('_done', () => {
this.handlePrereqDone(prereq);
prereq.removeAllListeners('_done');
});
}
if (prereq.taskStatus == Task.runStatuses.UNSTARTED) {
prereq.taskStatus = Task.runStatuses.STARTED;
prereq._invocationChain = this._invocationChain;
Expand Down Expand Up @@ -308,7 +312,11 @@ class Task extends EventEmitter {
}

if (!(this._internal || jake.program.opts.quiet)) {
console.log("Starting '" + chalk.green(this.fullName) + "'...");
jake.emit('started', {
name: this.fullName,
task: this,
});
console.log("Starting '" + pc.green(this.fullName) + "'...");
}

this.startTime = (new Date()).getTime();
Expand Down Expand Up @@ -361,11 +369,11 @@ class Task extends EventEmitter {
}

complete(val) {

// chain array can be empty [] when using concurrency
if (Array.isArray(this._waitForChains)) {
let stillWaiting = this._waitForChains.some((chain) => {
return !(chain.chainStatus == Task.runStatuses.DONE ||
chain.chainStatus == Task.runStatuses.ERROR);
chain.chainStatus == Task.runStatuses.ERROR || chain.length===0);
});
if (stillWaiting) {
let now = (new Date()).getTime();
Expand Down Expand Up @@ -401,7 +409,12 @@ class Task extends EventEmitter {
let taskTime = this.endTime - this.startTime;

if (!(this._internal || jake.program.opts.quiet)) {
console.log("Finished '" + chalk.green(this.fullName) + "' after " + chalk.magenta(taskTime + ' ms'));
jake.emit('finished', {
name: this.fullName,
task: this,
time: taskTime,
});
console.log("Finished '" + pc.green(this.fullName) + "' after " + pc.magenta(taskTime + ' ms'));
}

}
Expand Down
Loading