go-admingo-admin
  • Guide
  • Development
    • Advanced
    • Commands
  • Advanced
  • Help
  • GitHub
  • Changelog
⌘ K
Standard Practice
Standard Module Development
Backend Basics
Backend Directory Structure
Backend Config File
Starting the Backend
Frontend Basics
Frontend Directory Structure
Frontend Config File
Starting the Frontend
Development Patterns
Actions Pattern
Hand-Written Pattern
First API Endpoint
Layered Development
API Layer
Service Layer
DTO Definitions
Model Definitions
Router Registration
Multi-Environment Config
Database Table Conventions
Data Permissions
Response Format
Code Generation
Pre-Generation Setup
Generating Business Code
One-Click Menu Generation
Binding APIs to the Menu
Configuring Role Permissions
Verifying the Feature
Generating Code with an LLM
Advanced Capabilities
Runtime Core API
Authentication & Authorization
Logging
Request Tracing
Cache
Queue
File Upload
Rate Limiting
Scheduled Jobs
Air Hot Reload
Swagger Docs
Code Generation Tool
Last updated:
Open-source MIT Licensed | Copyright © 2020-present
Powered by go-admin-team

TABLE OF CONTENTS

‌
‌
‌
‌

Scheduled Jobs

The system currently supports two job types — a function type and an HTTP type — to cover different kinds of work.

HttpJob (HTTP Type)

The HTTP type is the simpler of the two: just configure the endpoint URL and the run interval in the system.

ExecJob (Function Type)

The function type is for work that needs to be done in code — that's when you reach for this type.

The system ships an example: look in the jobs directory for examples.go, which contains sample code.

Here's a walkthrough of that example:

Step one: create a struct that implements the JobCore interface — for example, ExamplesOne, which implements the Exec method:

go
type ExamplesOne struct {
}
func (t ExamplesOne) Exec(arg interface{}) error {
str := "JobCore ExamplesOne exec success"
// TODO: note that Examples passes its argument as a string, so it's asserted as arg.(string); convert according to your actual type.
switch arg.(type) {
case string:
if arg.(string) != "" {
logger.Info(str, arg.(string))
} else {
logger.Warn(str, "arg is nil")
}
break
}
return nil
}

Step two: register the struct in InitJob — for example, ExamplesOne — using the struct's name as the key and the struct itself as the value. After that, restarting the project makes it available to configure and use in the system:

go
func InitJob() {
jobList = map[string]JobsExec{
"ExamplesOne": ExamplesOne{},
// ...
}
}

WARNING

Where to get help:

If anything in this guide is unclear, please open an issue.