Ejemplo n.º 1
0
        public override List <string> GetFirstByLowestScoreFromSet(string key, double fromScore, double toScore, int count)
        {
            if (!_queues.Any())
            {
                return(new List <string>());
            }

            var ids = _sqlServerConnection.GetFirstByLowestScoreFromSet(key, fromScore, toScore, count);

            if (_queues == null)
            {
                return(ids);
            }

            return(ids.Where(id =>
            {
                string?recurringJobId = key switch
                {
                    "recurring-jobs" => id,
                    "schedule" => _sqlServerConnection.GetJobParameter(id, "RecurringJobId")?.Replace("\"", ""),
                    _ => throw new InvalidOperationException($"{key} is not a recognized job type")
                };

                string queue = recurringJobId switch
                {
                    null => "default",
                    _ => _sqlServerConnection.GetValueFromHash($"recurring-job:{recurringJobId}", "Queue") ?? "default"
                };

                return _queues.Contains(queue);
            })
                   .ToList());
        }
Ejemplo n.º 2
0
        public IEnumerable <ConsoleLine> GetLines(ConsoleId consoleId, int start, int end)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            var useOldKeys = false;
            var items      = _connection.GetRangeFromSet(consoleId.GetSetKey(), start, end);

            if (items == null || items.Count == 0)
            {
                // Read operations should be backwards compatible and use
                // old keys, if new one don't contain any data.
                items      = _connection.GetRangeFromSet(consoleId.GetOldConsoleKey(), start, end);
                useOldKeys = true;
            }

            foreach (var item in items)
            {
                var line = JobHelper.FromJson <ConsoleLine>(item);

                if (line.IsReference)
                {
                    if (useOldKeys)
                    {
                        try
                        {
                            line.Message = _connection.GetValueFromHash(consoleId.GetOldConsoleKey(), line.Message);
                        }
                        catch
                        {
                            // This may happen, when using Hangfire.Redis storage and having
                            // background job, whose console session was stored using old key
                            // format.
                        }
                    }
                    else
                    {
                        line.Message = _connection.GetValueFromHash(consoleId.GetHashKey(), line.Message);
                    }

                    line.IsReference = false;
                }

                yield return(line);
            }
        }
Ejemplo n.º 3
0
        public override string GetFirstByLowestScoreFromSet(string key, double fromScore, double toScore)
        {
            if (!_queues.Any())
            {
                return(null);
            }

            var id = _postgreSqlConnection.GetFirstByLowestScoreFromSet(key, fromScore, toScore);

            if (_queues == null || id == null)
            {
                return(id);
            }

            var recurringJobId = key switch
            {
                "recurring-jobs" => id,
                "schedule" => _postgreSqlConnection.GetJobParameter(id, "RecurringJobId")?.Replace("\"", ""),
                _ => throw new InvalidOperationException($"{key} is not a recognized job type")
            };

            var queue = recurringJobId switch
            {
                null => "default",
                _ => _postgreSqlConnection.GetValueFromHash($"recurring-job:{recurringJobId}", "Queue") ?? "default"
            };

            return(_queues.Contains(queue) ? id : null);

            // return id.Where(id =>
            //     {
            //         string? recurringJobId = key switch
            //         {
            //             "recurring-jobs" => id,
            //             "schedule" => _postgreSqlConnection.GetJobParameter(id, "RecurringJobId")?.Replace("\"", ""),
            //             _ => throw new InvalidOperationException($"{key} is not a recognized job type")
            //         };
            //
            //         string queue = recurringJobId switch
            //         {
            //             null => "default",
            //             _ => _postgreSqlConnection.GetValueFromHash($"recurring-job:{recurringJobId}", "Queue") ?? "default"
            //         };
            //
            //         return _queues.Contains(queue);
            //     }).SingleOrDefault<string>();
            //return _postgreSqlConnection.GetFirstByLowestScoreFromSet(key, fromScore, toScore);
        }
Ejemplo n.º 4
0
        public IEnumerable <ConsoleLine> GetLines(ConsoleId consoleId, int start, int end)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            foreach (var item in _connection.GetRangeFromSet(consoleId.ToString(), start, end))
            {
                var line = JobHelper.FromJson <ConsoleLine>(item);

                if (line.IsReference)
                {
                    line.Message     = _connection.GetValueFromHash(consoleId.ToString(), line.Message);
                    line.IsReference = false;
                }

                yield return(line);
            }
        }