public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.AddToSet( "processing", context.JobId, JobHelper.ToTimestamp(DateTime.UtcNow)); }
public bool ChangeState(StateContext context, IState toState, string oldStateName) { try { var filterInfo = GetFilters(context.Job); var electStateContext = new ElectStateContext(context, toState, oldStateName); var electedState = ElectState(electStateContext, filterInfo.ElectStateFilters); var applyStateContext = new ApplyStateContext(context, electedState, oldStateName); ApplyState(applyStateContext, filterInfo.ApplyStateFilters); // State transition was succeeded. return true; } catch (Exception ex) { var failedState = new FailedState(ex) { Reason = "An exception occurred during the transition of job's state" }; var applyStateContext = new ApplyStateContext(context, failedState, oldStateName); // We should not use any state changed filters, because // some of the could cause an exception. ApplyState(applyStateContext, Enumerable.Empty<IApplyStateFilter>()); // State transition was failed due to exception. return false; } }
public void Ctor_ShouldSetPropertiesCorrectly() { var context = new ApplyStateContext( _stateContext.Object, _newState.Object, OldState); Assert.Equal(OldState, context.OldStateName); Assert.Same(_newState.Object, context.NewState); Assert.Same(_job, context.Job); }
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { var enqueuedState = context.NewState as EnqueuedState; if (enqueuedState == null) { throw new InvalidOperationException(String.Format( "`{0}` state handler can be registered only for the Enqueued state.", typeof(Handler).FullName)); } transaction.AddToQueue(enqueuedState.Queue, context.JobId); }
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { var scheduledState = context.NewState as ScheduledState; if (scheduledState == null) { throw new InvalidOperationException(String.Format( "`{0}` state handler can be registered only for the Scheduled state.", typeof(Handler).FullName)); } var timestamp = JobHelper.ToTimestamp(scheduledState.EnqueueAt); transaction.AddToSet("schedule", context.JobId, timestamp); }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.DecrementCounter("stats:deleted"); }
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.IncrementCounter("stats:succeeded"); }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.RemoveFromSet("schedule", context.JobId); }
private void ApplyState(ApplyStateContext context, IEnumerable<IApplyStateFilter> filters) { using (var transaction = context.Connection.CreateWriteTransaction()) { foreach (var handler in _handlers.GetHandlers(context.OldStateName)) { handler.Unapply(context, transaction); } foreach (var filter in filters) { filter.OnStateUnapplied(context, transaction); } transaction.SetJobState(context.JobId, context.NewState); foreach (var handler in _handlers.GetHandlers(context.NewState.Name)) { handler.Apply(context, transaction); } foreach (var filter in filters) { filter.OnStateApplied(context, transaction); } if (context.NewState.IsFinal) { transaction.ExpireJob(context.JobId, context.JobExpirationTimeout); } else { transaction.PersistJob(context.JobId); } transaction.Commit(); } }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.DecrementCounter("stats:succeeded"); }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.RemoveFromSet("schedule", context.JobId); }
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.IncrementCounter("stats:deleted"); }
public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.RemoveFromList("deleted", context.JobId); }
public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction) { transaction.InsertToList("deleted", context.JobId); transaction.TrimList("deleted", 0, 99); }