StackExchange.Redis.RedisTimeoutException: Timeout performing SETEX (5000ms), next: SETEX AutoOps:PodLauncher:2109:LWSY:75:85001:IsMainServerRunning, inst: 0, qu: 0, qs: 1, aw: False, rs: ReadAsync, ws: Idle, in: 0, in-pipe: 0, out-pipe: 0, serverEndpoint: r-bp1je5yrr7ctdzwhmk.redis.rds.aliyuncs.com:6379, mc: 1/1/0, mgr: 10 of 10 available, clientName: 2109-85001-0, IOCP: (Busy=1,Free=999,Min=4,Max=1000), WORKER: (Busy=2,Free=32765,Min=32,Max=32767), v: 2.1.28.64774 (Please take a look at this article for some common client-side issues …
Category: C#
Methods to start process in C# and powershell
private int StartProcess(SoftwareSvr swSvr, string workingDir) { Process proc = new Process(); proc.StartInfo.UseShellExecute = true; proc.StartInfo.WorkingDirectory = workingDir; proc.StartInfo.FileName = swSvr.Command; if (swSvr.Args != null && swSvr.Args.Any()) { proc.StartInfo.Arguments = string.Join(' ', swSvr.Args); } bool started = proc.Start(); if (started) { return proc.Id; } else { return -1; } } private int StartProcessByPs(SoftwareSvr swSvr, string …
Implementing Graceful Shutdown in Windows Container
Kubernetes Linux Pod中,当通过kubectl删除一个Pod或rolling update一个Pod时, 每Terminating的Pod中的每个Container中PID为1的进程会收到SIGTERM信号, 通知进程进行资源回收并准备退出. 如果在Pod spec.terminationGracePeriodSeconds指定的时间周期内进程没有退出, 则Kubernetes接着会发出SIGKILL信号KILL这个进程。 通过 kubectl delete –force –grace-period=0 … 的效果等同于直接发SIGKILL信号. 但SIGTERM和SIGKILL方式在Windows Container中并不工作, 目前Windows Container的表现是接收到Terminating指令5秒后直接终止。。。 参见:https://v1-18.docs.kubernetes.io/docs/setup/production-environment/windows/intro-windows-in-kubernetes/#v1-pod V1.Pod.terminationGracePeriodSeconds – this is not fully implemented in Docker on Windows, see: reference. The behavior today is that the ENTRYPOINT process is sent CTRL_SHUTDOWN_EVENT, then Windows waits 5 seconds by default, and finally shuts down …
How to override an ASP.NET Core configuration array setting using environment variables
假如一个appsettings.json文件, 需要在环境变量中添加配置覆盖AppSettings/EnabledWorkspace节: { "Logging": { "LogLevel": { "Default": "Warning", "System": "Information", "Microsoft": "Information" } }, //Basic Auth for Tapd api "AppSettings": { "EnabledWorkspace": [ "58645295", "44506107", "84506239" ] } } 这样配置: AppSettings__EnabledWorkspace__0 = 58645295 AppSettings__EnabledWorkspace__1 = 44506107 AppSettings__EnabledWorkspace__2 = 84506239 Refer to: How to override an ASP.NET Core configuration array setting using environment variables …
Time Range Overlap
(StartA <= EndB) and (EndA >= StartB) Precondition: StartA < EndA StartB < EndB Ref: https://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
[MongoDB] Read preference in a transaction must be primary
MongoDB 4.0.3 ReplicaSet MongoDB.Driver for .net Core 2.7.3 在Connection String中配置了readPreference=secondaryPreferred: mongodb://user:password@mongod-1:27017,mongod-2:27017,mongod-3:27017/DBName?connect=replicaSet&readPreference=secondaryPreferred 然后在一个Transaction中读取数据报错:”Read preference in a transaction must be primary”, Transaction中的读取不能使用secondaryPreferred
Dynamically create generic C# object using reflection | 动态创建C#泛型实例
Classes referenced by generic type: public class Cat { ... } public class Dog { ... } Generic class: public class Animals<T> { public Animals(int id, T body) { Id = id; Body = body; } public int Id { get; set; } public T Body { get; set; } } Create instance for generic …
Consume AutoMapper in a Singleton instance during impliment an IHostedService
AutoMapper中的AddAutoMapper默认使用AddScoped方式把AutoMapper实例注册到.NET Core DI中的: public void ConfigureServices(IServiceCollection services) { ... services.AddAutoMapper(); ... } 如果你在一个IHostedService注册了一个Singleton实例, 该Singleton实例的构造函数中通过DI注入的方式引用了IMapper, 将会发生如下错误: 'Cannot consume scoped service 'AutoMapper.IMapper' from singleton 'XXX'.' 解决方法是把IMapper也以Singleton模式注册: public class AutoMapperProfile : Profile { public AutoMapperProfile() { CreateMap<SourceClass, DestinationClass>(); } } public void ConfigureServices(IServiceCollection services) { ... var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new AutoMapperProfile()); }); IMapper mapper …
C#中使用反射调用参数中包含Lambda表达式的方法
如下代码片断展示了怎样在C#中使用反射调用参数中包含Lambda表达式的方法: GetData(Expression<Func<ExampleEntity, bool>>), 以及根据条件动态选择无参和有参方法: using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace ReflectCallGenericMethod { class Program { static void Main(string[] args) { Assembly assembly = Assembly.GetExecutingAssembly(); Type typeService = assembly.GetTypes() .Where(t => t.IsClass && t.Name == "ExampleService").SingleOrDefault(); Type typeEntity = assembly.GetTypes() .Where(t => t.IsClass && t.Name == "ExampleEntity").SingleOrDefault(); ParameterExpression paramExp = Expression.Parameter(typeEntity); Expression expression …