Example #1
0
        public void Start()
        {
            lock (_lock)
            {
                if (_running || _statusManager.IsDestroyed())
                {
                    return;
                }

                _running           = true;
                _cancelTokenSource = new CancellationTokenSource();

                _tasksManager.Start(() =>
                {
                    //Delay first execution until expected time has passed
                    var intervalInMilliseconds = _interval * 1000;
                    _wrappedAdapter.TaskDelay(intervalInMilliseconds).Wait();

                    if (_running)
                    {
                        _tasksManager.Start(() => _worker.ExecuteTasks(_cancelTokenSource.Token), _cancelTokenSource, "Segments Fetcher Worker.");
                        _tasksManager.StartPeriodic(() => AddSegmentsToQueue(), intervalInMilliseconds, _cancelTokenSource, "Segmennnnts Fetcher Add to Queue.");
                    }
                }, _cancelTokenSource, "Main Segments Fetcher.");
            }
        }
Example #2
0
        public bool ConnectAsync(string url)
        {
            if (IsConnected())
            {
                _log.Debug("Event source Client already connected.");
                return(false);
            }

            _firstEvent = true;
            _url        = url;
            _disconnectSignal.Reset();
            _connectedSignal.Reset();
            _cancellationTokenSource = new CancellationTokenSource();

            _tasksManager.Start(() => ConnectAsync(_cancellationTokenSource.Token).Wait(), _cancellationTokenSource, "SSE - ConnectAsync");

            try
            {
                if (!_connectedSignal.Wait(ConnectTimeoutMs))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _log.Debug(ex.Message);
                return(false);
            }

            return(IsConnected());
        }
Example #3
0
        public virtual bool Track(string key, string trafficType, string eventType, double?value = null, Dictionary <string, object> properties = null)
        {
            if (_statusManager.IsDestroyed())
            {
                return(false);
            }

            using (var clock = new Util.SplitStopwatch())
            {
                clock.Start();

                var keyResult             = _keyValidator.IsValid(new Key(key, null), nameof(Track));
                var eventTypeResult       = _eventTypeValidator.IsValid(eventType, nameof(eventType));
                var eventPropertiesResult = _eventPropertiesValidator.IsValid(properties);

                var trafficTypeResult = _blockUntilReadyService.IsSdkReady()
                    ? _trafficTypeValidator.IsValid(trafficType, nameof(trafficType))
                    : new ValidatorResult {
                    Success = true, Value = trafficType
                };

                if (!keyResult || !trafficTypeResult.Success || !eventTypeResult || !eventPropertiesResult.Success)
                {
                    return(false);
                }

                try
                {
                    var eventToLog = new Event
                    {
                        key             = key,
                        trafficTypeName = trafficTypeResult.Value,
                        eventTypeId     = eventType,
                        value           = value,
                        timestamp       = CurrentTimeHelper.CurrentTimeMillis(),
                        properties      = (Dictionary <string, object>)eventPropertiesResult.Value
                    };

                    _tasksManager.Start(() =>
                    {
                        _eventsLog.Log(new WrappedEvent
                        {
                            Event = eventToLog,
                            Size  = eventPropertiesResult.EventSize
                        });
                    }, new CancellationTokenSource(), "Track");

                    RecordLatency(nameof(Track), clock.ElapsedMilliseconds);

                    return(true);
                }
                catch (Exception e)
                {
                    _log.Error("Exception caught trying to track an event", e);
                    RecordException(nameof(Track));
                    return(false);
                }
            }
        }
Example #4
0
        public bool SyncAll(CancellationTokenSource cancellationTokenSource, bool asynchronous = true)
        {
            if (asynchronous)
            {
                _tasksManager.Start(() => SyncAll(), cancellationTokenSource, "SyncAll");
                return(true);
            }

            return(SyncAll());
        }
Example #5
0
        public void Start()
        {
            lock (_lock)
            {
                if (_running)
                {
                    return;
                }

                _running = true;

                _tasksManager.Start(() =>
                {
                    //Delay first execution until expected time has passed
                    var intervalInMilliseconds = _configurationOptions.TelemetryRefreshRate * 1000;
                    _wrapperAdapter.TaskDelay(intervalInMilliseconds).Wait();

                    _tasksManager.StartPeriodic(() => RecordStats(), intervalInMilliseconds, _cancellationTokenSource, "Telemetry Stats.");
                }, _cancellationTokenSource, "Main Telemetry.");
            }
        }
Example #6
0
        public void Start()
        {
            lock (_lock)
            {
                if (_running)
                {
                    return;
                }

                _running = true;
                _tasksManager.Start(() =>
                {
                    _wrapperAdapter.TaskDelay(_firstPushWindow * 1000).Wait();
                    _tasksManager.StartPeriodic(() => SendBulkEvents(), _interval * 1000, _cancellationTokenSource, "Send Bulk Events.");
                }, new CancellationTokenSource(), "Main Events Log.");
            }
        }
Example #7
0
        public void Start()
        {
            lock (_lock)
            {
                try
                {
                    if (_running)
                    {
                        _log.Error("Segments Worker already running.");
                        return;
                    }

                    _log.Debug($"Segments worker starting ...");
                    _cancellationTokenSource = new CancellationTokenSource();
                    _running = true;
                    _tasksManager.Start(() => Execute(), _cancellationTokenSource, "Segments Workers.");
                }
                catch (Exception ex)
                {
                    _log.Error($"Start: {ex.Message}");
                }
            }
        }
Example #8
0
        public void Start()
        {
            _tasksManager.Start(() =>
            {
                try
                {
                    while (!_synchronizer.SyncAll(_shutdownCancellationTokenSource, asynchronous: false))
                    {
                        _wrapperAdapter.TaskDelay(500).Wait();
                    }

                    _statusManager.SetReady();
                    _telemetrySyncTask.RecordConfigInit();
                    _synchronizer.StartPeriodicDataRecording();

                    if (_streamingEnabled)
                    {
                        _log.Debug("Starting streaming mode...");
                        var connected = _pushManager.StartSse().Result;

                        if (connected)
                        {
                            return;
                        }
                    }

                    _log.Debug("Starting polling mode ...");
                    _synchronizer.StartPeriodicFetching();
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.SyncMode, (int)SyncModeEnum.Polling));
                }
                catch (Exception ex)
                {
                    _log.Debug("Exception initialization SDK.", ex);
                }
            }, _shutdownCancellationTokenSource, "SDK Initialization");
        }
Example #9
0
 public void SendBulkEventsTask(List <Event> events)
 {
     _tasksManager.Start(async() => await SendBulkEventsAsync(events), new CancellationTokenSource(), "Send Bulk Events.");
 }