Skip to content

Code Component Can Not Store State Between Executions #41

@jhorbulyk

Description

@jhorbulyk

Steps to reproduce

  1. Create a flow: Simple Trigger -> JSONata Transform -> Code
    JSONata transform:
[{"one": "foo"}, {"two":"bar"}, {"three": "baz"}]

Code component:

let state = {}
async function run(msg, cfg, snapshot) {
    this.logger.info(`Pre State is: ${JSON.stringify(state)}`);
    state = _.merge(state, msg.body);
    this.logger.info(`Post State is: ${JSON.stringify(state)}`);
	await this.emit('data', { body : {} });
	this.logger.info('Execution finished');
}

2.Run the flow once and look at the logs of the code component

Actual Result

The logs contain

Pre State is: {}
Post State is: {"one":"foo"}
Pre State is: {}
Post State is: {"two":"bar"}
Pre State is: {}
Post State is: {"three":"baz"}

Expected Result

The logs contain

Pre State is: {}
Post State is: {"one":"foo"}
Pre State is: {"one":"foo"}
Post State is: {"one":"foo", "two":"bar"}
Pre State is: {"one":"foo", "two":"bar"}
Post State is: {"one":"foo", "two":"bar", "three":"baz"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ready For ToDoThe task can be transferred to Backlog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions