Monitor for the specific parameter in the incoming GET request

My application is using the POST method to submit jobs remotely. After submitting a job, I receive a unique job ID from the POST request that allows me to check the status of the job using a GET request.

$http.get('http://localhost:8090/jobs/'+id).then(function successCallback(results) { 
    jobResults = results; 
}

The issue I am facing is that I want to assign the variable once the job is completed, and not right at the beginning. Is there a way to achieve this?

If the job is successfully finished, the results will be displayed like this:

{
  "duration": "0.171 secs",
  "classPath": "spark.jobserver.WordCountExample",
  "startTime": "2017-02-17T22:47:49.291Z",
  "context": "c4c62dd3-spark.jobserver.WordCountExample",
  "result": {
    "word1": 1,
    "word2": 3
  },
  "status": "FINISHED",
  "jobId": "994569f9-b6a5-40d3-a4b3-f281276c6716"
}

The only visible difference if the job is not yet completed is that the "result" variable will be absent in the response.

Answer №1

It appears that the issue you are facing stems from looking for a solution in the wrong place. It seems like the processing of your job is happening on the backend, which means that updating it on the frontend requires specific information that you may not have access to. In order to resolve this, you'll need to create a process that monitors the job status and assigns the variable accordingly, particularly when the job is completed. One way to achieve this is by using setInterval.

var jobs = [];
setInterval(function () {
  for (var i = 0; i < jobs.length; i++) {
    checkJobStatus();
  }
});

Answer №2

Kindly attempt accessing the following URL.
Assume you have obtained the jobId from a previous POST request.

$http.get('http://localhost:8090/jobs/:id',{id : jobId}).then(function successCallback(results) { 
    jobResults = results; 
}

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

Contrasting the utilization of jQuery versus angular element references within an angular directive

Recently, I have been exploring ways to integrate jQuery into angular. One method I found was by utilizing the link function. $('#slider').slider(); However, I couldn't help but wonder about the disparity between the above code snippet an ...

Yet another error has been encountered: TypeError undefined is not a function

Hey everyone, I'm currently working on a JavaScript school project where I'm creating a dungeon. It may not be the best code out there, but hey, I'm still learning. I'm encountering an error in the following code: function damageFormu ...

Executing "mounted" in VueJS SSR with Quasar: A step-by-step guide

In accordance with the documentation: Given that there are no dynamic updates, only beforeCreate and created Vue lifecycle hooks will be triggered during SSR. This implies that any code within other lifecycle hooks like beforeMount or mounted will sole ...

What are the steps for transitioning with JavaScript?

My goal is to make both the <hr> elements transition, but I'm struggling with only being able to select the lower <hr> using CSS. html { margin-bottom: 0; height: 100%; min-height: 100%; } body { margin-top: 0; height: 100%; ...

What is the most efficient way to transfer a large volume of documents from mongoDB using http?

I'm dealing with a large mongoDB database that contains millions of documents and I need to fetch them all at once without crashing or encountering cursor errors. My goal is to send this data over http using express in nodeJS. The collection contains ...

Error encountered while rendering HTML template with Django and AngularJS due to TemplateSyntaxError

Hello, I am new to Angular and Django. I have built a Django webpage and am attempting to display values from a basic AngularJS app and controller tutorial using my HTML template. However, I keep encountering an error in the index.html file when trying to ...

Javascript build a list of location classifications

I'm attempting to create a list of categories from an array of objects named places, here is what I have tried: this.places.forEach((p) => { p.categories.forEach((c) => { if(!this.categories.some(c ...

Encountering an error when utilizing Firefox version 35 with protractor

When running my Angular app scenarios with Chrome, everything runs smoothly. However, I encounter a halt when trying to run the scenarios on Firefox version 35.0b6. Any help would be greatly appreciated. Thank you in advance. I am currently using Protract ...

To convert an image file into a string, use JSON.stringify before including it in an AJAX request

Is it possible to send image files contained within JSON objects in an array via an AJAX call using JSON.stringify? When attempting to send the data through an AJAX call, and utilizing JSON.stringify with an array containing JSON objects that have image f ...

What could be the reason behind the absence of this.props.onLayout in my React Native component?

In my React Native app, I have the below class implemented with Typescript: class Component1 extends React.Component<IntroProps, {}> { constructor(props){ super(props) console.log(props.onLayout) } ... } The documentation for the View ...

In Chrome, the $http GET request fails to send the JSESSIONID, but it functions properly on Firefox with AngularJS

Here is the code snippet I am working with: $http({ 'method': 'GET', 'url': 'http://www.example.com', 'withCredentials': true, headers: { 'Content-type': &apo ...

The data from my API is not showing up in my React application

Im working on a project where I am trying to retrieve an image of a recipe card from and display it on my react.js application. However, I am encountering difficulties in getting the API data to show up on the page when running the code. Any assistance wo ...

JavaScript, Page Method, and GridView are essential components to creating dynamic and interactive

After learning how to use the page method in JavaScript and ASP.Net (VB.Net), I encountered an issue when trying to insert multiple items into a database using a gridview. Despite my efforts, there were no error messages appearing. Here is what I have so f ...

Issue encountered with Ionic and ssh2: process.binding is not supported

I am currently delving into the world of Ionic and experimenting with creating a basic application that utilizes SSH2 to establish an ssh connection between the app and a server. Here is a breakdown of the steps I took to encounter the issue: Steps to Rep ...

Triggering a sweet alert on a mouse click

Here is a code snippet I found on . It shows an alert box that doesn't disappear when clicked outside of it. swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, ...

What benefits come with utilizing page objects in Protractor for conducting tests on AngularJS applications?

I've come across two examples demonstrating how to create Page Objects: The initial example showcases the following code snippet: var LoginPage = function() { this.userName = element(by.input('login.userName')); this.password = elem ...

Tips for enabling or disabling elements within an array using React JS

I am looking to develop a feature where I can toggle individual boxes on and off by clicking on them. Currently, only one box at a time can be activated (displayed in green), but I want the ability to control each box independently without affecting the ot ...

Utilizing AngularJs to connect server-generated HTML content to an iframe

My Angular app functions as an HTML editor that transmits the template to a server for rendering with dynamic data. The rendered content is then sent back to the client, where it needs to be placed inside an iframe for preview purposes. It appears that ng- ...

Retrieve the stylesheet based on the presence of a specific class

Is there a way to dynamically add a CSS stylesheet based on the presence of a specific class on a page? For example, instead of checking the time and loading different stylesheets, I want to load different stylesheets depending on the class present in the ...

Disabling the ripple effect on the primary action in React Material lists: A Step-by-Step

I was attempting to include two action buttons at the opposite ends of a list component. https://i.stack.imgur.com/juv8F.gif When clicking on the secondary action (delete icon on the right), the ripple effect is confined to just the icon. On the othe ...