protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { if (G_Volume.IsZero) { G_Volume = getVolume(); } var subscribers = readNextRows(); var count = subscribers.Count(); sendEventsChunk(subscribers); if (count < SocialConsts.SUBSCRIPTION_DELIVERY_CHUNK_SIZE) { G_Volume = getNextVolume(); if (G_Volume.IsZero) { return(ExecuteState.Complete); } ChunkIndex = 0; } else { ChunkIndex += count; } return(ExecuteState.ReexecuteUpdated); } catch (Exception error) { host.Log(MessageType.Error, this, "Deliver()", error.ToMessageWithType(), error); } return(ExecuteState.ReexecuteAfterError); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { var result = FinishSignal.Dispatch(PID, "OK"); var ok = result is OkSignal; return(ok ? ExecuteState.Complete : ExecuteState.ReexecuteAfterError); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { SubscriberVolumeRow minCntVol; var existing = FindSubscriber(out minCntVol); if (existing != null) { return(ExecuteState.Complete); } if (minCntVol == null) { minCntVol = createVolume(); } var row = new SubscriberRow() { G_SubscriberVolume = minCntVol.G_SubscriberVolume, G_Subscriber = G_Subscriber, Subs_Type = Subs_Type, Create_Date = App.TimeSource.UTCNow, Parameters = Parameters }; try { ForNode(row.G_SubscriberVolume).Insert(row); } catch (DataAccessException dae) { if (dae.KeyViolation.IsNotNullOrWhiteSpace()) { return(ExecuteState.Complete); } throw; } try { minCntVol.Count++; ForNode(G_Owner).Update(minCntVol, filter: "Count".OnlyTheseFields()); } catch (Exception error) { host.Log(MessageType.Error, this, "Subscribe()", error.ToMessageWithType(), error); } return(ExecuteState.Complete); } catch (Exception error) { host.Log(MessageType.Error, this, "Subscribe()", error.ToMessageWithType(), error); return(ExecuteState.ReexecuteAfterError); } }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { //------------------------------------------------------------------------------- if (SysState == State_WorkPart) { if (Done) { return(State_DispatchDone); } var rndMs = ExternalRandomGenerator.Instance.NextScaledRandomInteger(3 * 60 * 1000, 5 * 60 * 1000); SysStartDate = utcBatchNow.AddMilliseconds(rndMs); Done = true; return(ExecuteState.ReexecuteUpdated); } //------------------------------------------------------------------------------- if (SysState == State_DispatchDone) { try { var signal = WorkPartDoneSignal.Make(PID, Part, "OK"); var result = AgniSystem.ProcessManager.Dispatch(signal); if (result is OkSignal) { return(State_EnqueueFinish); } } catch (Exception error) { host.Log(MessageType.Error, this, "Execute().DispatchDone", error.ToMessageWithType(), error); return(ExecuteState.ReexecuteAfterError); } throw new DemoException("Wrong result signal"); } //------------------------------------------------------------------------------- if (SysState == State_EnqueueFinish) { try { var todo = Todo.MakeNew <FinishDemoProcessTodo>(); todo.PID = PID; todo.SysStartDate = utcBatchNow.AddMinutes(5); AgniSystem.ProcessManager.Enqueue(todo, "todo", "todoqueue"); return(ExecuteState.Complete); } catch (Exception error) { host.Log(MessageType.Error, this, "Execute().EnqueueFinish", error.ToMessageWithType(), error); return(ExecuteState.ReexecuteAfterError); } } throw new WorkersException(StringConsts.UNKNOWN_TODO_STATE_ERROR.Args(GetType().Name, SysState)); }
protected internal override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { System.Threading.Interlocked.Increment(ref TotalProcessed); //App.Log.Write( new Message //{ // Type = MessageType.Info, // From = "", // Text = "--------------> {0} {1} {2}".Args(PersonID, PersonName, PersonDOB) //}); return(ExecuteState.Complete); }
protected override MergeResult Merge(ITodoHost host, DateTime utcNow, CorrelatedTodo another) { var anotherTodo = another as FinishDemoProcessTodo; if (anotherTodo == null) { return(MergeResult.None); } if (SysStartDate < anotherTodo.SysStartDate) { SysStartDate = anotherTodo.SysStartDate; return(MergeResult.Merged); } return(MergeResult.IgnoreAnother); }
protected internal override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { Count--; if (Count < 0) { return(ExecuteState.Complete); } App.Log.Write(new Message { Type = MessageType.Info, From = "", Text = "--------------> Email nomer #{0} poslan {1}".Args(Count, Who) }); SysStartDate = App.TimeSource.UTCNow.AddSeconds(IntervalSec); return(ExecuteState.ReexecuteUpdated); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { SubscriberVolumeRow minColVol; var row = FindSubscriber(out minColVol); if (row == null) { return(ExecuteState.ReexecuteAfterError); } ForNode(row.G_SubscriberVolume).Delete(row); return(ExecuteState.Complete); } catch (Exception error) { host.Log(MessageType.Error, this, "Unsubscribe()", error.ToMessageWithType(), error); return(ExecuteState.ReexecuteAfterError); } }
protected internal override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { System.Threading.Interlocked.Increment(ref TotalProcessed); // System.Threading.Thread.Sleep(App.Random.NextScaledRandomInteger(1000, 3000)); App.Log.Write(new Message { Type = MessageType.Info, From = "", Text = "--------------> {0} {1}".Args(SysCorrelationKey, Counter) }); //var t = Todo.NewTodo<CorrelatedTeztTodo>(); //t.SysCorrelationKey = this.SysCorrelationKey; //t.Counter = 1; //t.SysStartDate = App.TimeSource.UTCNow.AddSeconds(2); //host.Enqueue(t); return(ExecuteState.Complete); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { //------------------------------------------------------------------------------- if (SysState == State_SpawnProcess) { try { DemoProcess.Spawn(PID, PartCount); return(State_EnqueueWorkParts); } catch (Exception error) { host.Log(MessageType.Error, this, "Execute().SpawnProcess", error.ToMessageWithType(), error); return(ExecuteState.ReexecuteAfterError); } } //------------------------------------------------------------------------------- if (SysState == State_EnqueueWorkParts) { try { var todo = MakeNew <WorkPartDemoProcessTodo>(); todo.PID = PID; PartCount--; m_IsModified = true; todo.Part = PartCount; AgniSystem.ProcessManager.Enqueue(todo, "todo", "todoqueue"); return(PartCount == 0 ? ExecuteState.Complete : State_EnqueueWorkParts); } catch (Exception error) { host.Log(MessageType.Error, this, "Execute().EnqueueWorkParts", error.ToMessageWithType(), error); return(m_IsModified ? ExecuteState.ReexecuteUpdatedAfterError : ExecuteState.ReexecuteAfterError); } } throw new WorkersException(StringConsts.UNKNOWN_TODO_STATE_ERROR.Args(GetType().Name, SysState)); }
protected internal override MergeResult Merge(ITodoHost host, DateTime utcNow, CorrelatedTodo another) { var at = another as CorrelatedTeztTodo; if (at == null) { return(MergeResult.None); } //if (at.Counter==73) //{ // var t = Todo.NewTodo<TeztTodo>(); // t.PersonID = "fwdeohfdh"; // t.PersonDOB = DateTime.Now; // t.PersonName = "zhabakritskiy"; // host.Enqueue( t ); //} //if(at.Counter == 73) //{ // var t = Todo.NewTodo<CorrelatedTeztTodo>(); // t.SysCorrelationKey = this.SysCorrelationKey; // t.Counter = 1; // host.Enqueue(t); //} if (Counter >= 10) { return(MergeResult.None); //can not have counter > 10 (business logic) } Counter += at.Counter; // SysStartDate = utcNow.AddSeconds(10);//reschedule for later call return(MergeResult.Merged); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { IConfigSectionNode cfg = null; if (Event.Config.IsNotNullOrWhiteSpace()) { cfg = Event.Config.AsLaconicConfig(handling: ConvertErrorHandling.ReturnDefault); } var graphHost = GraphOperationContext.Instance.GraphHost; var badSubs = graphHost.DeliverEventsChunk(ToRedilever, Event, cfg); if (badSubs != null && badSubs.Any()) { ToRedilever = badSubs.ToArray(); return(ExecuteState.ReexecuteUpdated); } return(ExecuteState.Complete); } catch (Exception error) { host.Log(MessageType.Error, this, "Redeliver()", error.ToMessageWithType(), error); } return(ExecuteState.ReexecuteAfterError); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { if (G_Volume.IsZero) { G_Volume = getVolume(); } removeSubscribers(); G_Volume = getNextVolume(); if (G_Volume.IsZero) { removeVolumes(); removeNode(); return(ExecuteState.Complete); } return(ExecuteState.ReexecuteUpdated); } catch (Exception error) { host.Log(MessageType.Error, this, "RemoveNode()", error.ToMessageWithType(), error); } return(ExecuteState.ReexecuteAfterError); }
protected override ExecuteState Execute(ITodoHost host, DateTime utcBatchNow) { try { if (G_Friend.IsZero) { G_Friend = getFriend(); } removeFriends(); G_Friend = getNextFriend(); if (G_Friend.IsZero) { removeFriendList(); removeFriend(); return(ExecuteState.Complete); } return(ExecuteState.ReexecuteUpdated); } catch (Exception error) { host.Log(MessageType.Error, this, "RemoveNode()", error.ToMessageWithType(), error); } return(ExecuteState.ReexecuteAfterError); }
/// <summary> /// Executes merge operation returning what whould happen to the original and another todo. /// This method MUST execute be VERY FAST and only contain merge logic, do not make externall IO calls - /// all business data must already be contained in the original and another instance /// </summary> protected internal abstract MergeResult Merge(ITodoHost host, DateTime utcNow, CorrelatedTodo another);
/// <summary> /// Executes the todo. Override to perform actual logic. /// You have to handle all exceptions, otherwise the leaked exception will /// complete the todo with error. Return the result that describes whether the item completed or should be reexecuted again. /// Keep in mind: Todos are not designed to execute long-running(tens+ of seconds) processes, launch other async workers instead /// </summary> protected internal abstract ExecuteState Execute(ITodoHost host, DateTime utcBatchNow);