예제 #1
0
        static void Main()
        {
            // log4net.Config.XmlConfigurator.Configure();00000000
            logger = NLog.LogManager.GetCurrentClassLogger();
            logger.Info("Worker Host process has been started");
            unityContainer = UnityConfig.Register();
            UnityConfig.ConfigureDefaults(unityContainer);
            var storage = new SqlServerStorage("HangfireStorageDbContext");
            var options = new BackgroundJobServerOptions()
            {
                WorkerCount = 10
            };

            UnityJobActivator unityJobActivator = new UnityJobActivator(unityContainer);

            GlobalConfiguration.Configuration.UseActivator(unityJobActivator);
            JobActivator.Current = unityJobActivator;

            GlobalJobFilters.Filters.Add(new ChildContainerPerJobFilterAttribute(unityJobActivator));
            var server = new BackgroundJobServer(options, storage);

            server.Start();
            Thread.Sleep(300000);
            server.Stop();
        }
예제 #2
0
        // web server
        private static void StartServerB()
        {
            _currentJobStorage.UseMsmqQueues(@".\private$\hangfire-{0}", "serverbqueue", "serverbqueue2");

            var serverBOptions = new BackgroundJobServerOptions
            {
                Queues      = new[] { "serverbqueue" },
                WorkerCount = 8,
                ServerName  = String.Format("{0}:serverbqueue", "ServerB"),
            };

            _serverA = new BackgroundJobServer(serverBOptions, JobStorage.Current);


            var serverB2Options = new BackgroundJobServerOptions
            {
                Queues      = new[] { "serverbqueue2" },
                WorkerCount = 1,
                ServerName  =
                    String.Format("{0}:serverbqueue2", "ServerB"),
            };

            _serverB = new BackgroundJobServer(serverB2Options, JobStorage.Current);

            _serverA.Start();
            _serverB.Start();
        }
예제 #3
0
        private static void StartAllInOneServer()
        {
            _currentJobStorage.UseMsmqQueues(@".\private$\hangfire-{0}", "serveraqueue", "serverbqueue", "serverbqueue2");

            var defaultHangFireInstanceOptions = new BackgroundJobServerOptions
            {
                Queues      = new[] { "serveraqueue", "serverbqueue" },
                WorkerCount = 2,
                ServerName  = String.Format("{0}:serverbqueue", "AllInOneServer"),
            };

            _serverA = new BackgroundJobServer(defaultHangFireInstanceOptions, JobStorage.Current);

            var exportContactsInstanceOptions = new BackgroundJobServerOptions
            {
                Queues      = new[] { "serverbqueue2" },
                WorkerCount = 1,
                ServerName  = String.Format("{0}:serverbqueue2", "AllInOneServer"),
            };

            _serverB = new BackgroundJobServer(exportContactsInstanceOptions, JobStorage.Current);

            _serverA.Start();
            _serverB.Start();
        }
예제 #4
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(); //only once

            _log.Debug("Application is starting");

            if (args.Length > 0)
            {
                _storage = new SqlServerStorage(@"Data Source=.;Initial Catalog=SpriteHangFire;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
                var options = new BackgroundJobServerOptions();
                var server  = new BackgroundJobServer(options, _storage);
                server.Start();

                Console.WriteLine("Hangfire Server started. Press any key to exit...");

                var input = Console.ReadKey();
                HandleInput(input);
                //using ()
                //{
                //    server.Start();
            }
            else
            {
                _log.Info("application launched without arguments");
                throw new NullReferenceException("kkkkkkjkljfkldsjfkl");
                //FileInfo f = new FileInfo();
                File.Create(string.Format(@"C:\TFSDATA\KissTheFuture\Trunk\shopping.lacage.be\shoppingconsole.lacage.be\bin\Debug\{0}.txt", Guid.NewGuid()));
                Thread.Sleep(5000);
            }

            //c.Schedule(() => MyJob.DoSomething(), TimeSpan.FromMinutes(10));

            //Console.ReadKey();
            //}
        }
예제 #5
0
        protected void Application_Start()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <ApplicationDbContext, Configuration>());
            AreaRegistration.RegisterAllAreas();
            ControllerBuilder.Current.DefaultNamespaces.Add("HealthTrac.Controllers.Api");
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            GlobalConfiguration.Configuration.Formatters.Clear();
            var json = new JsonMediaTypeFormatter();

            json.SerializerSettings.ReferenceLoopHandling      = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            json.SerializerSettings.PreserveReferencesHandling =
                Newtonsoft.Json.PreserveReferencesHandling.None;
            GlobalConfiguration.Configuration.Formatters.Add(json);
            DependencyResolver.SetResolver(Bootstrapper.GetMvcResolver());
            GlobalConfiguration.Configuration.DependencyResolver = Bootstrapper.GetApiResolver();
            JobStorage.Current =
                new SqlServerStorage("DefaultConnection");
            _server = new BackgroundJobServer();
            _server.Start();
            BuildForest();
            BuildLinearModel();
            RecurringJob.AddOrUpdate(() => BuildLinearModel(), Cron.Daily);
            RecurringJob.AddOrUpdate(() => BuildForest(), Cron.Daily);
        }
예제 #6
0
        protected override void OnStart(string[] args)
        {
            _redisMQLog = new RedisMQLog {
                Title = "服务启动", Content = "大方工业云数据同步服务:【服务启动】", CDate = ToolMethods.GetNow()
            };
            WriteLog(_redisMQLog);

            _server.Start();
        }
예제 #7
0
        public static void RunHangfireServer(
            this IAppBuilder app,
            BackgroundJobServer server)
        {
            Servers.Add(server);

            server.Start();

            var context = new OwinContext(app.Properties);
            var token   = context.Get <CancellationToken>("host.OnAppDisposing");

            if (token != CancellationToken.None)
            {
                token.Register(server.Dispose);
            }
        }
예제 #8
0
        public static void RunHangfireServer(
            this IAppBuilder app,
            BackgroundJobServer server)
        {
            Servers.Add(server);

            server.Start();

            var context = new OwinContext(app.Properties);
            var token = context.Get<CancellationToken>("host.OnAppDisposing");

            if (token != CancellationToken.None)
            {
                token.Register(server.Dispose);
            }
        }
예제 #9
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            //initiate all cron jobs
            JobStorage.Current = new SqlServerStorage("DefaultConnection");
            _server            = new BackgroundJobServer();
            _server.Start();

            new DenariCronJobs().initateDividends();
            new DenariCronJobs().generateReconciliation();
        }
예제 #10
0
        static void Main()
        {
            // log4net.Config.XmlConfigurator.Configure();00000000
            logger = NLog.LogManager.GetCurrentClassLogger();
            logger.Info("Worker Host process has been started");
            unityContainer = UnityConfig.Register();
            UnityConfig.ConfigureDefaults(unityContainer);
            var storage = new SqlServerStorage("HangfireStorageDbContext");
            var options = new BackgroundJobServerOptions()
            {
                WorkerCount = 10
            };

            UnityJobActivator unityJobActivator = new UnityJobActivator(unityContainer);
            GlobalConfiguration.Configuration.UseActivator(unityJobActivator);
            JobActivator.Current = unityJobActivator;

            GlobalJobFilters.Filters.Add(new ChildContainerPerJobFilterAttribute(unityJobActivator));
            var server = new BackgroundJobServer(options, storage);
            server.Start();
            Thread.Sleep(300000);
            server.Stop();
        }
