public IList <ExternalTask> FetchAndLockTasks(FetchAndLockRequest fetchAndLockRequest)
        {
            var http = helper.HttpClient("external-task/fetchAndLock");

            try
            {
                var requestContent = new StringContent(JsonConvert.SerializeObject(fetchAndLockRequest), Encoding.UTF8, CamundaClientHelper.CONTENT_TYPE_JSON);
                var response       = http.PostAsync("", requestContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    var tasks = JsonConvert.DeserializeObject <IEnumerable <ExternalTask> >(response.Content.ReadAsStringAsync().Result);

                    http.Dispose();
                    return(new List <ExternalTask>(tasks));
                }
                else
                {
                    http.Dispose();
                    throw new EngineException("Could not fetch and lock tasks: " + response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                http.Dispose();
                Console.WriteLine(ex.Message);
                // TODO: Handle Exception, add back off
                return(new List <ExternalTask>());
            }
        }
Beispiel #2
0
        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>());
            }
        }
Beispiel #3
0
        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));
        }
        private async Task <List <ExternalTask> > PerformSelection(
            FetchAndLockRequest request,
            CancellationToken cancellationToken
            )
        {
            var externalTasks = await _client.FetchAndLockAsync(request, cancellationToken);

            return(externalTasks);
        }
        private async Task <IEnumerable <ExternalTask> > PerformSelection(
            IExternalTaskClient client,
            FetchAndLockRequest request,
            CancellationToken cancellationToken
            )
        {
            var externalTasks = await client.FetchAndLockAsync(request, cancellationToken);

            return(externalTasks);
        }
        private FetchAndLockRequest MakeRequestBody(IEnumerable <FetchAndLockRequest.Topic> topics)
        {
            var fetchAndLockRequest = new FetchAndLockRequest(_options.WorkerId)
            {
                UsePriority          = true,
                AsyncResponseTimeout = _options.AsyncResponseTimeout,
                Topics = topics
            };

            return(fetchAndLockRequest);
        }
        private FetchAndLockRequest MakeRequestBody()
        {
            var topics = _topicsProvider.GetTopics();

            var fetchAndLockRequest = new FetchAndLockRequest(_options.WorkerId)
            {
                UsePriority          = true,
                AsyncResponseTimeout = _options.AsyncResponseTimeout,
                Topics = topics
            };

            return(fetchAndLockRequest);
        }
        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 async Task <IEnumerable <ExternalTask <TPayload> > > FetchAndLockExternalTasks <TPayload>(IIdentity identity, string workerId, string topicName, int maxTasks, int longPollingTimeout, int lockDuration) where TPayload : new()
        {
            var uri     = "fetch_and_lock";
            var request = new FetchAndLockRequest
                          (
                workerId,
                topicName,
                maxTasks,
                longPollingTimeout,
                lockDuration
                          );

            var response = await this.SendPostToExternalTaskApi <FetchAndLockRequest, IEnumerable <ExternalTask <TPayload> > >
                           (
                identity,
                uri,
                request
                           );

            return(response);
        }
Beispiel #10
0
        public async Task <IEnumerable <ExternalTask <TPayload> > > FetchAndLockExternalTasks <TPayload>(IIdentity identity, string workerId, string topicName, int maxTasks, int longPollingTimeout, int lockDuration) where TPayload : new()
        {
            var endpoint = RestSettings.Paths.FetchAndLockExternalTasks;
            var url      = this.ApplyBaseUrl(endpoint);

            var fetchAndLockRequest = new FetchAndLockRequest
                                      (
                workerId,
                topicName,
                maxTasks,
                longPollingTimeout,
                lockDuration
                                      );

            var jsonPayload    = SerializeForProcessEngine(fetchAndLockRequest);
            var requestContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");

            var result = await this.SendRequestAndExpectResult <IEnumerable <ExternalTask <TPayload> > >(identity, HttpMethod.Post, url, requestContent);

            return(result);
        }
        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));
        }