feat: add initial scheduled task implementation

This functionality enables users to manage a global crontab for the Dokku user that contains all scheduled tasks across all apps. Alternative schedulers can implement cron tasks as desired.
This commit is contained in:
Jose Diaz-Gonzalez
2021-01-18 18:15:42 -05:00
parent e00e498e50
commit f7ef14d737
23 changed files with 1026 additions and 391 deletions

View File

@@ -0,0 +1,5 @@
def main(args):
print(args)
if __name__ == '__main__':
main(sys.argv)

95
tests/unit/cron.bats Normal file
View File

@@ -0,0 +1,95 @@
#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
}
teardown() {
destroy_app
global_teardown
}
@test "(cron) cron:help" {
run /bin/bash -c "dokku cron"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage scheduled cron tasks"
help_output="$output"
run /bin/bash -c "dokku cron:help"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage scheduled cron tasks"
assert_output "$help_output"
}
@test "(cron) invalid" {
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_invalid
echo "output: $output"
echo "status: $status"
assert_failure
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_invalid_schedule
echo "output: $output"
echo "status: $status"
assert_failure
run deploy_app python dokku@dokku.me:$TEST_APP template_cron_file_invalid_schedule_seconds
echo "output: $output"
echo "status: $status"
assert_failure
}
template_cron_file_invalid() {
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
echo "injecting invalid cron app.json -> $APP_REPO_DIR/app.json"
cat <<EOF >"$APP_REPO_DIR/app.json"
{
"cron": [
{
"key": "value"
}
]
}
EOF
}
template_cron_file_invalid_schedule() {
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
echo "injecting invalid cron app.json -> $APP_REPO_DIR/app.json"
cat <<EOF >"$APP_REPO_DIR/app.json"
{
"cron": [
{
"command": "python task.py",
"schedule": "@nonstandard"
}
]
}
EOF
}
template_cron_file_invalid_schedule_seconds() {
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
echo "injecting invalid cron app.json -> $APP_REPO_DIR/app.json"
cat <<EOF >"$APP_REPO_DIR/app.json"
{
"cron": [
{
"command": "python task.py",
"schedule": "0 5 * * * *"
}
]
}
EOF
}