public IList <ExternalTask> FetchAndLockTasks(string workerId, int maxTasks, IEnumerable <string> topicNames, long lockDurationInMilliseconds, IEnumerable <string> variablesToFetch = null) { var lockRequest = new FetchAndLockRequest { WorkerId = workerId, MaxTasks = maxTasks }; //if (longPolling) //{ // lockRequest.AsyncResponseTimeout = 1 * 60 * 1000; // 1 minute //} foreach (var topicName in topicNames) { var lockTopic = new FetchAndLockTopic { TopicName = topicName, LockDuration = lockDurationInMilliseconds, Variables = variablesToFetch }; lockRequest.Topics.Add(lockTopic); } return(FetchAndLockTasks(lockRequest)); }
public IList <ExternalTask> FetchAndLockTasks(string workerId, int maxTasks, string topicName, long lockDurationInMilliseconds, List <string> variablesToFetch) { HttpClient http = helper.HttpClient("external-task/fetchAndLock"); FetchAndLockRequest request = new FetchAndLockRequest(); request.workerId = workerId; request.maxTasks = maxTasks; FetchAndLockTopic topic = new FetchAndLockTopic(); topic.topicName = topicName; topic.lockDuration = lockDurationInMilliseconds; topic.variables = variablesToFetch; request.topics.Add(topic); try { HttpResponseMessage response = http.PostAsJsonAsync("", request).Result; if (response.IsSuccessStatusCode) { var tasks = response.Content.ReadAsAsync <IEnumerable <ExternalTask> >().Result; http.Dispose(); return(new List <ExternalTask>(tasks)); } else { return(new List <ExternalTask>()); } } catch (Exception ex) { http.Dispose(); // TODO: Handle Exception, add backoff return(new List <ExternalTask>()); } }
public IList <ExternalTask> FetchAndLockTasks(string workerId, int maxTasks, string topicName, long lockDurationInMilliseconds, IEnumerable <string> variablesToFetch) { var lockRequest = new FetchAndLockRequest { WorkerId = workerId, MaxTasks = maxTasks }; var lockTopic = new FetchAndLockTopic { TopicName = topicName, LockDuration = lockDurationInMilliseconds, Variables = variablesToFetch }; lockRequest.Topics.Add(lockTopic); return(FetchAndLockTasks(lockRequest)); }
public IList <ExternalTask> FetchAndLockTasks(string workerId, int maxTasks, IEnumerable <string> topicNames, long lockDurationInMilliseconds, IEnumerable <string> variablesToFetch = null) { var fetchAndLockRequest = new FetchAndLockRequest { WorkerId = workerId, MaxTasks = maxTasks }; var fetchAndLockHttpRequest = new HttpClientRequest <FetchAndLockRequest>("external-task/fetchAndLock", fetchAndLockRequest); foreach (var topicName in topicNames) { var lockTopic = new FetchAndLockTopic { TopicName = topicName, LockDuration = lockDurationInMilliseconds, Variables = variablesToFetch?.ToList() }; fetchAndLockRequest.Topics.Add(lockTopic); } return(_httpClientService.PostAsync <FetchAndLockRequest, IList <ExternalTask> >(fetchAndLockHttpRequest)); }