dimanche 10 mai 2015

Is it good to call Thread.Sleep during polling Google Big Query results in ASP.NET? Alternatives?

I am using ASP.NET MVC 5 which gets data from Google Big Query. Due to the way Google Big Query is designed, I need to poll for results if job is not finished. Here is my code,

       var qr = new QueryRequest
        {
            Query = string.Format(myQuery, param1, param2)
        };// all params are mine
        var jobs = _bigqueryService.Jobs;
        var response = await jobs.Query(qr, _settings.GoogleCloudServiceProjectId).ExecuteAsync();
        var jobId = response.JobReference.JobId;
        var isCompleted = response.JobComplete == true;
        IList<TableRow> rows = response.Rows;
        while (!isCompleted)
        {
            var r = await jobs.GetQueryResults(_settings.GoogleCloudServiceProjectId, jobId).ExecuteAsync();
            isCompleted = r.JobComplete == true;
            if (!isCompleted)
            {
                Thread.Sleep(100);
            }
            else
            {
                rows = r.Rows;
            }
        }

Looking at this code can someone tell me whether its good to call Thread.Sleep inside this context or I should continuously burn CPU cycles.

Aucun commentaire:

Enregistrer un commentaire