public void AddLine(ConsoleId consoleId, ConsoleLine line)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            if (line.IsReference)
            {
                throw new ArgumentException("Cannot add reference directly", nameof(line));
            }

            using (var tran = _connection.CreateWriteTransaction())
            {
                // check if encoded message fits into Set's Value field

                string value;

                if (line.Message.Length > ValueFieldLimit - 36)
                {
                    // pretty sure it won't fit
                    // (36 is an upper bound for JSON formatting, TimeOffset and TextColor)
                    value = null;
                }
                else
                {
                    // try to encode and see if it fits
                    value = JobHelper.ToJson(line);

                    if (value.Length > ValueFieldLimit)
                    {
                        value = null;
                    }
                }

                if (value == null)
                {
                    var referenceKey = Guid.NewGuid().ToString("N");

                    tran.SetRangeInHash(consoleId.ToString(), new[] { new KeyValuePair <string, string>(referenceKey, line.Message) });

                    line.Message     = referenceKey;
                    line.IsReference = true;

                    value = JobHelper.ToJson(line);
                }

                tran.AddToSet(consoleId.ToString(), value);

                tran.Commit();
            }
        }
Beispiel #2
0
        public void AddTag(string jobid, string tag)
        {
            using (var tran = _connection.CreateWriteTransaction())
            {
                if (!(tran is JobStorageTransaction))
                {
                    throw new NotSupportedException(" Storage transactions must impelement JobStorageTransaction");
                }

                var cleanTag = tag.Clean();

                tran.AddToSet("tags", cleanTag);
                tran.AddToSet(jobid.GetSetKey(), cleanTag);
                tran.AddToSet(cleanTag.GetSetKey(), jobid);
                tran.Commit();
            }
        }
        public void InitConsole(ConsoleId consoleId)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            // We add an extra "jobId" record into Hash for console,
            // to correctly track TTL even if console contains no lines

            using (var transaction = _connection.CreateWriteTransaction())
            {
                if (!(transaction is JobStorageTransaction))
                {
                    throw new NotSupportedException("Storage tranactions must implement JobStorageTransaction");
                }

                transaction.SetRangeInHash(consoleId.GetHashKey(), new[] { new KeyValuePair <string, string>("jobId", consoleId.JobId) });

                transaction.Commit();
            }
        }
 public static JobStorageTransaction CreateJobStorageTransaction(this JobStorageConnection jobStorageConnection)
 => (JobStorageTransaction)jobStorageConnection.CreateWriteTransaction();
Beispiel #5
0
 public override IWriteOnlyTransaction CreateWriteTransaction()
 {
     return(_postgreSqlConnection.CreateWriteTransaction());
 }
Beispiel #6
0
 public override IWriteOnlyTransaction CreateWriteTransaction()
 {
     return(_sqlServerConnection.CreateWriteTransaction());
 }