public static void Configure(JobCommandContext context) { var app = context.Application; var argOption = app.Option("-c|--custom-arg", "This is a custom job argument.", CommandOptionType.SingleValue); app.OnExecute(() => { var job = context.ServiceProvider.Value.GetService(typeof(Sample2Job)) as Sample2Job; job.CustomArg = argOption.Value(); return(new JobRunner(job, context.LoggerFactory, runContinuous: true, interval: TimeSpan.FromSeconds(1)).RunInConsole()); }); }
public static void Configure(JobCommandContext context) { var app = context.Application; var migrationOption = app.Option("-m|--migration-type", "The type of the migration to run manually.", CommandOptionType.MultipleValue); app.OnExecute(() => { var provider = context.ServiceProvider.Value; var migrationTypeNames = migrationOption.Values; if (context.JobType == null) { throw new ArgumentNullException(nameof(context), $"{nameof(context)}.{nameof(context.JobType)} cannot be null"); } object jobInstance = provider.GetService(context.JobType); if (jobInstance == null) { throw new ArgumentException($"Unable to get instance of type '{context.JobType.Name}'. Please ensure it's registered in Dependency Injection.", nameof(context)); } if (!(jobInstance is ElasticMigrationJobBase job)) { throw new ArgumentException($"Type '{context.JobType.Name}' must implement '{nameof(ElasticMigrationJobBase)}'.", nameof(context)); } if (migrationTypeNames.Any(m => !String.IsNullOrEmpty(m))) { job.MigrationManager.Migrations.Clear(); } foreach (string migrationTypeName in migrationTypeNames.Where(m => !String.IsNullOrEmpty(m))) { try { var migrationType = Type.GetType(migrationTypeName); if (migrationType == null) { Console.WriteLine("Migration type is null."); return(Task.FromResult(-1)); } job.MigrationManager.AddMigration(migrationType); } catch (Exception ex) { Console.WriteLine($"Error getting migration type: {ex.Message}"); return(Task.FromResult(-1)); } } return(new JobRunner(job, context.LoggerFactory, runContinuous: false).RunInConsoleAsync()); }); }
public static void Configure(JobCommandContext context) { var app = context.Application; var migrationOption = app.Option("-m|--migration-type", "The type of the migration to run manually.", CommandOptionType.MultipleValue); app.OnExecute(() => { var provider = context.ServiceProvider.Value; var migrationTypeNames = migrationOption.Values; var job = provider.GetService(context.JobType) as ElasticMigrationJobBase; if (migrationTypeNames.Any(m => !String.IsNullOrEmpty(m))) { job.MigrationManager.Migrations.Clear(); } foreach (string migrationTypeName in migrationTypeNames.Where(m => !String.IsNullOrEmpty(m))) { try { var migrationType = Type.GetType(migrationTypeName); if (migrationType == null) { Console.WriteLine($"Migration type is null."); return(Task.FromResult(-1)); } job.MigrationManager.AddMigration(migrationType); } catch (Exception ex) { Console.WriteLine($"Error getting migration type: {ex.Message}"); return(Task.FromResult(-1)); } } return(new JobRunner(job, context.LoggerFactory, runContinuous: false).RunInConsoleAsync()); }); }