@@ -218,10 +218,18 @@ func main() {
218218 attribute .String ("key" , event .Key ),
219219 attribute .Bool ("dir" , event .IsDir ),
220220 )
221- logger .V (1 ).Info ("Starting new workflow" , "watcher" , event .WatcherName , "bucket" , event .Bucket , "key" , event .Key , "dir" , event .IsDir )
221+ pipelineName := workflow .RandomPipeline (event .PipelineName , pipelineRegistry )
222+ logger .V (1 ).Info (
223+ "Starting new workflow" ,
224+ "watcher" , event .WatcherName ,
225+ "bucket" , event .Bucket ,
226+ "key" , event .Key ,
227+ "dir" , event .IsDir ,
228+ "pipeline" , pipelineName ,
229+ )
222230 req := collection.ProcessingWorkflowRequest {
223231 WatcherName : event .WatcherName ,
224- PipelineNames : event . PipelineName ,
232+ PipelineName : pipelineName ,
225233 RetentionPeriod : event .RetentionPeriod ,
226234 CompletedDir : event .CompletedDir ,
227235 StripTopLevelDir : event .StripTopLevelDir ,
@@ -233,7 +241,8 @@ func main() {
233241 ValidationConfig : config .Validation ,
234242 MetadataConfig : config .Metadata ,
235243 }
236- if err := collection .InitProcessingWorkflow (ctx , tracer , temporalClient , config .Temporal .TaskQueue , & req ); err != nil {
244+
245+ if err := collection .InitProcessingWorkflow (ctx , tracer , temporalClient , & req ); err != nil {
237246 logger .Error (err , "Error initializing processing workflow." )
238247 }
239248 span .End ()
@@ -247,62 +256,36 @@ func main() {
247256 }
248257 }
249258
250- // Workflow and activity worker.
251- {
252- h := hooks .NewHooks (config .Hooks )
253-
254- done := make (chan struct {})
255- w := temporalsdk_worker .New (temporalClient , config .Temporal .TaskQueue , temporalsdk_worker.Options {
256- EnableSessionWorker : true ,
257- MaxConcurrentSessionExecutionSize : config .Worker .MaxConcurrentSessionExecutionSize ,
258- MaxConcurrentWorkflowTaskExecutionSize : config .Worker .MaxConcurrentWorkflowsExecutionsSize ,
259- MaxHeartbeatThrottleInterval : config .Worker .HeartbeatThrottleInterval ,
260- DefaultHeartbeatThrottleInterval : config .Worker .HeartbeatThrottleInterval ,
261- })
262- if err != nil {
263- logger .Error (err , "Error creating Temporal worker." )
264- os .Exit (1 )
259+ for _ , p := range pipelineRegistry .List () {
260+ if p .Status (ctx ) == "active" {
261+ logger .Info ("Creating worker and task queue" , "Pipeline" , p .TaskQueue )
262+ } else {
263+ logger .Error (errors .New ("Pipeline not active" ), "Cannot create worker and task queue for inactive pipeline" )
264+ continue
265265 }
266-
267- w .RegisterWorkflowWithOptions (workflow .NewProcessingWorkflow (h , colsvc , pipelineRegistry , logger , config .Workflow ).Execute , temporalsdk_workflow.RegisterOptions {Name : collection .ProcessingWorkflowName })
268- w .RegisterActivityWithOptions (activities .NewAcquirePipelineActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .AcquirePipelineActivityName })
269- w .RegisterActivityWithOptions (activities .NewDownloadActivity (h , pipelineRegistry , wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DownloadActivityName })
270- w .RegisterActivityWithOptions (archive .NewExtractActivity (config .ExtractActivity ).Execute , temporalsdk_activity.RegisterOptions {Name : archive .ExtractActivityName })
271- w .RegisterActivityWithOptions (activities .NewBundleActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .BundleActivityName })
272- w .RegisterActivityWithOptions (activities .NewValidateTransferActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .ValidateTransferActivityName })
273- w .RegisterActivityWithOptions (activities .NewTransferActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .TransferActivityName })
274- w .RegisterActivityWithOptions (activities .NewPollTransferActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PollTransferActivityName })
275- w .RegisterActivityWithOptions (activities .NewPollIngestActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PollIngestActivityName })
276- w .RegisterActivityWithOptions (activities .NewCleanUpActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .CleanUpActivityName })
277- w .RegisterActivityWithOptions (activities .NewHidePackageActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .HidePackageActivityName })
278- w .RegisterActivityWithOptions (activities .NewDeleteOriginalActivity (wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DeleteOriginalActivityName })
279- w .RegisterActivityWithOptions (activities .NewDisposeOriginalActivity (wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DisposeOriginalActivityName })
280- w .RegisterActivityWithOptions (activities .NewPopulateMetadataActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PopulateMetadataActivityName })
281-
282- w .RegisterActivityWithOptions (workflow .NewAsyncCompletionActivity (colsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : workflow .AsyncCompletionActivityName })
283- w .RegisterActivityWithOptions (nha_activities .NewUpdateHARIActivity (h ).Execute , temporalsdk_activity.RegisterOptions {Name : nha_activities .UpdateHARIActivityName })
284- w .RegisterActivityWithOptions (nha_activities .NewUpdateProductionSystemActivity (h ).Execute , temporalsdk_activity.RegisterOptions {Name : nha_activities .UpdateProductionSystemActivityName })
285-
286- w .RegisterWorkflowWithOptions (collection .BulkWorkflow , temporalsdk_workflow.RegisterOptions {Name : collection .BulkWorkflowName })
287- w .RegisterActivityWithOptions (collection .NewBulkActivity (colsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : collection .BulkActivityName })
288-
289- w .RegisterWorkflowWithOptions (batch .BatchWorkflow , temporalsdk_workflow.RegisterOptions {Name : batch .BatchWorkflowName })
290- w .RegisterActivityWithOptions (batch .NewBatchActivity (batchsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : batch .BatchActivityName })
291-
292- g .Add (
293- func () error {
294- if err := w .Start (); err != nil {
295- return err
296- }
297- <- done
298- return nil
299- },
300- func (err error ) {
301- w .Stop ()
302- close (done )
303- },
266+ registerWorker (
267+ p .TaskQueue ,
268+ temporalClient ,
269+ pipelineRegistry ,
270+ config ,
271+ colsvc ,
272+ wsvc ,
273+ batchsvc ,
274+ logger ,
275+ & g ,
304276 )
305277 }
278+ registerWorker (
279+ config .Temporal .TaskQueue ,
280+ temporalClient ,
281+ pipelineRegistry ,
282+ config ,
283+ colsvc ,
284+ wsvc ,
285+ batchsvc ,
286+ logger ,
287+ & g ,
288+ )
306289
307290 // Observability server.
308291 {
@@ -506,3 +489,66 @@ func initTracerProvider(ctx context.Context, logger logr.Logger, cfg TelemetryCo
506489
507490 return tp , shutdown , nil
508491}
492+
493+ func registerWorker (
494+ taskQueue string ,
495+ temporalClient temporalsdk_client.Client ,
496+ pipelineRegistry * pipeline.Registry ,
497+ config configuration ,
498+ colsvc collection.Service ,
499+ wsvc watcher.Service ,
500+ batchsvc batch.Service ,
501+ logger logr.Logger ,
502+ g * run.Group ,
503+ ) {
504+ // Workflow and activity worker.
505+ h := hooks .NewHooks (config .Hooks )
506+
507+ done := make (chan struct {})
508+ w := temporalsdk_worker .New (temporalClient , taskQueue , temporalsdk_worker.Options {
509+ EnableSessionWorker : true ,
510+ MaxConcurrentSessionExecutionSize : config .Worker .MaxConcurrentSessionExecutionSize ,
511+ MaxConcurrentWorkflowTaskExecutionSize : config .Worker .MaxConcurrentWorkflowsExecutionsSize ,
512+ MaxHeartbeatThrottleInterval : config .Worker .HeartbeatThrottleInterval ,
513+ DefaultHeartbeatThrottleInterval : config .Worker .HeartbeatThrottleInterval ,
514+ })
515+
516+ w .RegisterWorkflowWithOptions (workflow .NewProcessingWorkflow (h , colsvc , pipelineRegistry , logger , config .Workflow ).Execute , temporalsdk_workflow.RegisterOptions {Name : collection .ProcessingWorkflowName })
517+ w .RegisterActivityWithOptions (activities .NewAcquirePipelineActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .AcquirePipelineActivityName })
518+ w .RegisterActivityWithOptions (activities .NewDownloadActivity (h , pipelineRegistry , wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DownloadActivityName })
519+ w .RegisterActivityWithOptions (archive .NewExtractActivity (config .ExtractActivity ).Execute , temporalsdk_activity.RegisterOptions {Name : archive .ExtractActivityName })
520+ w .RegisterActivityWithOptions (activities .NewBundleActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .BundleActivityName })
521+ w .RegisterActivityWithOptions (activities .NewValidateTransferActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .ValidateTransferActivityName })
522+ w .RegisterActivityWithOptions (activities .NewTransferActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .TransferActivityName })
523+ w .RegisterActivityWithOptions (activities .NewPollTransferActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PollTransferActivityName })
524+ w .RegisterActivityWithOptions (activities .NewPollIngestActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PollIngestActivityName })
525+ w .RegisterActivityWithOptions (activities .NewCleanUpActivity ().Execute , temporalsdk_activity.RegisterOptions {Name : activities .CleanUpActivityName })
526+ w .RegisterActivityWithOptions (activities .NewHidePackageActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .HidePackageActivityName })
527+ w .RegisterActivityWithOptions (activities .NewDeleteOriginalActivity (wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DeleteOriginalActivityName })
528+ w .RegisterActivityWithOptions (activities .NewDisposeOriginalActivity (wsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .DisposeOriginalActivityName })
529+ w .RegisterActivityWithOptions (activities .NewPopulateMetadataActivity (pipelineRegistry ).Execute , temporalsdk_activity.RegisterOptions {Name : activities .PopulateMetadataActivityName })
530+
531+ w .RegisterActivityWithOptions (workflow .NewAsyncCompletionActivity (colsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : workflow .AsyncCompletionActivityName })
532+ w .RegisterActivityWithOptions (nha_activities .NewUpdateHARIActivity (h ).Execute , temporalsdk_activity.RegisterOptions {Name : nha_activities .UpdateHARIActivityName })
533+ w .RegisterActivityWithOptions (nha_activities .NewUpdateProductionSystemActivity (h ).Execute , temporalsdk_activity.RegisterOptions {Name : nha_activities .UpdateProductionSystemActivityName })
534+
535+ w .RegisterWorkflowWithOptions (collection .BulkWorkflow , temporalsdk_workflow.RegisterOptions {Name : collection .BulkWorkflowName })
536+ w .RegisterActivityWithOptions (collection .NewBulkActivity (colsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : collection .BulkActivityName })
537+
538+ w .RegisterWorkflowWithOptions (batch .BatchWorkflow , temporalsdk_workflow.RegisterOptions {Name : batch .BatchWorkflowName })
539+ w .RegisterActivityWithOptions (batch .NewBatchActivity (batchsvc ).Execute , temporalsdk_activity.RegisterOptions {Name : batch .BatchActivityName })
540+
541+ g .Add (
542+ func () error {
543+ if err := w .Start (); err != nil {
544+ return err
545+ }
546+ <- done
547+ return nil
548+ },
549+ func (err error ) {
550+ w .Stop ()
551+ close (done )
552+ },
553+ )
554+ }
0 commit comments