Repository: bacalhau-project/bacalhau (language: python)

Issue:
Add a --queue-timeout flag to docker run
Add a `--queue-timeout` flag to docker run to allow queueing with imperative job submissions



Discussion / hints:

Fix patch:
diff --git a/cmd/cli/helpers/helpers.go b/cmd/cli/helpers/helpers.go
index a26f9fe1b7..1f639a074c 100644
--- a/cmd/cli/helpers/helpers.go
+++ b/cmd/cli/helpers/helpers.go
@@ -46,7 +46,10 @@ func BuildJobFromFlags(
 			Type:    taskSettings.Network.Network,
 			Domains: taskSettings.Network.Domains,
 		}).
-		Timeouts(&models.TimeoutConfig{TotalTimeout: taskSettings.Timeout}).
+		Timeouts(&models.TimeoutConfig{
+			TotalTimeout: taskSettings.Timeout,
+			QueueTimeout: taskSettings.QueueTimeout,
+		}).
 		Build()
 	if err != nil {
 		return nil, fmt.Errorf("failed to create job: %w", err)
diff --git a/cmd/util/flags/cliflags/task.go b/cmd/util/flags/cliflags/task.go
index d45a269f88..07c05dba3b 100644
--- a/cmd/util/flags/cliflags/task.go
+++ b/cmd/util/flags/cliflags/task.go
@@ -47,6 +47,7 @@ type TaskSettings struct {
 	Resources            ResourceSettings
 	Network              NetworkSettings
 	Timeout              int64
+	QueueTimeout         int64
 }
 
 type ResourceSettings struct {
@@ -78,7 +79,8 @@ func DefaultTaskSettings() *TaskSettings {
 			Network: models.NetworkNone,
 			Domains: make([]string, 0),
 		},
-		Timeout: int64(time.Duration(0)),
+		Timeout:      int64(time.Duration(0)),
+		QueueTimeout: int64(time.Duration(0)),
 	}
 }
 
@@ -98,6 +100,9 @@ func RegisterTaskFlags(cmd *cobra.Command, s *TaskSettings) {
 	fs.Int64Var(&s.Timeout, "timeout", s.Timeout,
 		`Job execution timeout in seconds (e.g. 300 for 5 minutes)`,
 	)
-
+	fs.Int64Var(&s.QueueTimeout, "queue-timeout", s.QueueTimeout,
+		`Job queue timeout in seconds (e.g. 300 for 5 minutes). 
+zero timeout means no queueing is enabled and jobs will fail if they cannot be scheduled immediately`,
+	)
 	cmd.Flags().AddFlagSet(fs)
 }


Test patch:
diff --git a/cmd/cli/docker/docker_run_cli_test.go b/cmd/cli/docker/docker_run_cli_test.go
index 51d142e416..acbd56505c 100644
--- a/cmd/cli/docker/docker_run_cli_test.go
+++ b/cmd/cli/docker/docker_run_cli_test.go
@@ -45,7 +45,8 @@ var (
 		Domains: []string(nil),
 	}
 	expectedDefaultTimeoutConfig = &models.TimeoutConfig{
-		ExecutionTimeout: 0,
+		TotalTimeout: 0,
+		QueueTimeout: 0,
 	}
 )
 
@@ -447,6 +448,16 @@ func TestJobFlagParsing(t *testing.T) {
 			},
 			expectedError: false,
 		},
+		{
+			name:  "with queue timeout",
+			flags: []string{"--queue-timeout=300", "image:tag"},
+			assertJob: func(t *testing.T, j *models.Job) {
+				defaultJobAssertions(t, j)
+				task := j.Task()
+				assert.EqualValues(t, 300, task.Timeouts.QueueTimeout)
+			},
+			expectedError: false,
+		},
 		{
 			name:  "with ipfs publisher",
 			flags: []string{"--publisher=ipfs", "image:tag"},
diff --git a/cmd/cli/docker/docker_run_test.go b/cmd/cli/docker/docker_run_test.go
index dd8355694c..2a54543e89 100644
--- a/cmd/cli/docker/docker_run_test.go
+++ b/cmd/cli/docker/docker_run_test.go
@@ -511,10 +511,12 @@ func (s *DockerRunSuite) TestRun_Timeout_DefaultValue() {
 
 func (s *DockerRunSuite) TestRun_Timeout_DefinedValue() {
 	const expectedTimeout = 999 * time.Second
+	const expectedQueueTimeout = 888 * time.Second
 
 	ctx := context.Background()
 	_, out, err := s.ExecuteTestCobraCommand("docker", "run",
 		"--timeout", fmt.Sprintf("%d", int64(expectedTimeout.Seconds())),
+		"--queue-timeout", fmt.Sprintf("%d", int64(expectedQueueTimeout.Seconds())),
 		"ubuntu",
 		"echo", "'hello world'",
 	)
@@ -523,6 +525,7 @@ func (s *DockerRunSuite) TestRun_Timeout_DefinedValue() {
 	j := testutils.GetJobFromTestOutput(ctx, s.T(), s.ClientV2, out)
 
 	s.Require().Equal(expectedTimeout, j.Task().Timeouts.GetTotalTimeout())
+	s.Require().Equal(expectedQueueTimeout, j.Task().Timeouts.GetQueueTimeout())
 }
 
 func (s *DockerRunSuite) TestRun_NoPublisher() {