Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // How a team of engineers interacts with projects
- engineers = [];
- backlog = new PriorityQueue();
- projectsInProgress = new PriorityQueue();
- projectsFinished = [];
- engineers.forEach(engineer => {
- engineer.on('puzzled', findHelp);
- engineer.on('tired', rest);
- engineer.on('frustrated', takeBreak);
- // this can happen when the engineer's current project no longer has an available stream of work
- engineer.on('idle', allocateProjects);
- })
- backlog.forEach(project => {
- project.on('ship', handleShip);
- })
- const handleShip = (project) => {
- project.engineers.forEach(handleFinish);
- projectsInProgress.remove(project);
- projectsFinished.push(project);
- allocateProjects();
- }
- const handleFinish = (engineer) => {
- engineer.project = undefined;
- engineer.celebrate();
- engineer.takeBreak();
- }
- const availableEngineers = () => _.reject(engineers, 'project');
- const isEngineerAvailable = () => !.empty(availableEngineers());
- const mostExcitedAvailableEngineer = (project) => _.first(
- _.sortBy(
- availableEngineers(),
- engineer => getExcitement(engineer, project)
- )
- )
- const assign = (engineer, project) => {
- engineer.project = project;
- project.engineers.push(engineer);
- }
- const allocateEngineer = (engineer, project = new Project('engineer driven project')) => {
- assign(engineer, project);
- }
- const mostImportantAvailableProject = () => _.first(_.filter(projectsInProgress, canUseEngineer)) || backlog.pop();
- const allocateProjects = () => {
- while (isEngineerAvailable()) {
- // something truly exciting happens when project === undefined, and in the best performing teams I've seen
- // this will happen and we view it as a joyous occasion
- const project = mostImportantAvailableProject();
- while (isEngineerAvailable() && canUseEngineer(project)) {
- const chosenEngineer = mostExcitedAvailableEngineer(project);
- allocateEngineer(chosenEngineer, project);
- }
- }
- }
- // To kick it all off
- allocateProjects();
- // ============
- // How a team of engineers interacts with a single project
- // A project can start out as vague as 'Plan how to build this' and the
- // DAG grows as the team gets clarity on the scope of the project.
- const tasks = new DirectedAcyclicGraph();
- const engineers = [];
- let canUseEngineer = false;
- const isReady = (task) => _.every(task.dependency, 'isDone');
- const availableTasks = () => _.filter(tasks, isReady);
- const mostExcitedAvailableEngineer = (task) => _.first(
- _.sortBy(
- availableEngineers(),
- engineer => getExcitement(engineer, task)
- )
- )
- const allocateTasks = () => {
- while (isEngineerAvailable() && !_.empty(availableTasks())) {
- const chosenEngineer = mostExcitedAvailableEngineer(task);
- assign(chosenEngineer, task);
- }
- if (isEngineerAvailable()) {
- // we've run out of parallel workstreams, engineers left out of work might want
- // to find another project using their idle callback
- availableEngineers().forEach(engineer => engineer.idle());
- }
- if (isTaskAvailable()) {
- canUseEngineer = makeAnInformedGuess();
- }
- }
- // kick it off
- allocateTasks();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement