Пример #1
0
        public static async Task <string> WriteRecordAsync(IApiClient apiClient, Schema schema, Record record,
                                                           IServerStreamWriter <RecordAck> responseStream)
        {
            // debug
            Logger.Debug($"Starting timer for {record.RecordId}");
            var timer = Stopwatch.StartNew();

            try
            {
                var endpoint = EndpointHelper.GetEndpointForSchema(schema);

                if (endpoint == null)
                {
                    throw new Exception($"Endpoint {schema.Id} does not exist");
                }

                // debug
                Logger.Debug(JsonConvert.SerializeObject(record, Formatting.Indented));

                // semaphore
                await WriteSemaphoreSlim.WaitAsync();

                // write records
                var errorMessage = await endpoint.WriteRecordAsync(apiClient, schema, record, responseStream);

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    Logger.Error(new Exception(errorMessage), errorMessage);
                }

                timer.Stop();
                Logger.Debug($"Acknowledged Record {record.RecordId} time: {timer.ElapsedMilliseconds}");

                return("");
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Error writing record {e.Message}");
                // send ack
                var ack = new RecordAck
                {
                    CorrelationId = record.CorrelationId,
                    Error         = e.Message
                };
                await responseStream.WriteAsync(ack);

                timer.Stop();
                Logger.Debug($"Failed Record {record.RecordId} time: {timer.ElapsedMilliseconds}");

                return(e.Message);
            }
            finally
            {
                WriteSemaphoreSlim.Release();
            }
        }
Пример #2
0
        public static async IAsyncEnumerable <Schema> GetRefreshSchemas(IApiClientFactory factory, Settings settings,
                                                                        RepeatedField <Schema> refreshSchemas, int sampleSize = 5)
        {
            foreach (var schema in refreshSchemas)
            {
                var endpoint = EndpointHelper.GetEndpointForSchema(schema);

                var refreshSchema = await GetSchemaForEndpoint(factory, settings, schema, endpoint);

                // get sample and count
                yield return(await AddSampleAndCount(factory, settings, refreshSchema, sampleSize, endpoint));
            }
        }
Пример #3
0
        public static async IAsyncEnumerable <Record> ReadRecordsAsync(IApiClient apiClient, Schema schema)
        {
            var endpoint = EndpointHelper.GetEndpointForSchema(schema);

            var records = endpoint?.ReadRecordsAsync(apiClient, schema);

            if (records != null)
            {
                await foreach (var record in records)
                {
                    yield return(record);
                }
            }
        }
Пример #4
0
        public static async IAsyncEnumerable <Record> ReadRecordsAsync(IApiClientFactory factory, Settings settings, Schema schema, DateTime?lastReadTime = null, TaskCompletionSource <DateTime>?tcs = null)
        {
            var endpoint = EndpointHelper.GetEndpointForSchema(schema);

            var records = endpoint?.ReadRecordsAsync(factory, settings, lastReadTime, tcs);

            if (records != null)
            {
                await foreach (var record in records)
                {
                    yield return(record);
                }
            }
        }