示例#1
0
        public void Process(string firstLine, NetworkStream stream, ILogger logger)
        {
            try
            {
                var parts = firstLine.Split(' ');
                if (parts.Length == 2 && parts[0] == "OK")
                {
                    var bytes  = Convert.ToInt32(parts[1]) + 2; // Get the last CRLF
                    var buffer = new byte[bytes];
                    stream.Read(buffer, 0, bytes);
                    var tubes = YamlHelper.ParseList(buffer);
                    _tcs.SetResult(tubes);
                    return;
                }
            }
            catch
            {
            }

            Reply.SetGeneralException(_tcs, firstLine, "list-tubes", logger);
        }
        public void Process(string firstLine, NetworkStream stream, ILogger logger)
        {
            var parts = firstLine.Split(new[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);

            switch (parts[0])
            {
            case "OK":
                try
                {
                    var bytes  = Convert.ToInt32(parts[1]);
                    var buffer = new byte[bytes];
                    stream.Read(buffer, 0, bytes);
                    stream.ReadByte();     // CR
                    stream.ReadByte();     // LF

                    var yaml   = YamlHelper.ParseDictionary(buffer);
                    var result = new Statistics();
                    foreach (var pair in yaml)
                    {
                        switch (pair.Key)
                        {
                        case "current-jobs-urgent": result.CurrentJobsUrgent = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-ready": result.CurrentJobsReady = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-reserved": result.CurrentJobsReserved = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-delayed": result.CurrentJobsDelayed = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-buried": result.CurrentJobsBuried = Convert.ToInt32(pair.Value); break;

                        case "cmd-put": result.PutCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-peek": result.PeekCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-peek-ready": result.PeekReadyCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-peek-delayed": result.PeekDelayedCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-peek-buried": result.PeekBuriedCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-reserve": result.ReserveCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-reserve-with-timeout": result.ReserveWithTimeoutCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-use": result.UseCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-watch": result.WatchCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-ignore": result.IgnoreCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-delete": result.DeleteCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-release": result.ReleaseCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-bury": result.BuryCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-kick": result.KickCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-touch": result.TouchCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-stats": result.StatsCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-stats-job": result.StatsJobCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-stats-tube": result.StatsTubeCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-list-tubes": result.ListTubesCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-list-tube-used": result.ListTubeUsedCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-list-tubes-watched": result.ListTubesWatchedCommandCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-pause-tube": result.PauseTubeCommandCount = Convert.ToInt32(pair.Value); break;

                        case "job-timeouts": result.JobTimeoutCount = Convert.ToInt32(pair.Value); break;

                        case "total-jobs": result.TotalJobCount = Convert.ToInt32(pair.Value); break;

                        case "max-job-size": result.MaxJobSize = Convert.ToInt32(pair.Value); break;

                        case "current-tubes": result.CurrentTubes = Convert.ToInt32(pair.Value); break;

                        case "current-connections": result.CurrentConnections = Convert.ToInt32(pair.Value); break;

                        case "current-producers": result.CurrentProducers = Convert.ToInt32(pair.Value); break;

                        case "current-workers": result.CurrentWorkers = Convert.ToInt32(pair.Value); break;

                        case "current-waiting": result.CurrentWaiting = Convert.ToInt32(pair.Value); break;

                        case "total-connections": result.TotalConnectionCount = Convert.ToInt32(pair.Value); break;

                        case "pid": result.ProcessID = Convert.ToInt32(pair.Value); break;

                        case "uptime": result.Uptime = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;

                        case "binlog-oldest-index": result.BinlogOldestIndex = Convert.ToInt32(pair.Value); break;

                        case "binlog-current-index": result.BinlogCurrentIndex = Convert.ToInt32(pair.Value); break;

                        case "binlog-max-size": result.BinlogMaxSize = Convert.ToInt32(pair.Value); break;

                        case "binlog-records-written": result.BinlogRecordsWritten = Convert.ToInt32(pair.Value); break;

                        case "binlog-records-migrated": result.BinlogRecordsMigrated = Convert.ToInt32(pair.Value); break;

                        case "rusage-utime": result.RusageUtime = Convert.ToDecimal(pair.Value); break;

                        case "rusage-stime": result.RusageStime = Convert.ToDecimal(pair.Value); break;

                        case "id": result.Id = pair.Value; break;

                        case "hostname": result.Hostname = pair.Value; break;

                        case "version": result.Version = pair.Value; break;
                        }
                    }
                    _tcs.SetResult(result);
                    return;
                }
                catch (Exception ex)
                {
                    logger?.LogError(0, ex, "Unhandled exception while processing {Request}", GetType().Name);
                    _tcs.SetException(ex);
                    return;
                }

            default:
                Reply.SetGeneralException(_tcs, firstLine, "stats", logger);
                return;
            }
        }
        public void Process(string firstLine, NetworkStream stream, ILogger logger)
        {
            var parts = firstLine.Split(new[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);

            switch (parts[0])
            {
            case "OK":
                try
                {
                    var bytes  = Convert.ToInt32(parts[1]);
                    var buffer = new byte[bytes];
                    stream.Read(buffer, 0, bytes);
                    stream.ReadByte();     // CR
                    stream.ReadByte();     // LF

                    var yaml   = YamlHelper.ParseDictionary(buffer);
                    var result = new TubeStatistics();
                    foreach (var pair in yaml)
                    {
                        switch (pair.Key)
                        {
                        case "name": result.Name = pair.Value; break;

                        case "total-jobs": result.TotalJobs = Convert.ToInt32(pair.Value); break;

                        case "current-using": result.CurrentUsing = Convert.ToInt32(pair.Value); break;

                        case "current-waiting": result.CurrentWaiting = Convert.ToInt32(pair.Value); break;

                        case "current-watching": result.CurrentWatching = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-ready": result.CurrentJobsReady = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-buried": result.CurrentJobsBuried = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-urgent": result.CurrentJobsUrgent = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-delayed": result.CurrentJobsDelayed = Convert.ToInt32(pair.Value); break;

                        case "current-jobs-reserved": result.CurrentJobsReserved = Convert.ToInt32(pair.Value); break;

                        case "cmd-delete": result.DeleteCount = Convert.ToInt32(pair.Value); break;

                        case "cmd-pause-tube": result.PauseCount = Convert.ToInt32(pair.Value); break;

                        case "pause": result.Pause = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;

                        case "pause-time-left": result.PauseTimeLeft = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;
                        }
                    }
                    _tcs.SetResult(result);
                    return;
                }
                catch (Exception ex)
                {
                    _tcs.SetException(ex);
                    return;
                }

            case "NOT_FOUND":
                _tcs.SetResult(null);
                return;

            default:
                Reply.SetGeneralException(_tcs, firstLine, "stats-tube", logger);
                return;
            }
        }
示例#4
0
        public void Process(string firstLine, NetworkStream stream, ILogger logger)
        {
            var parts = firstLine.Split(new[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);

            switch (parts[0])
            {
            case "OK":
                try
                {
                    var bytes  = Convert.ToInt32(parts[1]);
                    var buffer = new byte[bytes];
                    stream.Read(buffer, 0, bytes);
                    stream.ReadByte();     // CR
                    stream.ReadByte();     // LF

                    var yaml   = YamlHelper.ParseDictionary(buffer);
                    var result = new JobStatistics();
                    foreach (var pair in yaml)
                    {
                        switch (pair.Key)
                        {
                        case "tube": result.Tube = pair.Value; break;

                        case "id": result.Id = Convert.ToInt32(pair.Value); break;

                        case "pri": result.Priority = Convert.ToInt32(pair.Value); break;

                        case "file": result.File = Convert.ToInt32(pair.Value); break;

                        case "kicks": result.Kicks = Convert.ToInt32(pair.Value); break;

                        case "buries": result.Buries = Convert.ToInt32(pair.Value); break;

                        case "reserves": result.Reserves = Convert.ToInt32(pair.Value); break;

                        case "releases": result.Releases = Convert.ToInt32(pair.Value); break;

                        case "timeouts": result.Timeouts = Convert.ToInt32(pair.Value); break;

                        case "age": result.Age = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;

                        case "ttr": result.TimeToRun = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;

                        case "time-left": result.TimeLeft = TimeSpan.FromSeconds(Convert.ToInt32(pair.Value)); break;

                        case "state": result.State = (JobState)Enum.Parse(typeof(JobState), pair.Value, true); break;
                        }
                    }
                    _tcs.SetResult(result);
                    return;
                }
                catch (Exception ex)
                {
                    _tcs.SetException(ex);
                    return;
                }

            case "NOT_FOUND":
                _tcs.SetResult(null);
                return;

            default:
                Reply.SetGeneralException(_tcs, firstLine, "stats-job", logger);
                return;
            }
        }