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

Projections debugging #130

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -41,20 +41,36 @@ protected override IEnumerable<WhenStep> When()
yield return (new SystemMessage.BecomeMaster(Guid.NewGuid()));
yield return
(new ProjectionManagementMessage.Command.Post(
new PublishEnvelope(_bus), _projectionMode, _projectionName,
ProjectionManagementMessage.RunAs.System, "JS",
_projectionSource, enabled: false, checkpointsEnabled: false,
new PublishEnvelope(_bus),
_projectionMode,
_projectionName,
ProjectionManagementMessage.RunAs.System,
"JS",
_projectionSource,
enabled: false,
checkpointsEnabled: false,
emitEnabled: false));

yield return
new ProjectionManagementMessage.Command.Enable(
Envelope, _projectionName, ProjectionManagementMessage.RunAs.System);
new ProjectionManagementMessage.Command.Disable(
Envelope,
_projectionName,
ProjectionManagementMessage.RunAs.System);

yield return
new WhenStep(
new ProjectionManagementMessage.Command.UpdateQuery(
Envelope, _projectionName, ProjectionManagementMessage.RunAs.System, "JS", _projectionSource,
emitEnabled: false),
new ProjectionManagementMessage.Command.Enable(
Envelope, _projectionName, ProjectionManagementMessage.RunAs.System));
new ProjectionManagementMessage.Command.UpdateQuery(
Envelope,
_projectionName,
ProjectionManagementMessage.RunAs.System,
"JS",
_projectionSource,
emitEnabled: false);

yield return
new ProjectionManagementMessage.Command.Enable(
Envelope,
_projectionName,
ProjectionManagementMessage.RunAs.System);
}

[Test]
Expand Down
24 changes: 21 additions & 3 deletions src/EventStore/EventStore.Projections.Core/Prelude/Projections.js
Expand Up @@ -235,9 +235,27 @@ var $projections = {
}

function callHandler(handler, state, eventEnvelope) {
if (debugging)
debugger;
var newState = handler(state, eventEnvelope);
var newState;
if (debugging) {
try {



debugger;

/* F11 to step into the projection user code */

newState = handler(state, eventEnvelope);



} catch (ex) {
_log("Exception: " + ex.toString());
throw ex;
}
} else {
newState = handler(state, eventEnvelope);
}
if (newState === undefined)
newState = state;
return newState;
Expand Down
Expand Up @@ -535,6 +535,7 @@ private void DoReset1()
private void ResetProjection()
{
UpdateProjectionVersion(force: true);
Enabled = false;
_persistedState.Epoch = _persistedState.Version;
}

Expand Down
Expand Up @@ -29,10 +29,10 @@ require(['projections/Observer', 'projections/Controller'],

observer.subscribe({
statusChanged: function (status) {
if (status.status !== "Stopped" && status.status !== "Faulted")
if (status.status.indexOf("Stopped") !== 0 && status.status.indexOf("Faulted") !== 0)
alert("The projection must be stopped to be debugged. " + status.status);
projectionStatusOk = true;
checkLoaded();
partLoaded();
},
stateChanged: function (state, xhr) {
var positionJson = xhr.getResponseHeader("ES-Position");
Expand Down Expand Up @@ -104,9 +104,10 @@ require(['projections/Observer', 'projections/Controller'],
$('.run-button').removeAttr("disabled");
if (data == "") {
processor.initialize();
cachedStates[partition] = processor.debugging_get_state();
} else
} else {
processor.set_state(data);
}
cachedStates[partition] = processor.debugging_get_state();
$("#projection-debug-result").text(cachedStates[partition]);
}

Expand Down Expand Up @@ -208,7 +209,6 @@ require(['projections/Observer', 'projections/Controller'],
currentEvent.isJson ? JSON.stringify(currentEvent.metadata) : currentEvent.metadata,
partition);


cachedStates[partition] = state;
console.log(currentEvent.readerPosition);
projectionPosition = currentEvent.readerPosition;
Expand Down
Expand Up @@ -28,6 +28,7 @@ define(["ace/ace", "projections/ui/Confirmation", "projections/Observer", "proje
var lastEmitEnabled = false;
var lastStatusUrl = url;
var lastName = null;
var lastStatus = null;

function setEnabled(control, enabled) {
if (!control)
Expand Down Expand Up @@ -74,6 +75,7 @@ define(["ace/ace", "projections/ui/Confirmation", "projections/Observer", "proje
window.location.hash = status.statusUrl;
lastStatusUrl = status.statusUrl;
lastName = status.name;
lastStatus = status.status;
}

function urlChanged(url) {
Expand Down Expand Up @@ -190,6 +192,14 @@ define(["ace/ace", "projections/ui/Confirmation", "projections/Observer", "proje
}
}

function resetIfCompleted(success) {
if (lastStatus.indexOf("Completed") === 0) {
controller.reset(success);
} else {
success();
}
}

function updateAndStart() {
var success = controller.start.bind(controller);
updateIfChanged(success);
Expand All @@ -203,7 +213,9 @@ define(["ace/ace", "projections/ui/Confirmation", "projections/Observer", "proje

function debug() {
updateIfChanged(function () {
window.open("/web/debug-projection.htm#" + lastStatusUrl, "debug-" + lastName);
resetIfCompleted(function() {
window.open("/web/debug-projection.htm#" + lastStatusUrl, "debug-" + lastName);
});
});
}

Expand Down