Date: 7th May 2020
This blog post displays a method for writing long running tasks for a web application. It is aimed at long running tasks that are composite of many long repetitive actions. Examples of such are: sending a lot of emails, paying staff salaries etc.
This approach is more comfortable than the usual method of creating a separate server for long running tasks.
The demo here doesn't do anything with the id. Instead it delays for 3 seconds to simulate real life situations.
The demo doesn't show how to get the ids from a database. These you could look up online. In the demo the ids were randomly created and placed in an array.
A real life situation should store the ids that has been worked on. This is necessary in case of any network interruption.
Web workers are needed here because if AJAX requests are made synchronously the page might start hanging. The web workers seems like threading in the browser.
After including Jquery on a page. It was found that Jquery cannot be called from a web worker. So to achieve this opinion I had to use plain JavaScript. Majorly the XMLHttpRequest object.
Synchronous requests were preferred here since the script would be easier to write.
If you have any comments or objections or complaints or contributions please mail us