Skip to content

There needs to be a deterministic way to determine when a metaSignal command has completed #42

Description

@chefsteph9

Currently, there is just a timer after the dataHub.megaSignalCommand is issued to make sure that it has been executed. This is non-deterministic and is not guaranteed to work. There needs to be a way for the DataHub to let the web page know when the MetaSignalCommand has executed.

An example of code that uses a timer when a better solution is needed is the addNewSignals function in
io-mapping-scripts.js:

    $scope.addNewSignals = function () {
        var promises = [];
        $.each($scope.mapping.Type.Fields, function (i, f) {
            var ms = {
                'AnalyticProjectName': $('#proj' + f.Identifier).val(),
                'AnalyticInstanceName': $('#inst' + f.Identifier).val(),
                'DeviceID': '00000000-0000-0000-0000-000000000000',
                'RuntimeID': 0,
                'SignalID': $('#signalID' + f.Identifier).val(),
                'PointTag': $('#point' + f.Identifier).val(),
                'SignalType': $('#type' + f.Identifier).val(),
                'Description': $('#desc' + f.Identifier).val()
            }
            $scope.mapping.FieldMappings[i].Expression = $('#point' + f.Identifier).val();
            promises.push(dataHub.metaSignalCommand(ms));
        });

        $(promises).whenAll().done(function () {
            // TODO: The setTimout is a temporary solution. A more permanent solution would involve maintaining a count of the number of metasignals sent and received
            // and refreshing the metadata when we know that all metasignal commands have been executed sucessfully.
            setTimeout(function () {  
                $(window).one('metaDataReceived', function () {  
                    dataHub.getMeasurementDetails().done(function (md) {
                        $.each($scope.mapping.Type.Fields, function (i, f) {
                            var signals = $.grep(md, function (d) { return d.PointTag == $('#point' + f.Identifier).val() });
                            if (signals.length > 0) {
                                $('#signalID' + f.Identifier).val(signals[0].SignalID);
                            }
                        });
                    });
                });
                dataHub.refreshMetaData();
            }, 1100); // If it's not working, make this number bigger. See: TODO above.
        });
        $scope.signalsAdded = true;
        $('#signalDialog').modal('hide');
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions