Ejemplo n.º 1
0
 public void Execute(IQueueProvider queueProvider, QueueMessage message)
 {
     _watch = DateTime.UtcNow;
     _timeout = message.Timeout;
     Provider = queueProvider;
     ExecuteNode(message);
 }
Ejemplo n.º 2
0
 public static QueueMessage FromJsonString(string id, string data)
 {
     var json = JsonValue.Parse(data);
     var m = new QueueMessage(id)
                 {
                     Worker = json["w"].ReadAs<string>(),
                     Timeout = json["t"].ReadAs<int>(),
                     TryNo = json["r"].ReadAs<int>(),
                     ID = id
                 };
     foreach (var item in json["p"])
     {
         m.WithParameter(item.Key, item.Value.ReadAs<string>());
     }
     return m;
 }
Ejemplo n.º 3
0
        public void GeneralTest()
        {
            Print("Started");
            using (var q = new BelzProviderIronMq(Token, ProjectId, Queue))
            {
                var a = new QueueMessage[PreparedMessages];
                for (var i = 0; i < PreparedMessages; i++)
                {
                    a[i] = new QueueMessage("d").WithParameter("m", "Hello " + i);
                }
                q.Enqueue(a);

                Print("Enqueued");

                var stopWatch = new Stopwatch();
                stopWatch.Start();
                using (var belz = new Belz(q))
                {
                    belz.Error += BelzOnError;

                    belz.OperationalThreadsCount = 30;
                    belz.RegisterWorker<Worker>("d");
                    belz.Run();
                    while (q.AvailableMessages > 0)
                    {
                        Thread.Sleep(500);
                    }

                    belz.Error -= BelzOnError;
                }
                stopWatch.Stop();

                var ts = stopWatch.Elapsed;
                var elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours, ts.Minutes, ts.Seconds,
                    ts.Milliseconds / 10);
                Print("RunTime " + elapsedTime);
                Print("Requests to IronMq made " + q.NumberOfRequestsMade);
            }
            Print("Ended");
        }
Ejemplo n.º 4
0
 private static void ExecuteAsync(INotificationProvider notifications, Type workerType, QueueMessage message, IQueueProvider provider)
 {
     BeltzWorker worker = null;
     var success = false;
     try
     {
         worker = (BeltzWorker)Activator.CreateInstance(workerType);
         worker.Execute(provider, message);
         success = true;
     }
     catch (Exception e)
     {
         notifications.OnError("Error executing worker", e);
         success = false;
     }
     finally
     {
         if (worker != null)
             worker.Dispose();
         notifications.OnWorkerEnded(message, success);
     }
 }
Ejemplo n.º 5
0
 public static void Execute(INotificationProvider notifications, Type workerType, QueueMessage message, IQueueProvider provider)
 {
     notifications.OnWorkerStarted(message);
     new Thread(x => ExecuteAsync(notifications, workerType, message, provider)).Start();
 }
Ejemplo n.º 6
0
 protected abstract void ExecuteNode(QueueMessage message);
Ejemplo n.º 7
0
 protected override void ExecuteNode(QueueMessage message)
 {
     var s = message.Parameters["m"];
     Thread.CurrentThread.Name = "Worker " + s;
     Print("Launched - " + s);
     Print("Status - " + s + " = " + TimeoutLeft());
     Thread.Sleep(TimeoutLeft(1000));
     if (TimeHasPassed)
     {
         Print("Aborted - " + s);
         throw new Exception("Failed try " + s);
     }
     Print("Ended - " + s);
 }