angularjs background process for sending data from db and deleting this data from db

209 views Asked by At

I want to implement a background process in angularjs which checks up if there is data in a table of a sqlite database is data stored.

If so it should send the data (I have implemented the sending function) remove the data from the table and then check again if there is more data in the table.

If there is no data in the table stored it should trigger itself in a delay of 30 seconds again to check if there is some data stored.

If there is data inserted while in delay of 30 seconds then it should not wait the remaining 30 seconds and just starting to process the data again.

I tried it on myself but I could not get a better solution like here (which is in my opinion not a good solution because it always triggers the function in 30 seconds):

$interval(function() {

var promise1 = DbService.getOutbox();

$q.all([promise1]).then(function (res) {

  if(res[0].rows.length > 0) {

      var promiseSendData = WebService.sendData(data);

      $q.all([promiseSendMessage]).then(function (result) {

        DbService.removeOutboxEntry(result[0].id);

      });
  }
});

},30000);

How can I implement my specific workflow?

0

There are 0 answers