Example #1
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 #2
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 #3
0
        public void Start()
        {
            lock (_lock)
            {
                if (_running || _statusManager.IsDestroyed())
                {
                    return;
                }

                _running           = true;
                _cancelTokenSource = new CancellationTokenSource();

                _taskManager.StartPeriodic(async() =>
                {
                    await FetchSplits(new FetchOptions());
                }, _interval * 1000, _cancelTokenSource, "Splits Fetcher.");
            }
        }