public void Process(JobContext context) { JobDataService jobService = new JobDataService(JobManager.Settings); Job job = new Job(); job.Id = context.JobId; job.StartedOn = DateTime.UtcNow; job.Status = JobStatus.Running; try { jobService.UpdateJob(job); lock (lockObj) { Pool.Add(context); } var assemblies = AppDomain.CurrentDomain.GetAssemblies(); Assembly assembly = assemblies.FirstOrDefault(a => a.GetName().Name == context.Type.Assembly); if (assembly == null) { //log error throw new Exception("Assembly can not be found!"); } Type type = assembly.GetType(context.Type.CompleteClassName); if (type == null) { throw new Exception($"Type with name '{context.Type.CompleteClassName}' does not exist in assembly {assembly.FullName}"); } var method = type.GetMethod(context.Type.MethodName); if (method == null) { throw new Exception($"Method with name '{context.Type.MethodName}' does not exist in assembly {assembly.FullName}"); } using (var secCtx = SecurityContext.OpenSystemScope()) { try { DbContext.CreateContext(Settings.ConnectionString); //execute job method method.Invoke(new DynamicObjectCreater(type).CreateInstance(), new object[] { context }); } catch (TargetInvocationException ex) { throw ex.InnerException; } catch (Exception ex) { throw ex; } finally { DbContext.CloseContext(); } } job.FinishedOn = DateTime.UtcNow; job.Status = JobStatus.Finished; jobService.UpdateJob(job); } catch (Exception ex) { using (var secCtx = SecurityContext.OpenSystemScope()) { try { DbContext.CreateContext(Settings.ConnectionString); Log log = new Log(); log.Create(LogType.Error, "JobPool.Process", ex); job.FinishedOn = DateTime.UtcNow; job.Status = JobStatus.Failed; job.ErrorMessage = ex.Message; jobService.UpdateJob(job); } finally { DbContext.CloseContext(); } } } finally { lock (lockObj) { Pool.Remove(context); } } }
//Just a test method public void Test(JobContext context) { }