feat: add the ability to execute a cron task on the fly

Closes #4904
This commit is contained in:
Jose Diaz-Gonzalez
2023-07-02 04:53:16 -04:00
parent 798a413096
commit 515994c8d3
11 changed files with 144 additions and 2 deletions

View File

@@ -78,7 +78,7 @@ teardown() {
}
@test "(cron) create [single-verbose]" {
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_valid
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_valid_single
echo "output: $output"
echo "status: $status"
assert_success
@@ -197,6 +197,39 @@ teardown() {
assert_output_exists
}
@test "(cron) cron:run" {
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_valid
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_id"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_exists
run /bin/bash -c "dokku cron:run $TEST_APP $cron_id"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "['task.py', 'schedule']"
cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[1].id')"
run /bin/bash -c "echo $cron_id"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_exists
run /bin/bash -c "dokku cron:run $TEST_APP $cron_id"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "['task.py', 'schedule', 'now']"
}
template_cron_file_invalid() {
local APP="$1"
local APP_REPO_DIR="$2"
@@ -258,12 +291,32 @@ template_cron_file_valid() {
{
"command": "python task.py schedule",
"schedule": "5 5 5 5 5"
},
{
"command": "python task.py schedule now",
"schedule": "6 5 5 5 5"
}
]
}
EOF
}
template_cron_file_valid_single() {
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 <<EOF >"$APP_REPO_DIR/app.json"
{
"cron": [
{
"command": "python task.py schedule",
"schedule": "5 5 5 5 5"
}
]
}
EOF
}
template_cron_file_valid_short() {
local APP="$1"
local APP_REPO_DIR="$2"