예제 #11
0
        public static void Main()
        {
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(
                LogLevel.Info, false, false, true, "");

            var sqlServerStorage = new SqlServerStorage(
                @"Server=.\sqlexpress;Database=Hangfire.Sample;Trusted_Connection=True;");

            sqlServerStorage.UseMsmqQueues(@".\Private$\hangfire{0}", "default", "critical");

            JobStorage.Current =
                sqlServerStorage;
            //new RedisStorage("localhost:6379", 3);

            RecurringJob.AddOrUpdate(() => Console.WriteLine("Hello, world!"), Cron.Minutely);
            RecurringJob.AddOrUpdate("hourly", () => Console.WriteLine("Hello"), "25 15 * * *");

            var options = new BackgroundJobServerOptions
            {
                Queues = new[] { "critical", "default" }
            };

            using (var server = new BackgroundJobServer(options))
            {
                var count = 1;

                while (true)
                {
                    var command = Console.ReadLine();

                    if (command == null || command.Equals("stop", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    if (command.Equals("start", StringComparison.OrdinalIgnoreCase))
                    {
                        server.Start();
                    }

                    if (command.StartsWith("add", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(4));
                            for (var i = 0; i < workCount; i++)
                            {
                                var number = i;
                                BackgroundJob.Enqueue <Services>(x => x.Random(number));
                            }
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    if (command.StartsWith("static", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(7));
                            for (var i = 0; i < workCount; i++)
                            {
                                BackgroundJob.Enqueue(() => Console.WriteLine("Hello, {0}!", "world"));
                            }
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    if (command.StartsWith("error", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(6));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.Error());
                        }
                    }

                    if (command.StartsWith("args", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(5));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.Args(Guid.NewGuid().ToString(), 14442, DateTime.UtcNow));
                        }
                    }

                    if (command.StartsWith("custom", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(7));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.Custom(
                                                                 new Random().Next(),
                                                                 new [] { "Hello", "world!" },
                                                                 new Services.CustomObject {
                                Id = 123
                            },
                                                                 DayOfWeek.Friday
                                                                 ));
                        }
                    }

                    if (command.StartsWith("fullargs", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(9));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.FullArgs(
                                                                 false,
                                                                 123,
                                                                 'c',
                                                                 DayOfWeek.Monday,
                                                                 "hello",
                                                                 new TimeSpan(12, 13, 14),
                                                                 new DateTime(2012, 11, 10),
                                                                 new Services.CustomObject {
                                Id = 123
                            },
                                                                 new[] { "1", "2", "3" },
                                                                 new[] { 4, 5, 6 },
                                                                 new long[0],
                                                                 null,
                                                                 new List <string> {
                                "7", "8", "9"
                            }));
                        }
                    }

                    if (command.StartsWith("in", StringComparison.OrdinalIgnoreCase))
                    {
                        var seconds = int.Parse(command.Substring(2));
                        var number  = count++;
                        BackgroundJob.Schedule <Services>(x => x.Random(number), TimeSpan.FromSeconds(seconds));
                    }

                    if (command.StartsWith("cancelable", StringComparison.OrdinalIgnoreCase))
                    {
                        var iterations = int.Parse(command.Substring(11));
                        BackgroundJob.Enqueue <Services>(x => x.Cancelable(iterations, JobCancellationToken.Null));
                    }

                    if (command.StartsWith("delete", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(7));
                        for (var i = 0; i < workCount; i++)
                        {
                            var jobId = BackgroundJob.Enqueue <Services>(x => x.EmptyDefault());
                            BackgroundJob.Delete(jobId);
                        }
                    }

                    if (command.StartsWith("fast", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(5));
                            Parallel.For(0, workCount, i =>
                            {
                                if (i % 2 == 0)
                                {
                                    BackgroundJob.Enqueue <Services>(x => x.EmptyCritical());
                                }
                                else
                                {
                                    BackgroundJob.Enqueue <Services>(x => x.EmptyDefault());
                                }
                            });
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }

            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }
예제 #12
0
        public static void Main()
        {
            LogManager.LogFactory = new ConsoleLogFactory();

            RedisFactory.Host = "127.0.0.1:19999";
            RedisFactory.Db   = 3;

            GlobalJobFilters.Filters.Add(new HistoryStatisticsAttribute(), 20);
            GlobalJobFilters.Filters.Add(new RetryAttribute());

            using (var server = new BackgroundJobServer(25, "critical", "default"))
            {
                server.Start();

                var count = 1;

                while (true)
                {
                    var command = Console.ReadLine();

                    if (command == null || command.Equals("stop", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    if (command.StartsWith("add", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(4));
                            for (var i = 0; i < workCount; i++)
                            {
                                var number = i;
                                BackgroundJob.Enqueue <Services>(x => x.Random(number));
                            }
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    if (command.StartsWith("static", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(7));
                            for (var i = 0; i < workCount; i++)
                            {
                                BackgroundJob.Enqueue(() => Console.WriteLine("Hello, {0}!", "world"));
                            }
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    if (command.StartsWith("error", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(6));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.Error());
                        }
                    }

                    if (command.StartsWith("old", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(4));
                        for (var i = 0; i < workCount; i++)
                        {
                            Perform.Async <OldJob>(new { Hello = "world", Empty = (string)null, Number = 12.44 });
                        }
                    }

                    if (command.StartsWith("args", StringComparison.OrdinalIgnoreCase))
                    {
                        var workCount = int.Parse(command.Substring(5));
                        for (var i = 0; i < workCount; i++)
                        {
                            BackgroundJob.Enqueue <Services>(x => x.Args(Guid.NewGuid().ToString(), 14442, DateTime.UtcNow));
                        }
                    }

                    if (command.StartsWith("in", StringComparison.OrdinalIgnoreCase))
                    {
                        var seconds = int.Parse(command.Substring(2));
                        var number  = count++;
                        BackgroundJob.Schedule <Services>(x => x.Random(number), TimeSpan.FromSeconds(seconds));
                    }

                    if (command.StartsWith("recurring", StringComparison.OrdinalIgnoreCase))
                    {
                        BackgroundJob.Enqueue <Services>(x => x.Recurring());
                        Console.WriteLine("Recurring job added");
                    }

                    if (command.StartsWith("fast", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var workCount = int.Parse(command.Substring(5));
                            Parallel.For(0, workCount, i =>
                            {
                                if (i % 2 == 0)
                                {
                                    BackgroundJob.Enqueue <Services>(x => x.EmptyCritical());
                                }
                                else
                                {
                                    BackgroundJob.Enqueue <Services>(x => x.EmptyDefault());
                                }
                            });
                            Console.WriteLine("Jobs enqueued.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }

            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }