示例#1
0
        /// <summary>
        /// Invokes events will be occurred during the service start.
        /// </summary>
        protected override void ServiceStart()
        {
            if (!this.firstInit)
            {
                return;
            }

            this.firstInit = false;

            if (this.Configuration != null)
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(this.Configuration.Culture);
            }

            this.Log.Write(LogLevel.Info, "Tasslehoff 0.9.7  (c) 2008-2016 Eser Ozvataf ([email protected]). All rights reserved.");
            this.Log.Write(LogLevel.Info, "This program is free software under the terms of the GPL v3 or later.");
            this.Log.Write(LogLevel.Info, string.Empty);

            if (this.Configuration != null)
            {
                if (!string.IsNullOrEmpty(this.Configuration.DatabaseConnectionString))
                {
                    this.DatabaseManager.Connections.Add(
                        this.DatabaseManager.DefaultDatabaseKey,
                        new DatabaseManagerConnection()
                        {
                            ProviderName = this.Configuration.DatabaseProviderName,
                            ConnectionString = this.Configuration.DatabaseConnectionString,
                        }
                    );
                }

                // search for extensions
                if (this.Configuration.ExtensionPaths != null)
                {
                    this.ExtensionFinder.SearchStructured(this.Configuration.ExtensionPaths);
                }
            }

            this.Log.Write(LogLevel.Info, string.Format("{0} extensions found:", this.ExtensionFinder.Assemblies.Count));
            foreach (string assemblyName in this.ExtensionFinder.Assemblies.Keys)
            {
                this.Log.Write(LogLevel.Info, string.Format("- {0}", assemblyName));
            }
            this.Log.Write(LogLevel.Info, string.Empty);

            if (this.Configuration != null)
            {
                if (!string.IsNullOrEmpty(this.Configuration.RabbitMQAddress))
                {
                    IQueueManager rabbitMq = new RabbitMQConnection(this.Configuration.RabbitMQAddress);
                    this.AddChild(rabbitMq);
                }

                if (!string.IsNullOrEmpty(this.Configuration.IronMQProjectId))
                {
                    IQueueManager ironMq = new IronMQConnection(this.Configuration.IronMQProjectId, this.Configuration.IronMQToken);
                    this.AddChild(ironMq);
                }

                if (!string.IsNullOrEmpty(this.Configuration.MemcachedAddress))
                {
                    ICacheManager memcached = new MemcachedConnection(this.Configuration.MemcachedAddress);
                    this.AddChild(memcached);
                }

                if (!string.IsNullOrEmpty(this.Configuration.RedisAddress))
                {
                    ICacheManager redis = new RedisConnection(this.Configuration.RedisAddress);
                    this.AddChild(redis);
                }

                if (!string.IsNullOrEmpty(this.Configuration.ElasticSearchAddress))
                {
                    ICacheManager elasticSearch = new ElasticSearchConnection(new Uri(this.Configuration.ElasticSearchAddress));
                    this.AddChild(elasticSearch);
                }
            }
        }
示例#2
0
 public WakeDownloader(RabbitMQConnection rabbitMQ)
 {
     _rabbitMQ = rabbitMQ;
 }
 protected CommandHandlerBase(RabbitMQConnection connection, RabbitMQOptions mqOptions)
 {
     _connection = connection;
     _mqOptions  = mqOptions;
 }
        static void Main(string[] args)
        {
            RabbitMQExtraQueueProcess QueueExtraProcess = RabbitMQExtraQueueProcess.createAsSingleton();

            Console.WriteLine("Sms Consumer");
            var rabbitMQService = new RabbitMQConnection();

            string mongodbMessage = "";

            using (var connection = rabbitMQService.GetRabbitMQConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            string   message  = Encoding.UTF8.GetString(ea.Body);
                            SmsModel smsModel = JsonConvert.DeserializeObject <SmsModel>(message);

                            string phones = ListofString(smsModel.Phones);

                            mongodbMessage = "Phones : " + phones;

                            string responseResult = "";

                            SmsProcess smsProcess = SmsProcess.createAsSingleton();
                            responseResult = smsProcess.SmsSend(smsModel);

                            channel.BasicAck(ea.DeliveryTag, false);

                            mongodbMessage += " Sms Api Result : " + responseResult + " - Sms Gönderildi ve Queue'den kaldırıldı.";
                        }
                        catch (Exception ex) //Email Consumer ile aynı yol izleniyor.
                        {
                            currentRetryCount = QueueExtraProcess.GetRetryAttempts(ea.BasicProperties);

                            mongodbMessage += " - RetryCount : " + currentRetryCount + " - Hata : " + ex.ToString();

                            if (currentRetryCount < RabbitMQModel.RetryCount)
                            {
                                currentRetryCount++;

                                var properties = channel.CreateBasicProperties();
                                properties.Headers = QueueExtraProcess.CopyMessageHeaders(ea.BasicProperties.Headers);
                                QueueExtraProcess.SetRetryAttempts(properties, currentRetryCount);
                                channel.BasicPublish(ea.Exchange, ea.RoutingKey, properties, ea.Body);
                                channel.BasicAck(ea.DeliveryTag, false);
                            }
                            else
                            {
                                channel.BasicReject(ea.DeliveryTag, false);
                                mongodbMessage += currentRetryCount + " - Email Queue' den silindi";
                            }
                        }
                    };

                    channel.BasicConsume("SmsQueue", false, consumer);

                    Console.ReadLine();
                }
            }
        }
示例#5
0
 public CreateBoxTokenTask(RabbitMQConnection rabbitMQ, BoxAPI box, ILogger <CreateBoxTokenTask> logger)
     : base(rabbitMQ, TaskType.CreateBoxToken, logger)
 {
     _box = box;
 }
示例#6
0
 public GenerateVTTFileTask(RabbitMQConnection rabbitMQ,
                            ILogger <GenerateVTTFileTask> logger)
     : base(rabbitMQ, TaskType.GenerateVTTFile, logger)
 {
 }
示例#7
0
 public ProcessVideoTask(RabbitMQConnection rabbitMQ, RpcClient rpcClient, ILogger <ProcessVideoTask> logger)
     : base(rabbitMQ, TaskType.ProcessVideo, logger)
 {
     _rpcClient = rpcClient;
 }
 public RabbitMQExamplesService(RabbitMQConnection connection)
 {
     _rabbitMQConnection = connection;
 }
        static void Main(string[] args)
        {
            RabbitMQExtraQueueProcess QueueExtraProcess = RabbitMQExtraQueueProcess.createAsSingleton();

            Console.WriteLine("Mail Consumer");
            var rabbitMQService = new RabbitMQConnection();

            string mongodbMessage = "";

            using (var connection = rabbitMQService.GetRabbitMQConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        mongodbMessage = "";
                        EmailModel emailModel = new EmailModel();

                        try
                        {
                            string message = Encoding.UTF8.GetString(ea.Body);
                            emailModel = JsonConvert.DeserializeObject <EmailModel>(message);

                            string responseResult = "";

                            MailProcess mailProcess = MailProcess.createAsSingleton();
                            responseResult = mailProcess.MailSend(emailModel);

                            channel.BasicAck(ea.DeliveryTag, false);

                            mongodbMessage += " Mail Api Result : " + responseResult + " - Mail Gönderildi ve Queue'den kaldırıldı.";
                        }
                        catch (Exception ex)
                        {
                            currentRetryCount = QueueExtraProcess.GetRetryAttempts(ea.BasicProperties);

                            mongodbMessage += " - RetryCount : " + currentRetryCount + " - Hata : " + ex.ToString();

                            if (currentRetryCount < RabbitMQModel.RetryCount)
                            {
                                currentRetryCount++;

                                var properties = channel.CreateBasicProperties();
                                properties.Headers = QueueExtraProcess.CopyMessageHeaders(ea.BasicProperties.Headers);
                                QueueExtraProcess.SetRetryAttempts(properties, currentRetryCount);
                                channel.BasicPublish(ea.Exchange, ea.RoutingKey, properties, ea.Body);
                                channel.BasicAck(ea.DeliveryTag, false);
                            }
                            else
                            {
                                channel.BasicReject(ea.DeliveryTag, false);
                                mongodbMessage += currentRetryCount + " - Email Queue' den silindi";
                            }
                        }

                        Console.WriteLine(mongodbMessage);
                        AppModel modelMongo = new AppModel
                        {
                            Name        = emailModel.Subject,
                            Description = mongodbMessage,
                            Date        = DateTime.Now
                        };
                        mongoDbService.Create(modelMongo);
                    };

                    channel.BasicConsume("EmailQueue", false, consumer);

                    Console.ReadLine();
                }
            }
        }
