Example #1
0
 public MssqlConsole(IHangfireStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException(nameof(IHangfireStorage));
     }
     _storage = storage;
 }
Example #2
0
 public MysqlConsole(IHangfireStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException(nameof(IHangfireStorage));
     }
     Storage         = storage;
     _lastTimeOffset = 0;
 }
 public IHangfireConsole CreateHangforeConsole(IHangfireStorage storage)
 {
     return(new MysqlConsole(storage));
 }
 public PostgreSqlConsole(IHangfireStorage storage)
 {
     Storage = storage ?? throw new ArgumentNullException(nameof(IHangfireStorage));
 }
        private IHangfireConsole GetHangfireConsole(HttpContext httpContext, Type jobType, IHangfireStorage storage)
        {
            IHangfireConsole console = null;

            try
            {
                //默认每次都是有一个新的实例
                var consoleFactory = httpContext.RequestServices.GetService <IStorageFactory>();
                console = consoleFactory.CreateHangforeConsole(storage);

                ConsoleInfo consoleInfo  = null;
                var         agentConsole = httpContext.Request.Headers["x-job-agent-console"].ToString();
                if (!string.IsNullOrEmpty(agentConsole))
                {
                    consoleInfo = agentConsole.ToJson <ConsoleInfo>();
                }

                if (console != null && consoleInfo != null)
                {
                    var initConsole = console as IHangfireConsoleInit;
                    if (initConsole == null)
                    {
                        console = null;
                    }
                    else
                    {
                        initConsole.Init(consoleInfo);
                    }
                }
                else
                {
                    console = null;
                }
            }
            catch (Exception)
            {
                //ignore
            }

            if (console == null)
            {
                var jobLogger = _loggerFactory.CreateLogger(jobType);
                console = new LoggerConsole(jobLogger);
            }

            return(console);
        }