Search Results for

    Show / Hide Table of Contents

    Class ForEachActionWorker<TItem>

    A worker that executes a callback once for each item in an IEnumerable<T>. The callback can optionally create child workers, which will be removed after each iteration, except on the last iteration, allowing them to be inspected.

    Less commonly, child workers can also be added (typically by the worker parent) before the worker runs, in which case they will run on the first iteration (if any), but not on later iterations.

    Any failure status returned from the user callback or escalated from worker children will halt the iteration. One can suppress Error escalation on selected child workers (by setting EscalateError to false), e.g. to implement retry-on-error functionality.

    Note that if a dedicated parent worker is not needed (e.g. to group child workers), and all child workers can be created before any child worker is started, it is simpler to instead use a regular foreach statement to perform the work, e.g. creating child workers. See Instantiating Workers via Looping for details.

    Inheritance
    Object
    WorkerParent
    WorkerBase
    WorkerBase<ForEachActionWorker<TItem>>
    ForEachActionWorker<TItem>
    Implements
    IDisposeOnFinished
    Inherited Members
    WorkerBase<ForEachActionWorker<TItem>>.AddCompletedCallback(Func<ForEachActionWorker<TItem>, OutcomeStatus, Task<OutcomeStatus>>)
    WorkerBase<ForEachActionWorker<TItem>>.AddRanCallback(Func<ForEachActionWorker<TItem>, OutcomeStatus, WorkerParentChildrenState, Task<OutcomeStatus>>)
    WorkerBase<ForEachActionWorker<TItem>>.AddStartingCallback(Func<ForEachActionWorker<TItem>, Task<ProgressStatus>>)
    WorkerBase.AddCompletedCallback(Func<WorkerBase, OutcomeStatus, Task<OutcomeStatus>>)
    WorkerBase.AddRanCallback(Func<WorkerBase, OutcomeStatus, WorkerParentChildrenState, Task<OutcomeStatus>>)
    WorkerBase.AddStartingCallback(Func<WorkerBase, Task<ProgressStatus>>)
    WorkerBase.DefaultIsStartable()
    WorkerBase.ErroredPortErrorsWorkerProtected
    WorkerBase.ErrorOutputs
    WorkerBase.EscalateError
    WorkerBase.Inputs
    WorkerBase.IsStartable
    WorkerBase.Outputs
    WorkerBase.Parent
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(WorkerBase, TLastWorker)
    WorkerBase.SucceededSequence<TLastWorker>(TLastWorker)
    WorkerParent.AddChildCompletedCallback(Action<WorkerBase>)
    WorkerParent.AddStartingChildrenCallback(Func<WorkerParent, Task<ProgressStatus>>)
    WorkerParent.Children
    WorkerParent.DisposeOnFinished<TDisposable>(TDisposable)
    WorkerParent.GetDownstreamFactory<TInput>()
    WorkerParent.HasChildren
    WorkerParent.IsCanceled
    WorkerParent.IsCompleted
    WorkerParent.IsCreated
    WorkerParent.IsError
    WorkerParent.IsFailed
    WorkerParent.IsFatal
    WorkerParent.IsRunning
    WorkerParent.IsSucceeded
    WorkerParent.KeepChildrenLevels
    WorkerParent.Locator
    WorkerParent.LogFactory
    WorkerParent.Logger
    WorkerParent.MaxRunningChildren
    WorkerParent.Name
    WorkerParent.RemoveChildren()
    WorkerParent.RescheduleChildren()
    WorkerParent.RunChildrenAsync(Boolean)
    WorkerParent.RunChildrenAsync()
    WorkerParent.Status
    WorkerParent.Item[String]
    WorkerParent.ToString()
    WorkerParent.WorkerSystem
    WorkerParent.DebugCommands
    WorkerParent.AggregateErrorOutputRows
    WorkerParent.AggregateOutputRows
    WorkerParent.AggregateWorkersCompleted
    WorkerParent.InstantCompleted
    WorkerParent.InstantCreated
    WorkerParent.InstantStarted
    WorkerParent.RunningDuration
    Namespace: actionETL
    Assembly: actionETL.dll
    Syntax
    public class ForEachActionWorker<TItem> : WorkerBase<ForEachActionWorker<TItem>>, IDisposeOnFinished
    Type Parameters
    Name Description
    TItem

    The type of each item in the IEnumerable<T>.

    Constructors

    ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Action<ForEachActionWorker<TItem>, TItem>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an action synchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Action<ForEachActionWorker<TItem>, TItem> iterateAction)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Action<ForEachActionWorker<TItem>, TItem> iterateAction

    The synchronous action to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an function synchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc

    The synchronous function to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an function asynchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync

    The asynchronous function to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an action asynchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync

    The asynchronous action to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Action<ForEachActionWorker<TItem>, TItem>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an action synchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Action<ForEachActionWorker<TItem>, TItem> iterateAction)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Action<ForEachActionWorker<TItem>, TItem> iterateAction

    The synchronous action to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an function synchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, OutcomeStatus> iterateFunc

    The synchronous function to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an function asynchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, Task<OutcomeStatus>> iterateFuncAsync

    The asynchronous function to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    ForEachActionWorker(WorkerParent, String, Func<Boolean>, IEnumerable<TItem>, Func<ForEachActionWorker<TItem>, TItem, Task>)

    Initializes a new instance of the ForEachActionWorker<TItem> worker that will execute an action asynchronously once for each item in an IEnumerable<T>.

    Declaration
    public ForEachActionWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, IEnumerable<TItem> enumerable, Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync)
    Parameters
    Type Name Description
    WorkerParent workerParent

    The parent worker or worker system that the new child worker will be added to. Cannot be null.

    String workerName

    Name of the worker.

    Set to a prefix plus a trailing "/" (e.g. "MyPrefix-/") to generate a unique name from the prefix plus an increasing number starting at 1.

    While less useful, set to null, whitespace or "/" to generate a unique name from the worker type plus an increasing number starting at 1.

    The name cannot otherwise contain "/", and cannot start with double underscore "__".

    Func<Boolean> isStartableFunc

    Function to calculate the worker start constraint; it should return true for startable and false for not startable. Defaults to startable if null.

    IEnumerable<TItem> enumerable

    The enumerable that the worker will iterate over.

    Func<ForEachActionWorker<TItem>, TItem, Task> iterateActionAsync

    The asynchronous action to execute each iteration, optionally creating child workers.

    Exceptions
    Type Condition
    ArgumentException

    workerName:

    • Workers with the same parent must have unique names.
    • Worker and worker system names cannot contain '/' or start with double underscore '__'.
    ArgumentNullException
    • workerParent - All workers must have a parent. The top level workers have the worker system as parent.
    • enumerable
    InvalidOperationException
    • Cannot add child worker to parent which has completed. Are you adding it to the correct parent?
    • Cannot add worker to parent, since its children have been started. Are you adding it to the correct parent?

    Methods

    RunAsync()

    This method can be overridden to add custom functionality to the derived worker that runs before and after the main processing. In this case, the base class base.RunAsync() must be called for the worker to function correctly.

    Typically, this worker is used without overriding this method.

    Declaration
    protected override Task<OutcomeStatus> RunAsync()
    Returns
    Type Description
    Task<OutcomeStatus>

    A Task describing the success or failure of the worker. An asynchronous async implementation would e.g. return OutcomeStatus.Succeeded on success, while a synchronous implementation would return OutcomeStatus.SucceededTask.

    Overrides
    WorkerParent.RunAsync()

    Implements

    IDisposeOnFinished

    See Also

    WhileActionWorker<T>
    EscalateError
    In This Article
    Back to top Copyright © 2020 Envobi Ltd