Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('action_status', () => {
beforeEach(() => {
upstreamJson = {
id: 'my-action',
lastCheckedRawFormat: '2017-03-01T20:55:49.679Z',
actionStatusJson: {
ack: {
timestamp: '2017-03-01T20:56:58.442Z',
Expand All @@ -107,8 +108,10 @@ describe('action_status', () => {
});

describe(`correctly calculates ACTION_STATES.ERROR`, () => {
it('lastExecutionSuccessful is equal to false', () => {
it('lastExecutionSuccessful is equal to false and it is the most recent execution', () => {
upstreamJson.actionStatusJson.last_execution.successful = false;
upstreamJson.actionStatusJson.last_execution.timestamp =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure what this assignment is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what I was going for there either 😂 . Removed.

upstreamJson.actionStatusJson.last_execution.timestamp;
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class ActionStatus {
this.id = props.id;
this.actionStatusJson = props.actionStatusJson;
this.errors = props.errors;
this.lastCheckedRawFormat = props.lastCheckedRawFormat;

this.lastExecutionRawFormat = get(this.actionStatusJson, 'last_execution.timestamp');
this.lastAcknowledged = getMoment(get(this.actionStatusJson, 'ack.timestamp'));
this.lastExecution = getMoment(get(this.actionStatusJson, 'last_execution.timestamp'));
this.lastExecutionSuccessful = get(this.actionStatusJson, 'last_execution.successful');
Expand All @@ -30,7 +32,10 @@ export class ActionStatus {
const actionStatusJson = this.actionStatusJson;
const ackState = actionStatusJson.ack.state;

if (this.lastExecutionSuccessful === false) {
if (
this.lastExecutionSuccessful === false &&
this.lastCheckedRawFormat === this.lastExecutionRawFormat
) {
Comment on lines +35 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this it looks like lastExecutionSuccessful can be false but we have an edge case where lastCheckedRawFormat come after that? I.o.w. the last execution could be successful even though the lastExecutionSuccessful field is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the watch only "executes" when the condition is met, but the watch condition is checked on a given interval. So the last time it was executed could be false, but the next time it is checked the condition may not be met so it doesn't execute. Does that make sense? I also tried to explain this in the PR description, but I'm probably not doing the best job so let me know if you need me to clarify more 😅 .

return ACTION_STATES.ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class WatchStatus {
id,
actionStatusJson,
errors: this.watchErrors.actions && this.watchErrors.actions[id],
lastCheckedRawFormat: get(this.watchStatusJson, 'last_checked'),
};
return ActionStatus.fromUpstreamJson(json);
});
Expand Down