Esempio n. 1
0
        public static void StartJob(string jobName, DriftClientConfig config, PerformContext hangfireContext)
        {
            config.Logger = new HangfireConsoleLogger <DriftClient>(hangfireContext, config.Logger);
            var drift = new DriftClient(config);

            drift.Run(jobName);
        }
Esempio n. 2
0
        static void Main(string[] rawArgs)
        {
            // Parse args
            var args = ParseArgs(rawArgs);

            // Setup logging
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(b =>
            {
                b.AddConsole();
                b.SetMinimumLevel(LogLevel.Debug);
            })
            .Configure <LoggerFilterOptions>(options => options.MinLevel = LogLevel.Debug);
            var services = serviceCollection.BuildServiceProvider();
            var logger   = services.GetRequiredService <ILogger <DriftClient> >();

            // Create/run client
            var drift = new DriftClient(c =>
            {
                c.DriftConfigPath = args.File;
                c.Logger          = logger;
            });

            drift.Run();

            // Dispose of services, without this logging may not be flushed/displayed
            services.Dispose();
        }
Esempio n. 3
0
 public static IServiceCollection AddDrift(this IServiceCollection serviceCollection, IConfiguration configuration)
 {
     serviceCollection.AddTransient <DriftClientConfig>((services) => {
         var driftSection = configuration.GetSection("Drift");
         var driftConfig  = driftSection.Get <DriftClientConfig>();
         return(driftConfig);
     });
     serviceCollection.AddTransient <DriftClient>((services) => {
         // Load "Drift" section from appsettings
         var driftConfig = services.GetRequiredService <DriftClientConfig>();
         // Pass our logger to the config
         driftConfig.Logger = services.GetService <ILogger <DriftClient> >();
         var drift          = new DriftClient(driftConfig);
         return(drift);
     });
     return(serviceCollection);
 }
Esempio n. 4
0
        /// <summary>
        /// Schedules all current Jobs within Hanfire as seperate jobs
        /// </summary>
        public void Schedule()
        {
            //ToDo: Remove kubectl call
            // As working around to k8s rest not supporting refresh tokens
            // Run kubectl command to handle this for us
            RunKubectlRefresh();
            _logger.LogInformation("Loading drift jobs");
            // Recreate client using this config and get job names
            var jobNames = new DriftClient(_driftConfig).GetJobNames();

            _logger.LogInformation($"Found total of {jobNames.Length} jobs to queue");
            foreach (var jobName in jobNames)
            {
                // Create separate queue'd job for each name
                _backgroundJobs.Enqueue(() => StartJob(jobName, _driftConfig, null));
                _logger.LogInformation($"Queued job: {jobName}");
            }
        }