diff --git a/docs/appendices/file-formats/app-json.md b/docs/appendices/file-formats/app-json.md index 842674376..b3cd72c7b 100644 --- a/docs/appendices/file-formats/app-json.md +++ b/docs/appendices/file-formats/app-json.md @@ -23,7 +23,7 @@ - `command`: (string, required) - `maintenance`: (boolean, optional) - `schedule`: (string, required) -- `concurrency_policy`: (string, optional, default: `allow`, options: `allow`, `deny`, `replace`) +- `concurrency_policy`: (string, optional, default: `allow`, options: `allow`, `forbid`, `replace`) ## Formation diff --git a/plugins/cron/subcommands.go b/plugins/cron/subcommands.go index 233361953..c47fa3289 100644 --- a/plugins/cron/subcommands.go +++ b/plugins/cron/subcommands.go @@ -42,7 +42,7 @@ func CommandList(appName string, format string) error { } if format == "stdout" { - output := []string{"ID | Schedule | Maintenance | Command"} + output := []string{"ID | Schedule | Concurrency | Maintenance | Command"} for _, task := range tasks { maintenance := "false" if task.Maintenance { @@ -52,7 +52,7 @@ func CommandList(appName string, format string) error { maintenance = "true (app)" } } - output = append(output, fmt.Sprintf("%s | %s | %s | %s", task.ID, task.Schedule, maintenance, task.Command)) + output = append(output, fmt.Sprintf("%s | %s | %s | %t | %s", task.ID, task.Schedule, task.ConcurrencyPolicy, maintenance, task.Command)) } result := columnize.SimpleFormat(output) diff --git a/plugins/scheduler-docker-local/scheduler-run b/plugins/scheduler-docker-local/scheduler-run index 096210dc3..0df116077 100755 --- a/plugins/scheduler-docker-local/scheduler-run +++ b/plugins/scheduler-docker-local/scheduler-run @@ -66,7 +66,6 @@ trigger-scheduler-docker-local-scheduler-run() { if [[ -n "$DOKKU_CONCURRENCY_POLICY" ]]; then concurrency_policy="$DOKKU_CONCURRENCY_POLICY" fi - concurrency_policy="$DOKKU_CONCURRENCY_POLICY" DOCKER_ARGS+=" --label=com.dokku.concurrency-policy=$concurrency_policy" if [[ "$concurrency_policy" == "forbid" ]]; then diff --git a/tests/unit/cron.bats b/tests/unit/cron.bats index 671e8f58f..fa5d8a0e4 100644 --- a/tests/unit/cron.bats +++ b/tests/unit/cron.bats @@ -235,6 +235,30 @@ teardown() { assert_output "['task.py', 'schedule', 'now']" } +@test "(cron) cron:run concurrency_policy forbid" { + run deploy_app dockerfile dokku@$DOKKU_DOMAIN:$TEST_APP template_cron_file_concurrency_forbid + echo "output: $output" + echo "status: $status" + assert_success + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo cron $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id --detach" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_failure +} + @test "(cron) cron:suspend cron:resume" { run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP template_cron_file_valid_multiple echo "output: $output" @@ -427,3 +451,21 @@ template_cron_file_valid_multiple() { } EOF } + +template_cron_file_concurrency_forbid() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + echo "injecting valid cron app.json -> $APP_REPO_DIR/app.json" + cat <"$APP_REPO_DIR/app.json" +{ + "cron": [ + { + "command": "sleep 5", + "schedule": "0 0 * * *", + "concurrency_policy": "forbid" + } + ] +} +EOF +}