示例#10
0
        public static void Main()
        {
            var configuration = CTDbContext.GetConfigurations();

            // This project relies on Dependency Injection to configure its various services,
            // For more info, https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.1
            // All the services used are configured using the service provider.
            var serviceProvider = new ServiceCollection()
                                  .AddLogging(builder =>
            {
                builder.AddConsole();
                builder.AddFilter <Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>
                    ("", LogLevel.Warning);
                builder.AddApplicationInsights(configuration.GetValue <string>("APPLICATION_INSIGHTS_KEY"));
            })
                                  .AddOptions()
                                  .Configure <AppSettings>(configuration)
                                  .AddDbContext <CTDbContext>(options => options.UseLazyLoadingProxies().UseNpgsql(CTDbContext.ConnectionStringBuilder()))
                                  .AddSingleton <RabbitMQConnection>()
                                  .AddSingleton <CaptionQueries>()
                                  .AddSingleton <DownloadPlaylistInfoTask>()
                                  .AddSingleton <DownloadMediaTask>()
                                  .AddSingleton <ConvertVideoToWavTask>()
                                  .AddSingleton <TranscriptionTask>()
                                  .AddSingleton <QueueAwakerTask>()
                                  .AddSingleton <GenerateVTTFileTask>()
                                  .AddSingleton <RpcClient>()
                                  .AddSingleton <ProcessVideoTask>()
                                  .AddSingleton <MSTranscriptionService>()
                                  .AddSingleton <SceneDetectionTask>()
                                  .AddSingleton <UpdateBoxTokenTask>()
                                  .AddSingleton <CreateBoxTokenTask>()
                                  .AddSingleton <ExampleTask>()

                                  .AddSingleton <BoxAPI>()
                                  .AddScoped <Seeder>()
                                  .AddScoped <SlackLogger>()
                                  .AddSingleton <TempCode>()
                                  .BuildServiceProvider();

            _serviceProvider = serviceProvider;
            _logger          = serviceProvider.GetRequiredService <ILogger <Program> >();

            Globals.appSettings           = serviceProvider.GetService <IOptions <AppSettings> >().Value;
            TaskEngineGlobals.KeyProvider = new KeyProvider(Globals.appSettings);

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);

            _logger.LogInformation("Seeding database");

            // Seed the database, with some initial data.
            Seeder seeder = serviceProvider.GetService <Seeder>();

            seeder.Seed();

            _logger.LogInformation("Starting TaskEngine");


            // Delete any pre-existing queues on rabbitMQ.
            RabbitMQConnection rabbitMQ = serviceProvider.GetService <RabbitMQConnection>();

            _logger.LogInformation("RabbitMQ - deleting all queues");

            rabbitMQ.DeleteAllQueues();
            //TODO/TOREVIEW: Should we create all of the queues _before_ starting them?
            // In the current version (all old messages deleted) it is ununnecessary
            // But it seems cleaner to me to create them all first before starting them



            ushort concurrent_videotasks     = toUInt16(Globals.appSettings.MAX_CONCURRENT_VIDEO_TASKS, NO_CONCURRENCY);
            ushort concurrent_synctasks      = toUInt16(Globals.appSettings.MAX_CONCURRENT_SYNC_TASKS, MIN_CONCURRENCY);
            ushort concurrent_transcriptions = toUInt16(Globals.appSettings.MAX_CONCURRENT_TRANSCRIPTIONS, MIN_CONCURRENCY);


            // Create and start consuming from all queues.


            // Upstream Sync related
            _logger.LogInformation($"Creating DownloadPlaylistInfoTask & DownloadMediaTask consumers. Concurrency={concurrent_synctasks} ");
            serviceProvider.GetService <DownloadPlaylistInfoTask>().Consume(concurrent_synctasks);
            serviceProvider.GetService <DownloadMediaTask>().Consume(concurrent_synctasks);

            // Transcription Related
            _logger.LogInformation($"Creating TranscriptionTask & GenerateVTTFileTask consumers. Concurrency={concurrent_transcriptions} ");

            serviceProvider.GetService <TranscriptionTask>().Consume(concurrent_transcriptions);
            serviceProvider.GetService <GenerateVTTFileTask>().Consume(concurrent_transcriptions);

            // Video Processing Related
            _logger.LogInformation($"Creating ProcessVideoTask & SceneDetectionTask consumers. Concurrency={concurrent_videotasks} ");
            serviceProvider.GetService <ProcessVideoTask>().Consume(concurrent_videotasks);
            serviceProvider.GetService <SceneDetectionTask>().Consume(concurrent_videotasks);

            // We dont want concurrency for these tasks
            _logger.LogInformation("Creating QueueAwakerTask and Box token tasks consumers.");
            serviceProvider.GetService <QueueAwakerTask>().Consume(NO_CONCURRENCY); //TODO TOREVIEW: NO_CONCURRENCY?
            serviceProvider.GetService <UpdateBoxTokenTask>().Consume(NO_CONCURRENCY);
            serviceProvider.GetService <CreateBoxTokenTask>().Consume(NO_CONCURRENCY);

            serviceProvider.GetService <ExampleTask>().Consume(NO_CONCURRENCY);

            _logger.LogInformation("Done creating task consumers");
            //nolonger used :
            // nope serviceProvider.GetService<nope ConvertVideoToWavTask>().Consume(concurrent_videotasks);

            bool hacktest = false;

            if (hacktest)
            {
                TempCode tempCode = serviceProvider.GetService <TempCode>();
                tempCode.Temp();
                return;
            }
            _logger.LogInformation("All done!");

            QueueAwakerTask queueAwakerTask = serviceProvider.GetService <QueueAwakerTask>();

            int periodicCheck = Math.Max(1, Convert.ToInt32(Globals.appSettings.PERIODIC_CHECK_EVERY_MINUTES));

            _logger.LogInformation("Periodic Check Every {0} minutes", periodicCheck);
            var timeInterval = new TimeSpan(0, periodicCheck, 0);

            // Check for new tasks every "timeInterval".
            // The periodic check will discover all undone tasks
            // TODO/REVIEW: However some tasks also publish the next items
            while (true)
            {
                queueAwakerTask.Publish(new JObject
                {
                    { "Type", TaskType.PeriodicCheck.ToString() }
                });
                Thread.Sleep(timeInterval);
            }
            ;
        }
        public RabbitMQSubscription(RabbitMQConnection server, DALRabbitMQ dalRabbitMQ)
		{
            _DALRabbitMQ = dalRabbitMQ;
            _Server = server;
			_Queues = new Dictionary<string, MessageQueue>();
			_UnsubscribedQueues = new Dictionary<string, MessageQueue>();
			_SubscriptionToAdd = new Queue<MessageQueue>();
			_ChannelHandlers = new Dictionary<string, ChannelHandler>();
			_TriggerSubscriptionRequest = new ManualResetEvent(false);
			_InvokeCallBack = new AsyncCallback(InvokeCallBack);
		}
示例#12
0
 public ExampleTask(RabbitMQConnection rabbitMQ,
                    ILogger <ExampleTask> logger)
     : base(rabbitMQ, TaskType.ExampleTask, logger)
 {
 }