private bool Perform(ScheduledJob job) { var success = false; Perform handler = null; IList <string> methods = null; try { // Acquire the handler handler = HandlerSerializer.Deserialize <object>(job.Handler).ActLike <Perform>(); if (handler == null) { job.LastError = "Missing handler"; return(false); } // Acquire and cache method manifest var handlerType = handler.GetType(); if (!Cache.TryGetValue(handlerType, out methods)) { methods = handlerType.GetMethods().Select(m => m.Name).ToList(); Cache.Add(handlerType, methods); } _pending.TryAdd(handler, methods); // Before if (methods.Contains("Before")) { handler.ActLike <Before>().Before(); } // Perform success = handler.Perform(); if (success) { if (methods.Contains("Success")) { handler.ActLike <Success>().Success(); } } // Failure if (JobWillFail(job) && methods.Contains("Failure")) { { handler.ActLike <Failure>().Failure(); } } // After if (methods.Contains("After")) { handler.ActLike <After>().After(); } _pending.TryRemove(handler, out methods); } catch (OperationCanceledException) { job.LastError = "Cancelled"; } catch (Exception ex) { job.LastError = ex.Message; if (methods != null && methods.Contains("Error")) { handler.ActLike <Error>().Error(ex); } } return(success); }