Using SignalR for lengthy processes: transmitting progress updates

Utilizing SignalR to initiate lengthy computations on the server and notify the client when the results are ready. The input bindings consist of an HTTP request.

Desire to send multiple messages to update the client on various stages of the process (e.g., start of computation, end of computation, etc.).

Tried pushing individual messages to context.bindings.signalRMessages but noticed they all get sent together at the end of the entire process. Is there a method to send multiple messages at different points in time?

Another issue is that the client's HTTP request remains in a frozen state until the process completes. Would like to provide an immediate response early on, as the response will be received through a signalR message.

Below is the server-side code:

module.exports = async function(context, req) {
    let ID = context.bindingData.invocationId;

    context.bindings.signalRMessages = [];
    const messageQueue = context.bindings.signalRMessages;

    var postMessage = (message) => {
        message.userId = req.query.userId;
        message.isPrivate = true;
        messageQueue.push(message);
    };

    let preProcessData = preProcess(req.body.input);

    let startMessage = {
        "target": "optimStart",
        "arguments": [{ preProcessData: preProcessData }]
    };
    postMessage(startMessage); // <<<< I want this one to be sent immediately

    try {
        let optimOutput = await computeOptim(req.body.input, ID); // that's the long process

        let response = {
            optimId: ID,
            optimOutput: optimOutput
        };

        let optimCompleteMessage = {
            "target": "optimComplete",
            "arguments": [response]
        };
        postMessage(optimCompleteMessage);
    } catch (err) {
        // ....
    }

};

Could it be an error in my implementation or is it simply not possible?

Appreciate any insights!

Answer №1

Unfortunately, a straightforward HTTP triggered function won't suffice for this task as bindings are resolved only after the function execution is complete.

In your specific case, utilizing durable functions would be the ideal solution.

You can still employ an HTTP Triggered function (client function) to initiate orchestration and promptly return. Within the orchestration function, you will implement distinct activity functions for processing and transmitting updates to the client using the SignalR binding.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Instructions on activating the standard scrolling function for a specific DIV element

I'm struggling to achieve a specific scrolling effect on my one-page website. I want the initial section to be displayed as a full page, and when the user scrolls down, it should transition to the next section with a full page scroll. However, once th ...

Redis: Unable to establish a connection as net.connect is not recognized as a

I'm struggling to integrate Redis with nodejs Encountering issues during execution Despite using the same code, I am facing this error: Here's my code snippet: import { createClient } from 'redis' export const client = createClient({ ...

Save this text in HTML format to the clipboard without including any styling

When using this code to copy a htmlLink to the clipboard: htmlLink = "<a href='#'>link</a>"; var copyDiv = document.createElement('div'); copyDiv.contentEditable = true; document.body.appendChild(copyDiv); ...

Deciphering the AngularJS Component Hierarchy and Managing Identifiers for Freshly Generated Objects (using HTTP)

In my project using Angular 1, I have developed a todo list application which consists of two components. The first is a smart (container) component responsible for server-side interactions, while the second is a dumb/pure/stateless presentation component ...

The connection between the type of request and the corresponding response in an Ajax function

When using the following: xhr.setRequestHeader("Content-Type", "application/json"); Am I obligated to only receive a response in json format, or is it possible to receive an html response instead? If there is flexibility in receiving different formats, h ...

Ajax ensures that the site stays active and responsive

Struggling to understand how to make this code work. var request; if(window.XMLHttpRequest){ request= new XMLHttpRequest(); }else{ request = new ActiveXObject("Microsoft.XMLHTTP"); } var handleStateChange = function () { switch (request.re ...

PHP script for batch string replacement

My function is triggered by a button click, where it takes two input IDs and forms a string as follows: var str = "headingText=" + $("#headingText").val() + "&centerText=" + $("#centerText").val(); $.ajax({ url: "indexpdf.php", data: str, ...

The JQuery chosen dropdown experiences a visual issue when placed inside a scrollbar, appearing to be "cut

Good day, I've been using the jQuery "chosen" plugin for a dropdown menu, but I encountered an issue with it being located in a scrollable area. The problem is that the dropdown items are getting cut off by the outer div element. I have provided a si ...

What are the steps to designing your own unique custom button with Material-UI?

While Material-UI allows you to utilize withStyles() for creating a Button with a predefined set of styles, I am curious if it is achievable to achieve the same result using props instead. This would ensure that all custom buttons I create automatically ha ...

The program failed to run properly because it couldn't find the reference to Chart

I added chart.js to my project using npm with the command: npm install chart.js --save-dev. In the file "resources/assets/js/bootstrap.js", I included it by using: require('chart.js');. After running npm run dev in the console, it compiled succe ...

Tips for concealing a div when the mouse is moved off it?

My goal is to create a simple hover effect where hovering over an image within a view filled with images displays an additional div. This part works as expected. However, I'm facing issues when trying to hide the same div when the user moves out of t ...

Save the content of a string object into an array

I am currently implementing an array sorting functionality using the MVC approach. The array called "array" is used to store values provided at runtime. Within the view, there is a textbox and a button for user input of integer values. Upon clicking the bu ...

The Homescreen.js file is not showing up as expected on the localhost/home page and is not displaying

Struggling to showcase the rooms on my hotel reservation website. Can't seem to crack it. Need some assistance, please. Spent a good 3 hours trying to figure this out. Snippet from My Homescreen.js import React ,{useState, useEffect, } from &apo ...

Ways to dynamically assign a name to a div using AngularJS

Currently, I am in the process of developing a download function for an Android app using Angularjs based on this tutorial: Utilizing the Progress event in PhoneGap file transfers Everything seems to be working efficiently as planned; I can successfully d ...

Azure Function encountered an issue while constructing the configuration in an external startup class

Currently, in my Azure Function using ".Net 8", I am attempting to implement a custom start-up as outlined in this article here. Below is the custom start-up code snippet: using System; using System.IO; using Microsoft.Azure.Functions.Extensions.Dependenc ...

Discover the secret to instantly displaying comments after submission without refreshing the page in VueJS

Is there a way to display the comment instantly after clicking on the submit button, without having to refresh the page? Currently, the comment is saved to the database but only appears after refreshing. I'm looking for a solution or syntax that can h ...

Is it advisable to perform unit testing on my JavaScript code?

I'm interested in exploring the potential value of using QUnit. However, I am completely new to testing, especially with JS, and don't know where to begin. I would appreciate any guidance on starting unit testing for an application that already ...

Allow editing for only a specific part of a text box

Creating a customized personal URL page for users on my site is important to me. I envision the value of a text box being "example.com/username," with the "example.com/" part displayed in the text box, but not editable. I've noticed that Tumblr accom ...

The table is unable to properly display the array data

My code includes an AJAX function that sends a GET request to an API and receives data in the format shown below: { "firstname": "John", "lastname": "Doe", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6 ...

Refreshing MongoDB data by utilizing values from an object

I am facing a challenge with my MongoDB collection structure: [ { "stock": "GOOGLE", "price": 0 }, { "stock": "FACEBOOK", "price": 0 } ] On the other hand, I have a Stock_P ...