/// <summary> /// Creates a new Temporal <see cref="Worker"/> attached to the current client. You'll /// use this to register your workflow and/or activity implementations with Temporal and /// the start the worker to signal Temporal that the worker is ready for business. /// </summary> /// <param name="namespace">Optionally specifies namespace for worker. Defaults /// to namespace set in <see cref="Settings"/>.</param> /// <param name="taskQueue">Optionally specifies task queue for worker. Defaults /// to task queue set in <see cref="Settings"/>.</param> /// <param name="options">Optionally specifies additional worker options.</param> /// <returns>A <see cref="Worker"/> identifying the worker instance.</returns> /// <remarks> /// <para> /// Each worker instance will be responsible for actually executing Temporal workflows and /// activities. Workers are registered within a Temporal namespace and are assigned to a /// task queue which identifies the virtual queue Temporal uses to schedule work on workers. /// Workers implementing the same workflows and activities will generally be assigned to /// the same task queue (which is just an identifying string). /// </para> /// <para> /// After you have a new worker, you'll need to register workflow and/or activity implementations /// via <see cref="Worker.RegisterActivityAsync{TActivity}(bool)"/>, /// <see cref="Worker.RegisterAssemblyActivitiesAsync(Assembly, bool)"/>, /// <see cref="Worker.RegisterAssemblyAsync(Assembly, bool)"/>, or /// <see cref="Worker.RegisterAssemblyWorkflowsAsync(Assembly, bool)"/>. /// </para> /// <para> /// Then after completing the registrations, you'll call <see cref="Worker.StartAsync"/> /// to start the worker, signalling to Temporal that the worker is ready to execute /// workflows and activities. /// </para> /// <para> /// You may call <see cref="Worker.Dispose"/> to explicitly stop a worker or just /// dispose the <see cref="TemporalClient"/> which automatically disposes any /// related workers. /// </para> /// </remarks> public async Task <Worker> NewWorkerAsync( string @namespace = null, string taskQueue = null, WorkerOptions options = null) { await SyncContext.Clear; EnsureNotDisposed(); @namespace = @namespace ?? Settings.Namespace; taskQueue = taskQueue ?? Settings.TaskQueue; options = options ?? new WorkerOptions(); var reply = (NewWorkerReply)(await CallProxyAsync( new NewWorkerRequest() { Namespace = @namespace, TaskQueue = taskQueue, Options = options })); reply.ThrowOnError(); var worker = new Worker(this, reply.WorkerId, options); lock (syncLock) { idToWorker.Add(reply.WorkerId, worker); } return(worker); }
/// <summary> /// Internal constructor. /// </summary> /// <param name="client">The parent client.</param> /// <param name="workerId">The ID of the worker as tracked by the <b>temporal-proxy</b>.</param> /// <param name="options">Specifies the worker options or <c>null</c>.</param> internal Worker(TemporalClient client, long workerId, WorkerOptions options) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); Covenant.Requires <ArgumentNullException>(options != null, nameof(options)); this.Client = client; this.WorkerId = workerId; this.options = options; }