9a5720e8ad
Branch Policy Check / Verify merge target (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
PR RC Release / Build RC Release (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cron
|
|
|
|
import (
|
|
"context"
|
|
|
|
user_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
actions_service "code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/actions"
|
|
)
|
|
|
|
func initActionsTasks() {
|
|
if !setting.Actions.Enabled {
|
|
return
|
|
}
|
|
registerStopZombieTasks()
|
|
registerStopEndlessTasks()
|
|
registerCancelAbandonedJobs()
|
|
registerScheduleTasks()
|
|
registerActionsCleanup()
|
|
}
|
|
|
|
func registerStopZombieTasks() {
|
|
RegisterTaskFatal("stop_zombie_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 5m",
|
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
|
return actions_service.StopZombieTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerStopEndlessTasks() {
|
|
RegisterTaskFatal("stop_endless_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 30m",
|
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
|
return actions_service.StopEndlessTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerCancelAbandonedJobs() {
|
|
RegisterTaskFatal("cancel_abandoned_jobs", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: true,
|
|
Schedule: "@every 6h",
|
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
|
return actions_service.CancelAbandonedJobs(ctx)
|
|
})
|
|
}
|
|
|
|
// registerScheduleTasks registers a scheduled task that runs every minute to start any due schedule tasks.
|
|
func registerScheduleTasks() {
|
|
// Register the task with a unique name, enabled status, and schedule for every minute.
|
|
RegisterTaskFatal("start_schedule_tasks", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: false,
|
|
Schedule: "@every 1m",
|
|
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
|
|
// Call the function to start schedule tasks and pass the context.
|
|
return actions_service.StartScheduleTasks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerActionsCleanup() {
|
|
RegisterTaskFatal("cleanup_actions", &BaseConfig{
|
|
Enabled: true,
|
|
RunAtStart: false,
|
|
Schedule: "@midnight",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return actions_service.Cleanup(ctx)
|
|
})
|
|
}
|