mirror of
https://github.com/mentos1386/zdravko.git
synced 2025-03-30 21:07:54 +00:00
feat: rename worker to worker-group
This commit is contained in:
parent
a9dd5a41b7
commit
6c960ba40a
38 changed files with 1051 additions and 1717 deletions
deploy
example.envinternal
justfilepkg
process-compose.ymltools/generate
web
|
@ -37,5 +37,5 @@ services:
|
||||||
image: ghcr.io/mentos1386/zdravko:main
|
image: ghcr.io/mentos1386/zdravko:main
|
||||||
command: ["--worker"]
|
command: ["--worker"]
|
||||||
environment:
|
environment:
|
||||||
- WORKER_TOKEN=change-me
|
- WORKER_GROUP_TOKEN=change-me
|
||||||
- WORKER_API_URL=http://server:8000
|
- WORKER_API_URL=http://server:8000
|
||||||
|
|
|
@ -12,7 +12,7 @@ JWT_PRIVATE_KEY=""
|
||||||
|
|
||||||
# To generate worker token, go to website and
|
# To generate worker token, go to website and
|
||||||
# create new worker. Then copy the token.
|
# create new worker. Then copy the token.
|
||||||
WORKER_TOKEN=""
|
WORKER_GROUP_TOKEN=""
|
||||||
|
|
||||||
# OAUTH2
|
# OAUTH2
|
||||||
# The redirect/callback url is ${ROOT_URL}/oauth2/callback
|
# The redirect/callback url is ${ROOT_URL}/oauth2/callback
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewWorkerConfig() *WorkerConfig {
|
||||||
v := newViper()
|
v := newViper()
|
||||||
|
|
||||||
// Set defaults
|
// Set defaults
|
||||||
v.SetDefault("token", os.Getenv("WORKER_TOKEN"))
|
v.SetDefault("token", os.Getenv("WORKER_GROUP_TOKEN"))
|
||||||
v.SetDefault("apiurl", GetEnvOrDefault("WORKER_API_URL", "http://localhost:8000"))
|
v.SetDefault("apiurl", GetEnvOrDefault("WORKER_API_URL", "http://localhost:8000"))
|
||||||
|
|
||||||
err := v.ReadInConfig()
|
err := v.ReadInConfig()
|
||||||
|
|
|
@ -5,21 +5,22 @@ import (
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate just _generate-gorm
|
//go:generate just _generate-gorm
|
||||||
func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
|
func ConnectToDatabase(path string) (*gorm.DB, *query.Query, error) {
|
||||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
|
||||||
|
Logger: logger.Default.LogMode(logger.Info),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.AutoMigrate(
|
err = db.AutoMigrate(
|
||||||
models.Worker{},
|
|
||||||
models.Monitor{},
|
models.Monitor{},
|
||||||
|
models.WorkerGroup{},
|
||||||
models.MonitorHistory{},
|
models.MonitorHistory{},
|
||||||
models.Cronjob{},
|
|
||||||
models.CronjobHistory{},
|
|
||||||
models.OAuth2State{},
|
models.OAuth2State{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -15,14 +15,13 @@ import (
|
||||||
type ApiV1WorkersConnectGETResponse struct {
|
type ApiV1WorkersConnectGETResponse struct {
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
Group string `json:"group"`
|
Group string `json:"group"`
|
||||||
Slug string `json:"slug"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *BaseHandler) ApiV1WorkersConnectGET(c echo.Context) error {
|
func (h *BaseHandler) ApiV1WorkersConnectGET(c echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cc := c.(AuthenticatedContext)
|
cc := c.(AuthenticatedContext)
|
||||||
|
|
||||||
worker, err := services.GetWorker(ctx, h.query, cc.Principal.Worker.Slug)
|
workerGroup, err := services.GetWorkerGroup(ctx, h.query, cc.Principal.Worker.Group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized, "Token invalid")
|
return echo.NewHTTPError(http.StatusUnauthorized, "Token invalid")
|
||||||
|
@ -32,8 +31,7 @@ func (h *BaseHandler) ApiV1WorkersConnectGET(c echo.Context) error {
|
||||||
|
|
||||||
response := ApiV1WorkersConnectGETResponse{
|
response := ApiV1WorkersConnectGETResponse{
|
||||||
Endpoint: h.config.Temporal.ServerHost,
|
Endpoint: h.config.Temporal.ServerHost,
|
||||||
Group: worker.Group,
|
Group: workerGroup.Slug,
|
||||||
Slug: worker.Slug,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, response)
|
return c.JSON(http.StatusOK, response)
|
||||||
|
|
|
@ -28,7 +28,6 @@ type AuthenticatedUser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthenticatedWorker struct {
|
type AuthenticatedWorker struct {
|
||||||
Slug string
|
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +99,9 @@ func (h *BaseHandler) AuthenticateRequestWithToken(r *http.Request) (*Authentica
|
||||||
|
|
||||||
if splitSubject[0] == "user" {
|
if splitSubject[0] == "user" {
|
||||||
user = &AuthenticatedUser{}
|
user = &AuthenticatedUser{}
|
||||||
} else if splitSubject[0] == "worker" {
|
} else if splitSubject[0] == "worker-group" {
|
||||||
worker = &AuthenticatedWorker{
|
worker = &AuthenticatedWorker{
|
||||||
Slug: splitSubject[1],
|
Group: splitSubject[1],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ var SettingsPages = []*components.Page{
|
||||||
{Path: "/settings", Title: "Overview", Breadcrumb: "Overview"},
|
{Path: "/settings", Title: "Overview", Breadcrumb: "Overview"},
|
||||||
{Path: "/settings/monitors", Title: "Monitors", Breadcrumb: "Monitors"},
|
{Path: "/settings/monitors", Title: "Monitors", Breadcrumb: "Monitors"},
|
||||||
{Path: "/settings/monitors/create", Title: "Monitors Create", Breadcrumb: "Create"},
|
{Path: "/settings/monitors/create", Title: "Monitors Create", Breadcrumb: "Create"},
|
||||||
{Path: "/settings/workers", Title: "Workers", Breadcrumb: "Workers"},
|
{Path: "/settings/worker-groups", Title: "Worker Groups", Breadcrumb: "Worker Groups"},
|
||||||
{Path: "/settings/workers/create", Title: "Workers Create", Breadcrumb: "Create"},
|
{Path: "/settings/worker-groups/create", Title: "Worker Groups Create", Breadcrumb: "Create"},
|
||||||
{Path: "/settings/notifications", Title: "Notifications", Breadcrumb: "Notifications"},
|
{Path: "/settings/notifications", Title: "Notifications", Breadcrumb: "Notifications"},
|
||||||
{Path: "/settings/temporal", Title: "Temporal", Breadcrumb: "Temporal"},
|
{Path: "/settings/temporal", Title: "Temporal", Breadcrumb: "Temporal"},
|
||||||
{Path: "/oauth2/logout", Title: "Logout", Breadcrumb: "Logout"},
|
{Path: "/oauth2/logout", Title: "Logout", Breadcrumb: "Logout"},
|
||||||
|
@ -42,7 +42,7 @@ var SettingsPages = []*components.Page{
|
||||||
var SettingsNavbar = []*components.Page{
|
var SettingsNavbar = []*components.Page{
|
||||||
GetPageByTitle(SettingsPages, "Overview"),
|
GetPageByTitle(SettingsPages, "Overview"),
|
||||||
GetPageByTitle(SettingsPages, "Monitors"),
|
GetPageByTitle(SettingsPages, "Monitors"),
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
GetPageByTitle(SettingsPages, "Notifications"),
|
GetPageByTitle(SettingsPages, "Notifications"),
|
||||||
GetPageByTitle(SettingsPages, "Temporal"),
|
GetPageByTitle(SettingsPages, "Temporal"),
|
||||||
GetPageByTitle(SettingsPages, "Logout"),
|
GetPageByTitle(SettingsPages, "Logout"),
|
||||||
|
|
|
@ -14,6 +14,19 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CreateMonitor struct {
|
||||||
|
Name string `validate:"required"`
|
||||||
|
WorkerGroups string `validate:"required"`
|
||||||
|
Schedule string `validate:"required,cron"`
|
||||||
|
Script string `validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateMonitor struct {
|
||||||
|
WorkerGroups string `validate:"required"`
|
||||||
|
Schedule string `validate:"required,cron"`
|
||||||
|
Script string `validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
type SettingsMonitors struct {
|
type SettingsMonitors struct {
|
||||||
*Settings
|
*Settings
|
||||||
Monitors []*models.Monitor
|
Monitors []*models.Monitor
|
||||||
|
@ -28,7 +41,7 @@ type SettingsMonitor struct {
|
||||||
func (h *BaseHandler) SettingsMonitorsGET(c echo.Context) error {
|
func (h *BaseHandler) SettingsMonitorsGET(c echo.Context) error {
|
||||||
cc := c.(AuthenticatedContext)
|
cc := c.(AuthenticatedContext)
|
||||||
|
|
||||||
monitors, err := h.query.Monitor.WithContext(context.Background()).Find()
|
monitors, err := services.GetMonitors(context.Background(), h.query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -72,42 +85,56 @@ func (h *BaseHandler) SettingsMonitorsDescribeGET(c echo.Context) error {
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsMonitorsDescribePOST(c echo.Context) error {
|
func (h *BaseHandler) SettingsMonitorsDescribePOST(c echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
monitorSlug := c.Param("slug")
|
||||||
|
|
||||||
slug := c.Param("slug")
|
update := UpdateMonitor{
|
||||||
|
WorkerGroups: strings.TrimSpace(c.FormValue("workergroups")),
|
||||||
monitor, err := services.GetMonitor(ctx, h.query, slug)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
update := &models.Monitor{
|
|
||||||
Slug: monitor.Slug,
|
|
||||||
Name: monitor.Name,
|
|
||||||
Schedule: c.FormValue("schedule"),
|
Schedule: c.FormValue("schedule"),
|
||||||
WorkerGroups: strings.Split(c.FormValue("workergroups"), " "),
|
|
||||||
Script: c.FormValue("script"),
|
Script: c.FormValue("script"),
|
||||||
}
|
}
|
||||||
|
err := validator.New(validator.WithRequiredStructEnabled()).Struct(update)
|
||||||
err = validator.New(validator.WithRequiredStructEnabled()).Struct(update)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monitor, err := services.GetMonitor(ctx, h.query, monitorSlug)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
monitor.Schedule = update.Schedule
|
||||||
|
monitor.Script = update.Script
|
||||||
|
|
||||||
err = services.UpdateMonitor(
|
err = services.UpdateMonitor(
|
||||||
ctx,
|
ctx,
|
||||||
h.query,
|
h.query,
|
||||||
update,
|
monitor,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workerGroups := []*models.WorkerGroup{}
|
||||||
|
for _, group := range strings.Split(update.WorkerGroups, " ") {
|
||||||
|
if group == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
workerGroup, err := services.GetOrCreateWorkerGroup(ctx, h.query, models.WorkerGroup{Name: group, Slug: slug.Make(group)})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
workerGroups = append(workerGroups, workerGroup)
|
||||||
|
}
|
||||||
|
err = services.UpdateMonitorWorkerGroups(ctx, h.query, monitor, workerGroups)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = services.CreateOrUpdateMonitorSchedule(ctx, h.temporal, monitor)
|
err = services.CreateOrUpdateMonitorSchedule(ctx, h.temporal, monitor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/settings/monitors/%s", slug))
|
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/settings/monitors/%s", monitorSlug))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsMonitorsCreateGET(c echo.Context) error {
|
func (h *BaseHandler) SettingsMonitorsCreateGET(c echo.Context) error {
|
||||||
|
@ -125,33 +152,45 @@ func (h *BaseHandler) SettingsMonitorsCreateGET(c echo.Context) error {
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsMonitorsCreatePOST(c echo.Context) error {
|
func (h *BaseHandler) SettingsMonitorsCreatePOST(c echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
monitorSlug := slug.Make(c.FormValue("name"))
|
||||||
|
|
||||||
monitorHttp := &models.Monitor{
|
create := CreateMonitor{
|
||||||
Name: c.FormValue("name"),
|
Name: c.FormValue("name"),
|
||||||
Slug: slug.Make(c.FormValue("name")),
|
|
||||||
Schedule: c.FormValue("schedule"),
|
Schedule: c.FormValue("schedule"),
|
||||||
WorkerGroups: strings.Split(c.FormValue("workergroups"), " "),
|
WorkerGroups: c.FormValue("workergroups"),
|
||||||
Script: c.FormValue("script"),
|
Script: c.FormValue("script"),
|
||||||
}
|
}
|
||||||
|
err := validator.New(validator.WithRequiredStructEnabled()).Struct(create)
|
||||||
err := validator.New(validator.WithRequiredStructEnabled()).Struct(monitorHttp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workerGroups := []models.WorkerGroup{}
|
||||||
|
for _, group := range strings.Split(create.WorkerGroups, " ") {
|
||||||
|
workerGroups = append(workerGroups, models.WorkerGroup{Name: group, Slug: slug.Make(group)})
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor := &models.Monitor{
|
||||||
|
Name: create.Name,
|
||||||
|
Slug: monitorSlug,
|
||||||
|
Schedule: create.Schedule,
|
||||||
|
Script: create.Script,
|
||||||
|
WorkerGroups: workerGroups,
|
||||||
|
}
|
||||||
|
|
||||||
err = services.CreateMonitor(
|
err = services.CreateMonitor(
|
||||||
ctx,
|
ctx,
|
||||||
h.query,
|
h.query,
|
||||||
monitorHttp,
|
monitor,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = services.CreateOrUpdateMonitorSchedule(ctx, h.temporal, monitorHttp)
|
err = services.CreateOrUpdateMonitorSchedule(ctx, h.temporal, monitor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Redirect(http.StatusSeeOther, "/settings/monitors")
|
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/settings/monitors/%s", monitorSlug))
|
||||||
}
|
}
|
||||||
|
|
124
internal/handlers/settingsworkergroups.go
Normal file
124
internal/handlers/settingsworkergroups.go
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/jwt"
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/services"
|
||||||
|
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/gosimple/slug"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WorkerWithToken struct {
|
||||||
|
*models.WorkerGroup
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SettingsWorkerGroups struct {
|
||||||
|
*Settings
|
||||||
|
WorkerGroups []*models.WorkerGroup
|
||||||
|
WorkerGroupsLength int
|
||||||
|
}
|
||||||
|
|
||||||
|
type SettingsWorker struct {
|
||||||
|
*Settings
|
||||||
|
Worker *WorkerWithToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) SettingsWorkerGroupsGET(c echo.Context) error {
|
||||||
|
cc := c.(AuthenticatedContext)
|
||||||
|
|
||||||
|
workerGroups, err := services.GetWorkerGroups(context.Background(), h.query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render(http.StatusOK, "settings_worker_groups.tmpl", &SettingsWorkerGroups{
|
||||||
|
Settings: NewSettings(
|
||||||
|
cc.Principal.User,
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
|
[]*components.Page{GetPageByTitle(SettingsPages, "Worker Groups")},
|
||||||
|
),
|
||||||
|
WorkerGroups: workerGroups,
|
||||||
|
WorkerGroupsLength: len(workerGroups),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) SettingsWorkerGroupsDescribeGET(c echo.Context) error {
|
||||||
|
cc := c.(AuthenticatedContext)
|
||||||
|
|
||||||
|
slug := c.Param("slug")
|
||||||
|
|
||||||
|
worker, err := services.GetWorkerGroup(context.Background(), h.query, slug)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow write access to default namespace
|
||||||
|
token, err := jwt.NewTokenForWorker(h.config.Jwt.PrivateKey, h.config.Jwt.PublicKey, worker)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Render(http.StatusOK, "settings_worker_groups_describe.tmpl", &SettingsWorker{
|
||||||
|
Settings: NewSettings(
|
||||||
|
cc.Principal.User,
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
|
[]*components.Page{
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
|
{
|
||||||
|
Path: fmt.Sprintf("/settings/worker-groups/%s", slug),
|
||||||
|
Title: "Describe",
|
||||||
|
Breadcrumb: worker.Name,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Worker: &WorkerWithToken{
|
||||||
|
WorkerGroup: worker,
|
||||||
|
Token: token,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) SettingsWorkerGroupsCreateGET(c echo.Context) error {
|
||||||
|
cc := c.(AuthenticatedContext)
|
||||||
|
|
||||||
|
return c.Render(http.StatusOK, "settings_worker_groups_create.tmpl", NewSettings(
|
||||||
|
cc.Principal.User,
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
|
[]*components.Page{
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
||||||
|
GetPageByTitle(SettingsPages, "Worker Groups Create"),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BaseHandler) SettingsWorkerGroupsCreatePOST(c echo.Context) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
slug := slug.Make(c.FormValue("name"))
|
||||||
|
|
||||||
|
worker := models.WorkerGroup{
|
||||||
|
Name: c.FormValue("name"),
|
||||||
|
Slug: slug,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := validator.New(validator.WithRequiredStructEnabled()).Struct(worker)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = services.GetOrCreateWorkerGroup(
|
||||||
|
ctx,
|
||||||
|
h.query,
|
||||||
|
worker,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/settings/worker-groups/%s", slug))
|
||||||
|
}
|
|
@ -1,124 +0,0 @@
|
||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/jwt"
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/services"
|
|
||||||
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
"github.com/gosimple/slug"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WorkerWithToken struct {
|
|
||||||
*models.Worker
|
|
||||||
Token string
|
|
||||||
}
|
|
||||||
|
|
||||||
type SettingsWorkers struct {
|
|
||||||
*Settings
|
|
||||||
Workers []*models.Worker
|
|
||||||
WorkersLength int
|
|
||||||
}
|
|
||||||
|
|
||||||
type SettingsWorker struct {
|
|
||||||
*Settings
|
|
||||||
Worker *WorkerWithToken
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsWorkersGET(c echo.Context) error {
|
|
||||||
cc := c.(AuthenticatedContext)
|
|
||||||
|
|
||||||
workers, err := h.query.Worker.WithContext(context.Background()).Find()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render(http.StatusOK, "settings_workers.tmpl", &SettingsWorkers{
|
|
||||||
Settings: NewSettings(
|
|
||||||
cc.Principal.User,
|
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
|
||||||
[]*components.Page{GetPageByTitle(SettingsPages, "Workers")},
|
|
||||||
),
|
|
||||||
Workers: workers,
|
|
||||||
WorkersLength: len(workers),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsWorkersDescribeGET(c echo.Context) error {
|
|
||||||
cc := c.(AuthenticatedContext)
|
|
||||||
|
|
||||||
slug := c.Param("slug")
|
|
||||||
|
|
||||||
worker, err := services.GetWorker(context.Background(), h.query, slug)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow write access to default namespace
|
|
||||||
token, err := jwt.NewTokenForWorker(h.config.Jwt.PrivateKey, h.config.Jwt.PublicKey, worker)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Render(http.StatusOK, "settings_workers_describe.tmpl", &SettingsWorker{
|
|
||||||
Settings: NewSettings(
|
|
||||||
cc.Principal.User,
|
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
|
||||||
[]*components.Page{
|
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
|
||||||
{
|
|
||||||
Path: fmt.Sprintf("/settings/workers/%s", slug),
|
|
||||||
Title: "Describe",
|
|
||||||
Breadcrumb: worker.Name,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
Worker: &WorkerWithToken{
|
|
||||||
Worker: worker,
|
|
||||||
Token: token,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsWorkersCreateGET(c echo.Context) error {
|
|
||||||
cc := c.(AuthenticatedContext)
|
|
||||||
|
|
||||||
return c.Render(http.StatusOK, "settings_workers_create.tmpl", NewSettings(
|
|
||||||
cc.Principal.User,
|
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
|
||||||
[]*components.Page{
|
|
||||||
GetPageByTitle(SettingsPages, "Workers"),
|
|
||||||
GetPageByTitle(SettingsPages, "Workers Create"),
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *BaseHandler) SettingsWorkersCreatePOST(c echo.Context) error {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
worker := &models.Worker{
|
|
||||||
Name: c.FormValue("name"),
|
|
||||||
Slug: slug.Make(c.FormValue("name")),
|
|
||||||
Group: c.FormValue("group"),
|
|
||||||
}
|
|
||||||
|
|
||||||
err := validator.New(validator.WithRequiredStructEnabled()).Struct(worker)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = services.CreateWorker(
|
|
||||||
ctx,
|
|
||||||
h.query,
|
|
||||||
worker,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Redirect(http.StatusSeeOther, "/settings/workers")
|
|
||||||
}
|
|
|
@ -71,7 +71,7 @@ func NewTokenForServer(privateKey string, publicKey string) (string, error) {
|
||||||
return NewToken(privateKey, publicKey, claims)
|
return NewToken(privateKey, publicKey, claims)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTokenForWorker(privateKey string, publicKey string, worker *models.Worker) (string, error) {
|
func NewTokenForWorker(privateKey string, publicKey string, workerGroup *models.WorkerGroup) (string, error) {
|
||||||
// Create claims with multiple fields populated
|
// Create claims with multiple fields populated
|
||||||
claims := Claims{
|
claims := Claims{
|
||||||
jwt.RegisteredClaims{
|
jwt.RegisteredClaims{
|
||||||
|
@ -79,7 +79,7 @@ func NewTokenForWorker(privateKey string, publicKey string, worker *models.Worke
|
||||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||||
Issuer: "zdravko",
|
Issuer: "zdravko",
|
||||||
Subject: "worker:" + worker.Slug,
|
Subject: "worker-group:" + workerGroup.Slug,
|
||||||
},
|
},
|
||||||
// Ref: https://docs.temporal.io/self-hosted-guide/security#authorization
|
// Ref: https://docs.temporal.io/self-hosted-guide/security#authorization
|
||||||
[]string{"default:read", "default:write", "default:worker"},
|
[]string{"default:read", "default:write", "default:worker"},
|
||||||
|
|
|
@ -3,7 +3,6 @@ package models
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,14 +11,6 @@ type OAuth2State struct {
|
||||||
Expiry time.Time
|
Expiry time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Worker struct {
|
|
||||||
gorm.Model
|
|
||||||
Name string `gorm:"unique" validate:"required"`
|
|
||||||
Slug string `gorm:"unique"`
|
|
||||||
Group string `validate:"required"`
|
|
||||||
Status string
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MonitorSuccess string = "SUCCESS"
|
MonitorSuccess string = "SUCCESS"
|
||||||
MonitorFailure string = "FAILURE"
|
MonitorFailure string = "FAILURE"
|
||||||
|
@ -30,33 +21,27 @@ const (
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Slug string `gorm:"unique"`
|
Slug string `gorm:"unique"`
|
||||||
Name string `gorm:"unique" validate:"required"`
|
Name string `gorm:"unique"`
|
||||||
|
|
||||||
Schedule string `validate:"required,cron"`
|
Schedule string
|
||||||
WorkerGroups pq.StringArray `gorm:"type:text[]"`
|
WorkerGroups []WorkerGroup `gorm:"many2many:monitor_worker_groups;"`
|
||||||
|
|
||||||
Script string `validate:"required"`
|
Script string `validate:"required"`
|
||||||
|
|
||||||
History []MonitorHistory `gorm:"foreignKey:Monitor"`
|
History []MonitorHistory `gorm:"foreignKey:Monitor"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cronjob struct {
|
|
||||||
gorm.Model
|
|
||||||
Slug string `gorm:"unique"`
|
|
||||||
Name string `gorm:"unique"`
|
|
||||||
Schedule string
|
|
||||||
Buffer int
|
|
||||||
}
|
|
||||||
|
|
||||||
type MonitorHistory struct {
|
type MonitorHistory struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Monitor uint
|
Monitor uint
|
||||||
Status string
|
Status string
|
||||||
Note string
|
Note string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CronjobHistory struct {
|
type WorkerGroup struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Cronjob Cronjob `gorm:"foreignkey:ID"`
|
Name string `gorm:"unique"`
|
||||||
Status string
|
Slug string `gorm:"unique"`
|
||||||
|
|
||||||
|
Monitors []Monitor `gorm:"many2many:monitor_worker_groups;"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,486 +0,0 @@
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package query
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
"gorm.io/gorm/schema"
|
|
||||||
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gen/field"
|
|
||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newCronjobHistory(db *gorm.DB, opts ...gen.DOOption) cronjobHistory {
|
|
||||||
_cronjobHistory := cronjobHistory{}
|
|
||||||
|
|
||||||
_cronjobHistory.cronjobHistoryDo.UseDB(db, opts...)
|
|
||||||
_cronjobHistory.cronjobHistoryDo.UseModel(&models.CronjobHistory{})
|
|
||||||
|
|
||||||
tableName := _cronjobHistory.cronjobHistoryDo.TableName()
|
|
||||||
_cronjobHistory.ALL = field.NewAsterisk(tableName)
|
|
||||||
_cronjobHistory.ID = field.NewUint(tableName, "id")
|
|
||||||
_cronjobHistory.CreatedAt = field.NewTime(tableName, "created_at")
|
|
||||||
_cronjobHistory.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
||||||
_cronjobHistory.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
||||||
_cronjobHistory.Status = field.NewString(tableName, "status")
|
|
||||||
_cronjobHistory.Cronjob = cronjobHistoryHasOneCronjob{
|
|
||||||
db: db.Session(&gorm.Session{}),
|
|
||||||
|
|
||||||
RelationField: field.NewRelation("Cronjob", "models.Cronjob"),
|
|
||||||
}
|
|
||||||
|
|
||||||
_cronjobHistory.fillFieldMap()
|
|
||||||
|
|
||||||
return _cronjobHistory
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjobHistory struct {
|
|
||||||
cronjobHistoryDo cronjobHistoryDo
|
|
||||||
|
|
||||||
ALL field.Asterisk
|
|
||||||
ID field.Uint
|
|
||||||
CreatedAt field.Time
|
|
||||||
UpdatedAt field.Time
|
|
||||||
DeletedAt field.Field
|
|
||||||
Status field.String
|
|
||||||
Cronjob cronjobHistoryHasOneCronjob
|
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistory) Table(newTableName string) *cronjobHistory {
|
|
||||||
c.cronjobHistoryDo.UseTable(newTableName)
|
|
||||||
return c.updateTableName(newTableName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistory) As(alias string) *cronjobHistory {
|
|
||||||
c.cronjobHistoryDo.DO = *(c.cronjobHistoryDo.As(alias).(*gen.DO))
|
|
||||||
return c.updateTableName(alias)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobHistory) updateTableName(table string) *cronjobHistory {
|
|
||||||
c.ALL = field.NewAsterisk(table)
|
|
||||||
c.ID = field.NewUint(table, "id")
|
|
||||||
c.CreatedAt = field.NewTime(table, "created_at")
|
|
||||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
|
||||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
|
||||||
c.Status = field.NewString(table, "status")
|
|
||||||
|
|
||||||
c.fillFieldMap()
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobHistory) WithContext(ctx context.Context) ICronjobHistoryDo {
|
|
||||||
return c.cronjobHistoryDo.WithContext(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistory) TableName() string { return c.cronjobHistoryDo.TableName() }
|
|
||||||
|
|
||||||
func (c cronjobHistory) Alias() string { return c.cronjobHistoryDo.Alias() }
|
|
||||||
|
|
||||||
func (c cronjobHistory) Columns(cols ...field.Expr) gen.Columns {
|
|
||||||
return c.cronjobHistoryDo.Columns(cols...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobHistory) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
||||||
_f, ok := c.fieldMap[fieldName]
|
|
||||||
if !ok || _f == nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
_oe, ok := _f.(field.OrderExpr)
|
|
||||||
return _oe, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobHistory) fillFieldMap() {
|
|
||||||
c.fieldMap = make(map[string]field.Expr, 6)
|
|
||||||
c.fieldMap["id"] = c.ID
|
|
||||||
c.fieldMap["created_at"] = c.CreatedAt
|
|
||||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
|
||||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
|
||||||
c.fieldMap["status"] = c.Status
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistory) clone(db *gorm.DB) cronjobHistory {
|
|
||||||
c.cronjobHistoryDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistory) replaceDB(db *gorm.DB) cronjobHistory {
|
|
||||||
c.cronjobHistoryDo.ReplaceDB(db)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjobHistoryHasOneCronjob struct {
|
|
||||||
db *gorm.DB
|
|
||||||
|
|
||||||
field.RelationField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjob) Where(conds ...field.Expr) *cronjobHistoryHasOneCronjob {
|
|
||||||
if len(conds) == 0 {
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
exprs := make([]clause.Expression, 0, len(conds))
|
|
||||||
for _, cond := range conds {
|
|
||||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
||||||
}
|
|
||||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjob) WithContext(ctx context.Context) *cronjobHistoryHasOneCronjob {
|
|
||||||
a.db = a.db.WithContext(ctx)
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjob) Session(session *gorm.Session) *cronjobHistoryHasOneCronjob {
|
|
||||||
a.db = a.db.Session(session)
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjob) Model(m *models.CronjobHistory) *cronjobHistoryHasOneCronjobTx {
|
|
||||||
return &cronjobHistoryHasOneCronjobTx{a.db.Model(m).Association(a.Name())}
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjobHistoryHasOneCronjobTx struct{ tx *gorm.Association }
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Find() (result *models.Cronjob, err error) {
|
|
||||||
return result, a.tx.Find(&result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Append(values ...*models.Cronjob) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Append(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Replace(values ...*models.Cronjob) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Replace(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Delete(values ...*models.Cronjob) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Delete(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Clear() error {
|
|
||||||
return a.tx.Clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a cronjobHistoryHasOneCronjobTx) Count() int64 {
|
|
||||||
return a.tx.Count()
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjobHistoryDo struct{ gen.DO }
|
|
||||||
|
|
||||||
type ICronjobHistoryDo interface {
|
|
||||||
gen.SubQuery
|
|
||||||
Debug() ICronjobHistoryDo
|
|
||||||
WithContext(ctx context.Context) ICronjobHistoryDo
|
|
||||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
||||||
ReplaceDB(db *gorm.DB)
|
|
||||||
ReadDB() ICronjobHistoryDo
|
|
||||||
WriteDB() ICronjobHistoryDo
|
|
||||||
As(alias string) gen.Dao
|
|
||||||
Session(config *gorm.Session) ICronjobHistoryDo
|
|
||||||
Columns(cols ...field.Expr) gen.Columns
|
|
||||||
Clauses(conds ...clause.Expression) ICronjobHistoryDo
|
|
||||||
Not(conds ...gen.Condition) ICronjobHistoryDo
|
|
||||||
Or(conds ...gen.Condition) ICronjobHistoryDo
|
|
||||||
Select(conds ...field.Expr) ICronjobHistoryDo
|
|
||||||
Where(conds ...gen.Condition) ICronjobHistoryDo
|
|
||||||
Order(conds ...field.Expr) ICronjobHistoryDo
|
|
||||||
Distinct(cols ...field.Expr) ICronjobHistoryDo
|
|
||||||
Omit(cols ...field.Expr) ICronjobHistoryDo
|
|
||||||
Join(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
|
|
||||||
LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
|
|
||||||
RightJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo
|
|
||||||
Group(cols ...field.Expr) ICronjobHistoryDo
|
|
||||||
Having(conds ...gen.Condition) ICronjobHistoryDo
|
|
||||||
Limit(limit int) ICronjobHistoryDo
|
|
||||||
Offset(offset int) ICronjobHistoryDo
|
|
||||||
Count() (count int64, err error)
|
|
||||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobHistoryDo
|
|
||||||
Unscoped() ICronjobHistoryDo
|
|
||||||
Create(values ...*models.CronjobHistory) error
|
|
||||||
CreateInBatches(values []*models.CronjobHistory, batchSize int) error
|
|
||||||
Save(values ...*models.CronjobHistory) error
|
|
||||||
First() (*models.CronjobHistory, error)
|
|
||||||
Take() (*models.CronjobHistory, error)
|
|
||||||
Last() (*models.CronjobHistory, error)
|
|
||||||
Find() ([]*models.CronjobHistory, error)
|
|
||||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CronjobHistory, err error)
|
|
||||||
FindInBatches(result *[]*models.CronjobHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
||||||
Pluck(column field.Expr, dest interface{}) error
|
|
||||||
Delete(...*models.CronjobHistory) (info gen.ResultInfo, err error)
|
|
||||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
||||||
Attrs(attrs ...field.AssignExpr) ICronjobHistoryDo
|
|
||||||
Assign(attrs ...field.AssignExpr) ICronjobHistoryDo
|
|
||||||
Joins(fields ...field.RelationField) ICronjobHistoryDo
|
|
||||||
Preload(fields ...field.RelationField) ICronjobHistoryDo
|
|
||||||
FirstOrInit() (*models.CronjobHistory, error)
|
|
||||||
FirstOrCreate() (*models.CronjobHistory, error)
|
|
||||||
FindByPage(offset int, limit int) (result []*models.CronjobHistory, count int64, err error)
|
|
||||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
||||||
Scan(result interface{}) (err error)
|
|
||||||
Returning(value interface{}, columns ...string) ICronjobHistoryDo
|
|
||||||
UnderlyingDB() *gorm.DB
|
|
||||||
schema.Tabler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Debug() ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Debug())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) WithContext(ctx context.Context) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.WithContext(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) ReadDB() ICronjobHistoryDo {
|
|
||||||
return c.Clauses(dbresolver.Read)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) WriteDB() ICronjobHistoryDo {
|
|
||||||
return c.Clauses(dbresolver.Write)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Session(config *gorm.Session) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Session(config))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Clauses(conds ...clause.Expression) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Clauses(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Returning(value interface{}, columns ...string) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Returning(value, columns...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Not(conds ...gen.Condition) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Not(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Or(conds ...gen.Condition) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Or(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Select(conds ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Select(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Where(conds ...gen.Condition) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Where(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Order(conds ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Order(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Distinct(cols ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Distinct(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Omit(cols ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Omit(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Join(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Join(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) RightJoin(table schema.Tabler, on ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.RightJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Group(cols ...field.Expr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Group(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Having(conds ...gen.Condition) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Having(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Limit(limit int) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Limit(limit))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Offset(offset int) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Offset(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Scopes(funcs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Unscoped() ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Unscoped())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Create(values ...*models.CronjobHistory) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DO.Create(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) CreateInBatches(values []*models.CronjobHistory, batchSize int) error {
|
|
||||||
return c.DO.CreateInBatches(values, batchSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save : !!! underlying implementation is different with GORM
|
|
||||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
|
||||||
func (c cronjobHistoryDo) Save(values ...*models.CronjobHistory) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DO.Save(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) First() (*models.CronjobHistory, error) {
|
|
||||||
if result, err := c.DO.First(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.CronjobHistory), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Take() (*models.CronjobHistory, error) {
|
|
||||||
if result, err := c.DO.Take(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.CronjobHistory), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Last() (*models.CronjobHistory, error) {
|
|
||||||
if result, err := c.DO.Last(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.CronjobHistory), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Find() ([]*models.CronjobHistory, error) {
|
|
||||||
result, err := c.DO.Find()
|
|
||||||
return result.([]*models.CronjobHistory), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.CronjobHistory, err error) {
|
|
||||||
buf := make([]*models.CronjobHistory, 0, batchSize)
|
|
||||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
|
||||||
defer func() { results = append(results, buf...) }()
|
|
||||||
return fc(tx, batch)
|
|
||||||
})
|
|
||||||
return results, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) FindInBatches(result *[]*models.CronjobHistory, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
||||||
return c.DO.FindInBatches(result, batchSize, fc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Attrs(attrs ...field.AssignExpr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Attrs(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Assign(attrs ...field.AssignExpr) ICronjobHistoryDo {
|
|
||||||
return c.withDO(c.DO.Assign(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Joins(fields ...field.RelationField) ICronjobHistoryDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
c = *c.withDO(c.DO.Joins(_f))
|
|
||||||
}
|
|
||||||
return &c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Preload(fields ...field.RelationField) ICronjobHistoryDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
c = *c.withDO(c.DO.Preload(_f))
|
|
||||||
}
|
|
||||||
return &c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) FirstOrInit() (*models.CronjobHistory, error) {
|
|
||||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.CronjobHistory), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) FirstOrCreate() (*models.CronjobHistory, error) {
|
|
||||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.CronjobHistory), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) FindByPage(offset int, limit int) (result []*models.CronjobHistory, count int64, err error) {
|
|
||||||
result, err = c.Offset(offset).Limit(limit).Find()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
|
||||||
count = int64(size + offset)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err = c.Offset(-1).Limit(-1).Count()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
||||||
count, err = c.Count()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Scan(result interface{}) (err error) {
|
|
||||||
return c.DO.Scan(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobHistoryDo) Delete(models ...*models.CronjobHistory) (result gen.ResultInfo, err error) {
|
|
||||||
return c.DO.Delete(models)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobHistoryDo) withDO(do gen.Dao) *cronjobHistoryDo {
|
|
||||||
c.DO = *do.(*gen.DO)
|
|
||||||
return c
|
|
||||||
}
|
|
|
@ -1,416 +0,0 @@
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package query
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
"gorm.io/gorm/schema"
|
|
||||||
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gen/field"
|
|
||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newCronjob(db *gorm.DB, opts ...gen.DOOption) cronjob {
|
|
||||||
_cronjob := cronjob{}
|
|
||||||
|
|
||||||
_cronjob.cronjobDo.UseDB(db, opts...)
|
|
||||||
_cronjob.cronjobDo.UseModel(&models.Cronjob{})
|
|
||||||
|
|
||||||
tableName := _cronjob.cronjobDo.TableName()
|
|
||||||
_cronjob.ALL = field.NewAsterisk(tableName)
|
|
||||||
_cronjob.ID = field.NewUint(tableName, "id")
|
|
||||||
_cronjob.CreatedAt = field.NewTime(tableName, "created_at")
|
|
||||||
_cronjob.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
||||||
_cronjob.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
||||||
_cronjob.Slug = field.NewString(tableName, "slug")
|
|
||||||
_cronjob.Name = field.NewString(tableName, "name")
|
|
||||||
_cronjob.Schedule = field.NewString(tableName, "schedule")
|
|
||||||
_cronjob.Buffer = field.NewInt(tableName, "buffer")
|
|
||||||
|
|
||||||
_cronjob.fillFieldMap()
|
|
||||||
|
|
||||||
return _cronjob
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjob struct {
|
|
||||||
cronjobDo cronjobDo
|
|
||||||
|
|
||||||
ALL field.Asterisk
|
|
||||||
ID field.Uint
|
|
||||||
CreatedAt field.Time
|
|
||||||
UpdatedAt field.Time
|
|
||||||
DeletedAt field.Field
|
|
||||||
Slug field.String
|
|
||||||
Name field.String
|
|
||||||
Schedule field.String
|
|
||||||
Buffer field.Int
|
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjob) Table(newTableName string) *cronjob {
|
|
||||||
c.cronjobDo.UseTable(newTableName)
|
|
||||||
return c.updateTableName(newTableName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjob) As(alias string) *cronjob {
|
|
||||||
c.cronjobDo.DO = *(c.cronjobDo.As(alias).(*gen.DO))
|
|
||||||
return c.updateTableName(alias)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjob) updateTableName(table string) *cronjob {
|
|
||||||
c.ALL = field.NewAsterisk(table)
|
|
||||||
c.ID = field.NewUint(table, "id")
|
|
||||||
c.CreatedAt = field.NewTime(table, "created_at")
|
|
||||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
|
||||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
|
||||||
c.Slug = field.NewString(table, "slug")
|
|
||||||
c.Name = field.NewString(table, "name")
|
|
||||||
c.Schedule = field.NewString(table, "schedule")
|
|
||||||
c.Buffer = field.NewInt(table, "buffer")
|
|
||||||
|
|
||||||
c.fillFieldMap()
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjob) WithContext(ctx context.Context) ICronjobDo { return c.cronjobDo.WithContext(ctx) }
|
|
||||||
|
|
||||||
func (c cronjob) TableName() string { return c.cronjobDo.TableName() }
|
|
||||||
|
|
||||||
func (c cronjob) Alias() string { return c.cronjobDo.Alias() }
|
|
||||||
|
|
||||||
func (c cronjob) Columns(cols ...field.Expr) gen.Columns { return c.cronjobDo.Columns(cols...) }
|
|
||||||
|
|
||||||
func (c *cronjob) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
||||||
_f, ok := c.fieldMap[fieldName]
|
|
||||||
if !ok || _f == nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
_oe, ok := _f.(field.OrderExpr)
|
|
||||||
return _oe, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjob) fillFieldMap() {
|
|
||||||
c.fieldMap = make(map[string]field.Expr, 8)
|
|
||||||
c.fieldMap["id"] = c.ID
|
|
||||||
c.fieldMap["created_at"] = c.CreatedAt
|
|
||||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
|
||||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
|
||||||
c.fieldMap["slug"] = c.Slug
|
|
||||||
c.fieldMap["name"] = c.Name
|
|
||||||
c.fieldMap["schedule"] = c.Schedule
|
|
||||||
c.fieldMap["buffer"] = c.Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjob) clone(db *gorm.DB) cronjob {
|
|
||||||
c.cronjobDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjob) replaceDB(db *gorm.DB) cronjob {
|
|
||||||
c.cronjobDo.ReplaceDB(db)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
type cronjobDo struct{ gen.DO }
|
|
||||||
|
|
||||||
type ICronjobDo interface {
|
|
||||||
gen.SubQuery
|
|
||||||
Debug() ICronjobDo
|
|
||||||
WithContext(ctx context.Context) ICronjobDo
|
|
||||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
||||||
ReplaceDB(db *gorm.DB)
|
|
||||||
ReadDB() ICronjobDo
|
|
||||||
WriteDB() ICronjobDo
|
|
||||||
As(alias string) gen.Dao
|
|
||||||
Session(config *gorm.Session) ICronjobDo
|
|
||||||
Columns(cols ...field.Expr) gen.Columns
|
|
||||||
Clauses(conds ...clause.Expression) ICronjobDo
|
|
||||||
Not(conds ...gen.Condition) ICronjobDo
|
|
||||||
Or(conds ...gen.Condition) ICronjobDo
|
|
||||||
Select(conds ...field.Expr) ICronjobDo
|
|
||||||
Where(conds ...gen.Condition) ICronjobDo
|
|
||||||
Order(conds ...field.Expr) ICronjobDo
|
|
||||||
Distinct(cols ...field.Expr) ICronjobDo
|
|
||||||
Omit(cols ...field.Expr) ICronjobDo
|
|
||||||
Join(table schema.Tabler, on ...field.Expr) ICronjobDo
|
|
||||||
LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobDo
|
|
||||||
RightJoin(table schema.Tabler, on ...field.Expr) ICronjobDo
|
|
||||||
Group(cols ...field.Expr) ICronjobDo
|
|
||||||
Having(conds ...gen.Condition) ICronjobDo
|
|
||||||
Limit(limit int) ICronjobDo
|
|
||||||
Offset(offset int) ICronjobDo
|
|
||||||
Count() (count int64, err error)
|
|
||||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobDo
|
|
||||||
Unscoped() ICronjobDo
|
|
||||||
Create(values ...*models.Cronjob) error
|
|
||||||
CreateInBatches(values []*models.Cronjob, batchSize int) error
|
|
||||||
Save(values ...*models.Cronjob) error
|
|
||||||
First() (*models.Cronjob, error)
|
|
||||||
Take() (*models.Cronjob, error)
|
|
||||||
Last() (*models.Cronjob, error)
|
|
||||||
Find() ([]*models.Cronjob, error)
|
|
||||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Cronjob, err error)
|
|
||||||
FindInBatches(result *[]*models.Cronjob, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
||||||
Pluck(column field.Expr, dest interface{}) error
|
|
||||||
Delete(...*models.Cronjob) (info gen.ResultInfo, err error)
|
|
||||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
||||||
Attrs(attrs ...field.AssignExpr) ICronjobDo
|
|
||||||
Assign(attrs ...field.AssignExpr) ICronjobDo
|
|
||||||
Joins(fields ...field.RelationField) ICronjobDo
|
|
||||||
Preload(fields ...field.RelationField) ICronjobDo
|
|
||||||
FirstOrInit() (*models.Cronjob, error)
|
|
||||||
FirstOrCreate() (*models.Cronjob, error)
|
|
||||||
FindByPage(offset int, limit int) (result []*models.Cronjob, count int64, err error)
|
|
||||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
||||||
Scan(result interface{}) (err error)
|
|
||||||
Returning(value interface{}, columns ...string) ICronjobDo
|
|
||||||
UnderlyingDB() *gorm.DB
|
|
||||||
schema.Tabler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Debug() ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Debug())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) WithContext(ctx context.Context) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.WithContext(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) ReadDB() ICronjobDo {
|
|
||||||
return c.Clauses(dbresolver.Read)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) WriteDB() ICronjobDo {
|
|
||||||
return c.Clauses(dbresolver.Write)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Session(config *gorm.Session) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Session(config))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Clauses(conds ...clause.Expression) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Clauses(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Returning(value interface{}, columns ...string) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Returning(value, columns...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Not(conds ...gen.Condition) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Not(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Or(conds ...gen.Condition) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Or(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Select(conds ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Select(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Where(conds ...gen.Condition) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Where(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Order(conds ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Order(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Distinct(cols ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Distinct(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Omit(cols ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Omit(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Join(table schema.Tabler, on ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Join(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) RightJoin(table schema.Tabler, on ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.RightJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Group(cols ...field.Expr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Group(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Having(conds ...gen.Condition) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Having(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Limit(limit int) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Limit(limit))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Offset(offset int) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Offset(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Scopes(funcs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Unscoped() ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Unscoped())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Create(values ...*models.Cronjob) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DO.Create(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) CreateInBatches(values []*models.Cronjob, batchSize int) error {
|
|
||||||
return c.DO.CreateInBatches(values, batchSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save : !!! underlying implementation is different with GORM
|
|
||||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
|
||||||
func (c cronjobDo) Save(values ...*models.Cronjob) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DO.Save(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) First() (*models.Cronjob, error) {
|
|
||||||
if result, err := c.DO.First(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Cronjob), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Take() (*models.Cronjob, error) {
|
|
||||||
if result, err := c.DO.Take(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Cronjob), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Last() (*models.Cronjob, error) {
|
|
||||||
if result, err := c.DO.Last(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Cronjob), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Find() ([]*models.Cronjob, error) {
|
|
||||||
result, err := c.DO.Find()
|
|
||||||
return result.([]*models.Cronjob), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Cronjob, err error) {
|
|
||||||
buf := make([]*models.Cronjob, 0, batchSize)
|
|
||||||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
|
||||||
defer func() { results = append(results, buf...) }()
|
|
||||||
return fc(tx, batch)
|
|
||||||
})
|
|
||||||
return results, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) FindInBatches(result *[]*models.Cronjob, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
||||||
return c.DO.FindInBatches(result, batchSize, fc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Attrs(attrs ...field.AssignExpr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Attrs(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Assign(attrs ...field.AssignExpr) ICronjobDo {
|
|
||||||
return c.withDO(c.DO.Assign(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Joins(fields ...field.RelationField) ICronjobDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
c = *c.withDO(c.DO.Joins(_f))
|
|
||||||
}
|
|
||||||
return &c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Preload(fields ...field.RelationField) ICronjobDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
c = *c.withDO(c.DO.Preload(_f))
|
|
||||||
}
|
|
||||||
return &c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) FirstOrInit() (*models.Cronjob, error) {
|
|
||||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Cronjob), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) FirstOrCreate() (*models.Cronjob, error) {
|
|
||||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Cronjob), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) FindByPage(offset int, limit int) (result []*models.Cronjob, count int64, err error) {
|
|
||||||
result, err = c.Offset(offset).Limit(limit).Find()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
|
||||||
count = int64(size + offset)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err = c.Offset(-1).Limit(-1).Count()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
||||||
count, err = c.Count()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.Offset(offset).Limit(limit).Scan(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Scan(result interface{}) (err error) {
|
|
||||||
return c.DO.Scan(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cronjobDo) Delete(models ...*models.Cronjob) (result gen.ResultInfo, err error) {
|
|
||||||
return c.DO.Delete(models)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cronjobDo) withDO(do gen.Dao) *cronjobDo {
|
|
||||||
c.DO = *do.(*gen.DO)
|
|
||||||
return c
|
|
||||||
}
|
|
|
@ -17,45 +17,37 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Q = new(Query)
|
Q = new(Query)
|
||||||
Cronjob *cronjob
|
|
||||||
CronjobHistory *cronjobHistory
|
|
||||||
Monitor *monitor
|
Monitor *monitor
|
||||||
MonitorHistory *monitorHistory
|
MonitorHistory *monitorHistory
|
||||||
OAuth2State *oAuth2State
|
OAuth2State *oAuth2State
|
||||||
Worker *worker
|
WorkerGroup *workerGroup
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||||
*Q = *Use(db, opts...)
|
*Q = *Use(db, opts...)
|
||||||
Cronjob = &Q.Cronjob
|
|
||||||
CronjobHistory = &Q.CronjobHistory
|
|
||||||
Monitor = &Q.Monitor
|
Monitor = &Q.Monitor
|
||||||
MonitorHistory = &Q.MonitorHistory
|
MonitorHistory = &Q.MonitorHistory
|
||||||
OAuth2State = &Q.OAuth2State
|
OAuth2State = &Q.OAuth2State
|
||||||
Worker = &Q.Worker
|
WorkerGroup = &Q.WorkerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Cronjob: newCronjob(db, opts...),
|
|
||||||
CronjobHistory: newCronjobHistory(db, opts...),
|
|
||||||
Monitor: newMonitor(db, opts...),
|
Monitor: newMonitor(db, opts...),
|
||||||
MonitorHistory: newMonitorHistory(db, opts...),
|
MonitorHistory: newMonitorHistory(db, opts...),
|
||||||
OAuth2State: newOAuth2State(db, opts...),
|
OAuth2State: newOAuth2State(db, opts...),
|
||||||
Worker: newWorker(db, opts...),
|
WorkerGroup: newWorkerGroup(db, opts...),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
|
||||||
Cronjob cronjob
|
|
||||||
CronjobHistory cronjobHistory
|
|
||||||
Monitor monitor
|
Monitor monitor
|
||||||
MonitorHistory monitorHistory
|
MonitorHistory monitorHistory
|
||||||
OAuth2State oAuth2State
|
OAuth2State oAuth2State
|
||||||
Worker worker
|
WorkerGroup workerGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Query) Available() bool { return q.db != nil }
|
func (q *Query) Available() bool { return q.db != nil }
|
||||||
|
@ -63,12 +55,10 @@ func (q *Query) Available() bool { return q.db != nil }
|
||||||
func (q *Query) clone(db *gorm.DB) *Query {
|
func (q *Query) clone(db *gorm.DB) *Query {
|
||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Cronjob: q.Cronjob.clone(db),
|
|
||||||
CronjobHistory: q.CronjobHistory.clone(db),
|
|
||||||
Monitor: q.Monitor.clone(db),
|
Monitor: q.Monitor.clone(db),
|
||||||
MonitorHistory: q.MonitorHistory.clone(db),
|
MonitorHistory: q.MonitorHistory.clone(db),
|
||||||
OAuth2State: q.OAuth2State.clone(db),
|
OAuth2State: q.OAuth2State.clone(db),
|
||||||
Worker: q.Worker.clone(db),
|
WorkerGroup: q.WorkerGroup.clone(db),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,32 +73,26 @@ func (q *Query) WriteDB() *Query {
|
||||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Cronjob: q.Cronjob.replaceDB(db),
|
|
||||||
CronjobHistory: q.CronjobHistory.replaceDB(db),
|
|
||||||
Monitor: q.Monitor.replaceDB(db),
|
Monitor: q.Monitor.replaceDB(db),
|
||||||
MonitorHistory: q.MonitorHistory.replaceDB(db),
|
MonitorHistory: q.MonitorHistory.replaceDB(db),
|
||||||
OAuth2State: q.OAuth2State.replaceDB(db),
|
OAuth2State: q.OAuth2State.replaceDB(db),
|
||||||
Worker: q.Worker.replaceDB(db),
|
WorkerGroup: q.WorkerGroup.replaceDB(db),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type queryCtx struct {
|
type queryCtx struct {
|
||||||
Cronjob ICronjobDo
|
|
||||||
CronjobHistory ICronjobHistoryDo
|
|
||||||
Monitor IMonitorDo
|
Monitor IMonitorDo
|
||||||
MonitorHistory IMonitorHistoryDo
|
MonitorHistory IMonitorHistoryDo
|
||||||
OAuth2State IOAuth2StateDo
|
OAuth2State IOAuth2StateDo
|
||||||
Worker IWorkerDo
|
WorkerGroup IWorkerGroupDo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||||
return &queryCtx{
|
return &queryCtx{
|
||||||
Cronjob: q.Cronjob.WithContext(ctx),
|
|
||||||
CronjobHistory: q.CronjobHistory.WithContext(ctx),
|
|
||||||
Monitor: q.Monitor.WithContext(ctx),
|
Monitor: q.Monitor.WithContext(ctx),
|
||||||
MonitorHistory: q.MonitorHistory.WithContext(ctx),
|
MonitorHistory: q.MonitorHistory.WithContext(ctx),
|
||||||
OAuth2State: q.OAuth2State.WithContext(ctx),
|
OAuth2State: q.OAuth2State.WithContext(ctx),
|
||||||
Worker: q.Worker.WithContext(ctx),
|
WorkerGroup: q.WorkerGroup.WithContext(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ func newMonitor(db *gorm.DB, opts ...gen.DOOption) monitor {
|
||||||
_monitor.Slug = field.NewString(tableName, "slug")
|
_monitor.Slug = field.NewString(tableName, "slug")
|
||||||
_monitor.Name = field.NewString(tableName, "name")
|
_monitor.Name = field.NewString(tableName, "name")
|
||||||
_monitor.Schedule = field.NewString(tableName, "schedule")
|
_monitor.Schedule = field.NewString(tableName, "schedule")
|
||||||
_monitor.WorkerGroups = field.NewField(tableName, "worker_groups")
|
|
||||||
_monitor.Script = field.NewString(tableName, "script")
|
_monitor.Script = field.NewString(tableName, "script")
|
||||||
_monitor.History = monitorHasManyHistory{
|
_monitor.History = monitorHasManyHistory{
|
||||||
db: db.Session(&gorm.Session{}),
|
db: db.Session(&gorm.Session{}),
|
||||||
|
@ -42,6 +41,33 @@ func newMonitor(db *gorm.DB, opts ...gen.DOOption) monitor {
|
||||||
RelationField: field.NewRelation("History", "models.MonitorHistory"),
|
RelationField: field.NewRelation("History", "models.MonitorHistory"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_monitor.WorkerGroups = monitorManyToManyWorkerGroups{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("WorkerGroups", "models.WorkerGroup"),
|
||||||
|
Monitors: struct {
|
||||||
|
field.RelationField
|
||||||
|
History struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
WorkerGroups struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("WorkerGroups.Monitors", "models.Monitor"),
|
||||||
|
History: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("WorkerGroups.Monitors.History", "models.MonitorHistory"),
|
||||||
|
},
|
||||||
|
WorkerGroups: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("WorkerGroups.Monitors.WorkerGroups", "models.WorkerGroup"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
_monitor.fillFieldMap()
|
_monitor.fillFieldMap()
|
||||||
|
|
||||||
return _monitor
|
return _monitor
|
||||||
|
@ -50,17 +76,18 @@ func newMonitor(db *gorm.DB, opts ...gen.DOOption) monitor {
|
||||||
type monitor struct {
|
type monitor struct {
|
||||||
monitorDo monitorDo
|
monitorDo monitorDo
|
||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint
|
ID field.Uint
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
DeletedAt field.Field
|
DeletedAt field.Field
|
||||||
Slug field.String
|
Slug field.String
|
||||||
Name field.String
|
Name field.String
|
||||||
Schedule field.String
|
Schedule field.String
|
||||||
WorkerGroups field.Field
|
Script field.String
|
||||||
Script field.String
|
History monitorHasManyHistory
|
||||||
History monitorHasManyHistory
|
|
||||||
|
WorkerGroups monitorManyToManyWorkerGroups
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
fieldMap map[string]field.Expr
|
||||||
}
|
}
|
||||||
|
@ -84,7 +111,6 @@ func (m *monitor) updateTableName(table string) *monitor {
|
||||||
m.Slug = field.NewString(table, "slug")
|
m.Slug = field.NewString(table, "slug")
|
||||||
m.Name = field.NewString(table, "name")
|
m.Name = field.NewString(table, "name")
|
||||||
m.Schedule = field.NewString(table, "schedule")
|
m.Schedule = field.NewString(table, "schedule")
|
||||||
m.WorkerGroups = field.NewField(table, "worker_groups")
|
|
||||||
m.Script = field.NewString(table, "script")
|
m.Script = field.NewString(table, "script")
|
||||||
|
|
||||||
m.fillFieldMap()
|
m.fillFieldMap()
|
||||||
|
@ -118,7 +144,6 @@ func (m *monitor) fillFieldMap() {
|
||||||
m.fieldMap["slug"] = m.Slug
|
m.fieldMap["slug"] = m.Slug
|
||||||
m.fieldMap["name"] = m.Name
|
m.fieldMap["name"] = m.Name
|
||||||
m.fieldMap["schedule"] = m.Schedule
|
m.fieldMap["schedule"] = m.Schedule
|
||||||
m.fieldMap["worker_groups"] = m.WorkerGroups
|
|
||||||
m.fieldMap["script"] = m.Script
|
m.fieldMap["script"] = m.Script
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -204,6 +229,87 @@ func (a monitorHasManyHistoryTx) Count() int64 {
|
||||||
return a.tx.Count()
|
return a.tx.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type monitorManyToManyWorkerGroups struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
Monitors struct {
|
||||||
|
field.RelationField
|
||||||
|
History struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
WorkerGroups struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroups) Where(conds ...field.Expr) *monitorManyToManyWorkerGroups {
|
||||||
|
if len(conds) == 0 {
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
exprs := make([]clause.Expression, 0, len(conds))
|
||||||
|
for _, cond := range conds {
|
||||||
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||||
|
}
|
||||||
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroups) WithContext(ctx context.Context) *monitorManyToManyWorkerGroups {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroups) Session(session *gorm.Session) *monitorManyToManyWorkerGroups {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroups) Model(m *models.Monitor) *monitorManyToManyWorkerGroupsTx {
|
||||||
|
return &monitorManyToManyWorkerGroupsTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type monitorManyToManyWorkerGroupsTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Find() (result []*models.WorkerGroup, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Append(values ...*models.WorkerGroup) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Append(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Replace(values ...*models.WorkerGroup) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Replace(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Delete(values ...*models.WorkerGroup) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Delete(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a monitorManyToManyWorkerGroupsTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
type monitorDo struct{ gen.DO }
|
type monitorDo struct{ gen.DO }
|
||||||
|
|
||||||
type IMonitorDo interface {
|
type IMonitorDo interface {
|
||||||
|
|
516
internal/models/query/worker_groups.gen.go
Normal file
516
internal/models/query/worker_groups.gen.go
Normal file
|
@ -0,0 +1,516 @@
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
|
||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
"gorm.io/gorm/schema"
|
||||||
|
|
||||||
|
"gorm.io/gen"
|
||||||
|
"gorm.io/gen/field"
|
||||||
|
|
||||||
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newWorkerGroup(db *gorm.DB, opts ...gen.DOOption) workerGroup {
|
||||||
|
_workerGroup := workerGroup{}
|
||||||
|
|
||||||
|
_workerGroup.workerGroupDo.UseDB(db, opts...)
|
||||||
|
_workerGroup.workerGroupDo.UseModel(&models.WorkerGroup{})
|
||||||
|
|
||||||
|
tableName := _workerGroup.workerGroupDo.TableName()
|
||||||
|
_workerGroup.ALL = field.NewAsterisk(tableName)
|
||||||
|
_workerGroup.ID = field.NewUint(tableName, "id")
|
||||||
|
_workerGroup.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
|
_workerGroup.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
|
_workerGroup.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||||
|
_workerGroup.Name = field.NewString(tableName, "name")
|
||||||
|
_workerGroup.Slug = field.NewString(tableName, "slug")
|
||||||
|
_workerGroup.Monitors = workerGroupManyToManyMonitors{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Monitors", "models.Monitor"),
|
||||||
|
History: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Monitors.History", "models.MonitorHistory"),
|
||||||
|
},
|
||||||
|
WorkerGroups: struct {
|
||||||
|
field.RelationField
|
||||||
|
Monitors struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Monitors.WorkerGroups", "models.WorkerGroup"),
|
||||||
|
Monitors: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Monitors.WorkerGroups.Monitors", "models.Monitor"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_workerGroup.fillFieldMap()
|
||||||
|
|
||||||
|
return _workerGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerGroup struct {
|
||||||
|
workerGroupDo workerGroupDo
|
||||||
|
|
||||||
|
ALL field.Asterisk
|
||||||
|
ID field.Uint
|
||||||
|
CreatedAt field.Time
|
||||||
|
UpdatedAt field.Time
|
||||||
|
DeletedAt field.Field
|
||||||
|
Name field.String
|
||||||
|
Slug field.String
|
||||||
|
Monitors workerGroupManyToManyMonitors
|
||||||
|
|
||||||
|
fieldMap map[string]field.Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroup) Table(newTableName string) *workerGroup {
|
||||||
|
w.workerGroupDo.UseTable(newTableName)
|
||||||
|
return w.updateTableName(newTableName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroup) As(alias string) *workerGroup {
|
||||||
|
w.workerGroupDo.DO = *(w.workerGroupDo.As(alias).(*gen.DO))
|
||||||
|
return w.updateTableName(alias)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *workerGroup) updateTableName(table string) *workerGroup {
|
||||||
|
w.ALL = field.NewAsterisk(table)
|
||||||
|
w.ID = field.NewUint(table, "id")
|
||||||
|
w.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
w.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
|
w.DeletedAt = field.NewField(table, "deleted_at")
|
||||||
|
w.Name = field.NewString(table, "name")
|
||||||
|
w.Slug = field.NewString(table, "slug")
|
||||||
|
|
||||||
|
w.fillFieldMap()
|
||||||
|
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *workerGroup) WithContext(ctx context.Context) IWorkerGroupDo {
|
||||||
|
return w.workerGroupDo.WithContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroup) TableName() string { return w.workerGroupDo.TableName() }
|
||||||
|
|
||||||
|
func (w workerGroup) Alias() string { return w.workerGroupDo.Alias() }
|
||||||
|
|
||||||
|
func (w workerGroup) Columns(cols ...field.Expr) gen.Columns { return w.workerGroupDo.Columns(cols...) }
|
||||||
|
|
||||||
|
func (w *workerGroup) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||||
|
_f, ok := w.fieldMap[fieldName]
|
||||||
|
if !ok || _f == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
_oe, ok := _f.(field.OrderExpr)
|
||||||
|
return _oe, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *workerGroup) fillFieldMap() {
|
||||||
|
w.fieldMap = make(map[string]field.Expr, 7)
|
||||||
|
w.fieldMap["id"] = w.ID
|
||||||
|
w.fieldMap["created_at"] = w.CreatedAt
|
||||||
|
w.fieldMap["updated_at"] = w.UpdatedAt
|
||||||
|
w.fieldMap["deleted_at"] = w.DeletedAt
|
||||||
|
w.fieldMap["name"] = w.Name
|
||||||
|
w.fieldMap["slug"] = w.Slug
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroup) clone(db *gorm.DB) workerGroup {
|
||||||
|
w.workerGroupDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroup) replaceDB(db *gorm.DB) workerGroup {
|
||||||
|
w.workerGroupDo.ReplaceDB(db)
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerGroupManyToManyMonitors struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
History struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
WorkerGroups struct {
|
||||||
|
field.RelationField
|
||||||
|
Monitors struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitors) Where(conds ...field.Expr) *workerGroupManyToManyMonitors {
|
||||||
|
if len(conds) == 0 {
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
exprs := make([]clause.Expression, 0, len(conds))
|
||||||
|
for _, cond := range conds {
|
||||||
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||||
|
}
|
||||||
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitors) WithContext(ctx context.Context) *workerGroupManyToManyMonitors {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitors) Session(session *gorm.Session) *workerGroupManyToManyMonitors {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitors) Model(m *models.WorkerGroup) *workerGroupManyToManyMonitorsTx {
|
||||||
|
return &workerGroupManyToManyMonitorsTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerGroupManyToManyMonitorsTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Find() (result []*models.Monitor, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Append(values ...*models.Monitor) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Append(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Replace(values ...*models.Monitor) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Replace(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Delete(values ...*models.Monitor) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Delete(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a workerGroupManyToManyMonitorsTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
type workerGroupDo struct{ gen.DO }
|
||||||
|
|
||||||
|
type IWorkerGroupDo interface {
|
||||||
|
gen.SubQuery
|
||||||
|
Debug() IWorkerGroupDo
|
||||||
|
WithContext(ctx context.Context) IWorkerGroupDo
|
||||||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||||
|
ReplaceDB(db *gorm.DB)
|
||||||
|
ReadDB() IWorkerGroupDo
|
||||||
|
WriteDB() IWorkerGroupDo
|
||||||
|
As(alias string) gen.Dao
|
||||||
|
Session(config *gorm.Session) IWorkerGroupDo
|
||||||
|
Columns(cols ...field.Expr) gen.Columns
|
||||||
|
Clauses(conds ...clause.Expression) IWorkerGroupDo
|
||||||
|
Not(conds ...gen.Condition) IWorkerGroupDo
|
||||||
|
Or(conds ...gen.Condition) IWorkerGroupDo
|
||||||
|
Select(conds ...field.Expr) IWorkerGroupDo
|
||||||
|
Where(conds ...gen.Condition) IWorkerGroupDo
|
||||||
|
Order(conds ...field.Expr) IWorkerGroupDo
|
||||||
|
Distinct(cols ...field.Expr) IWorkerGroupDo
|
||||||
|
Omit(cols ...field.Expr) IWorkerGroupDo
|
||||||
|
Join(table schema.Tabler, on ...field.Expr) IWorkerGroupDo
|
||||||
|
LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerGroupDo
|
||||||
|
RightJoin(table schema.Tabler, on ...field.Expr) IWorkerGroupDo
|
||||||
|
Group(cols ...field.Expr) IWorkerGroupDo
|
||||||
|
Having(conds ...gen.Condition) IWorkerGroupDo
|
||||||
|
Limit(limit int) IWorkerGroupDo
|
||||||
|
Offset(offset int) IWorkerGroupDo
|
||||||
|
Count() (count int64, err error)
|
||||||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerGroupDo
|
||||||
|
Unscoped() IWorkerGroupDo
|
||||||
|
Create(values ...*models.WorkerGroup) error
|
||||||
|
CreateInBatches(values []*models.WorkerGroup, batchSize int) error
|
||||||
|
Save(values ...*models.WorkerGroup) error
|
||||||
|
First() (*models.WorkerGroup, error)
|
||||||
|
Take() (*models.WorkerGroup, error)
|
||||||
|
Last() (*models.WorkerGroup, error)
|
||||||
|
Find() ([]*models.WorkerGroup, error)
|
||||||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.WorkerGroup, err error)
|
||||||
|
FindInBatches(result *[]*models.WorkerGroup, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||||
|
Pluck(column field.Expr, dest interface{}) error
|
||||||
|
Delete(...*models.WorkerGroup) (info gen.ResultInfo, err error)
|
||||||
|
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||||
|
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||||
|
Attrs(attrs ...field.AssignExpr) IWorkerGroupDo
|
||||||
|
Assign(attrs ...field.AssignExpr) IWorkerGroupDo
|
||||||
|
Joins(fields ...field.RelationField) IWorkerGroupDo
|
||||||
|
Preload(fields ...field.RelationField) IWorkerGroupDo
|
||||||
|
FirstOrInit() (*models.WorkerGroup, error)
|
||||||
|
FirstOrCreate() (*models.WorkerGroup, error)
|
||||||
|
FindByPage(offset int, limit int) (result []*models.WorkerGroup, count int64, err error)
|
||||||
|
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||||
|
Scan(result interface{}) (err error)
|
||||||
|
Returning(value interface{}, columns ...string) IWorkerGroupDo
|
||||||
|
UnderlyingDB() *gorm.DB
|
||||||
|
schema.Tabler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Debug() IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Debug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) WithContext(ctx context.Context) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) ReadDB() IWorkerGroupDo {
|
||||||
|
return w.Clauses(dbresolver.Read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) WriteDB() IWorkerGroupDo {
|
||||||
|
return w.Clauses(dbresolver.Write)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Session(config *gorm.Session) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Session(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Clauses(conds ...clause.Expression) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Clauses(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Returning(value interface{}, columns ...string) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Returning(value, columns...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Not(conds ...gen.Condition) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Not(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Or(conds ...gen.Condition) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Or(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Select(conds ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Select(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Where(conds ...gen.Condition) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Where(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Order(conds ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Order(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Distinct(cols ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Distinct(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Omit(cols ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Omit(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Join(table schema.Tabler, on ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Join(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.LeftJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) RightJoin(table schema.Tabler, on ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.RightJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Group(cols ...field.Expr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Group(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Having(conds ...gen.Condition) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Having(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Limit(limit int) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Limit(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Offset(offset int) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Offset(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Scopes(funcs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Unscoped() IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Unscoped())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Create(values ...*models.WorkerGroup) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return w.DO.Create(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) CreateInBatches(values []*models.WorkerGroup, batchSize int) error {
|
||||||
|
return w.DO.CreateInBatches(values, batchSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save : !!! underlying implementation is different with GORM
|
||||||
|
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||||
|
func (w workerGroupDo) Save(values ...*models.WorkerGroup) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return w.DO.Save(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) First() (*models.WorkerGroup, error) {
|
||||||
|
if result, err := w.DO.First(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.WorkerGroup), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Take() (*models.WorkerGroup, error) {
|
||||||
|
if result, err := w.DO.Take(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.WorkerGroup), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Last() (*models.WorkerGroup, error) {
|
||||||
|
if result, err := w.DO.Last(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.WorkerGroup), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Find() ([]*models.WorkerGroup, error) {
|
||||||
|
result, err := w.DO.Find()
|
||||||
|
return result.([]*models.WorkerGroup), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.WorkerGroup, err error) {
|
||||||
|
buf := make([]*models.WorkerGroup, 0, batchSize)
|
||||||
|
err = w.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||||
|
defer func() { results = append(results, buf...) }()
|
||||||
|
return fc(tx, batch)
|
||||||
|
})
|
||||||
|
return results, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) FindInBatches(result *[]*models.WorkerGroup, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||||
|
return w.DO.FindInBatches(result, batchSize, fc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Attrs(attrs ...field.AssignExpr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Attrs(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Assign(attrs ...field.AssignExpr) IWorkerGroupDo {
|
||||||
|
return w.withDO(w.DO.Assign(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Joins(fields ...field.RelationField) IWorkerGroupDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
w = *w.withDO(w.DO.Joins(_f))
|
||||||
|
}
|
||||||
|
return &w
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Preload(fields ...field.RelationField) IWorkerGroupDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
w = *w.withDO(w.DO.Preload(_f))
|
||||||
|
}
|
||||||
|
return &w
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) FirstOrInit() (*models.WorkerGroup, error) {
|
||||||
|
if result, err := w.DO.FirstOrInit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.WorkerGroup), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) FirstOrCreate() (*models.WorkerGroup, error) {
|
||||||
|
if result, err := w.DO.FirstOrCreate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.WorkerGroup), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) FindByPage(offset int, limit int) (result []*models.WorkerGroup, count int64, err error) {
|
||||||
|
result, err = w.Offset(offset).Limit(limit).Find()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||||
|
count = int64(size + offset)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err = w.Offset(-1).Limit(-1).Count()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||||
|
count, err = w.Count()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = w.Offset(offset).Limit(limit).Scan(result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Scan(result interface{}) (err error) {
|
||||||
|
return w.DO.Scan(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w workerGroupDo) Delete(models ...*models.WorkerGroup) (result gen.ResultInfo, err error) {
|
||||||
|
return w.DO.Delete(models)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *workerGroupDo) withDO(do gen.Dao) *workerGroupDo {
|
||||||
|
w.DO = *do.(*gen.DO)
|
||||||
|
return w
|
||||||
|
}
|
|
@ -1,416 +0,0 @@
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package query
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
"gorm.io/gorm/schema"
|
|
||||||
|
|
||||||
"gorm.io/gen"
|
|
||||||
"gorm.io/gen/field"
|
|
||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newWorker(db *gorm.DB, opts ...gen.DOOption) worker {
|
|
||||||
_worker := worker{}
|
|
||||||
|
|
||||||
_worker.workerDo.UseDB(db, opts...)
|
|
||||||
_worker.workerDo.UseModel(&models.Worker{})
|
|
||||||
|
|
||||||
tableName := _worker.workerDo.TableName()
|
|
||||||
_worker.ALL = field.NewAsterisk(tableName)
|
|
||||||
_worker.ID = field.NewUint(tableName, "id")
|
|
||||||
_worker.CreatedAt = field.NewTime(tableName, "created_at")
|
|
||||||
_worker.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
||||||
_worker.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
||||||
_worker.Name = field.NewString(tableName, "name")
|
|
||||||
_worker.Slug = field.NewString(tableName, "slug")
|
|
||||||
_worker.Group = field.NewString(tableName, "group")
|
|
||||||
_worker.Status = field.NewString(tableName, "status")
|
|
||||||
|
|
||||||
_worker.fillFieldMap()
|
|
||||||
|
|
||||||
return _worker
|
|
||||||
}
|
|
||||||
|
|
||||||
type worker struct {
|
|
||||||
workerDo workerDo
|
|
||||||
|
|
||||||
ALL field.Asterisk
|
|
||||||
ID field.Uint
|
|
||||||
CreatedAt field.Time
|
|
||||||
UpdatedAt field.Time
|
|
||||||
DeletedAt field.Field
|
|
||||||
Name field.String
|
|
||||||
Slug field.String
|
|
||||||
Group field.String
|
|
||||||
Status field.String
|
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w worker) Table(newTableName string) *worker {
|
|
||||||
w.workerDo.UseTable(newTableName)
|
|
||||||
return w.updateTableName(newTableName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w worker) As(alias string) *worker {
|
|
||||||
w.workerDo.DO = *(w.workerDo.As(alias).(*gen.DO))
|
|
||||||
return w.updateTableName(alias)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *worker) updateTableName(table string) *worker {
|
|
||||||
w.ALL = field.NewAsterisk(table)
|
|
||||||
w.ID = field.NewUint(table, "id")
|
|
||||||
w.CreatedAt = field.NewTime(table, "created_at")
|
|
||||||
w.UpdatedAt = field.NewTime(table, "updated_at")
|
|
||||||
w.DeletedAt = field.NewField(table, "deleted_at")
|
|
||||||
w.Name = field.NewString(table, "name")
|
|
||||||
w.Slug = field.NewString(table, "slug")
|
|
||||||
w.Group = field.NewString(table, "group")
|
|
||||||
w.Status = field.NewString(table, "status")
|
|
||||||
|
|
||||||
w.fillFieldMap()
|
|
||||||
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *worker) WithContext(ctx context.Context) IWorkerDo { return w.workerDo.WithContext(ctx) }
|
|
||||||
|
|
||||||
func (w worker) TableName() string { return w.workerDo.TableName() }
|
|
||||||
|
|
||||||
func (w worker) Alias() string { return w.workerDo.Alias() }
|
|
||||||
|
|
||||||
func (w worker) Columns(cols ...field.Expr) gen.Columns { return w.workerDo.Columns(cols...) }
|
|
||||||
|
|
||||||
func (w *worker) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
||||||
_f, ok := w.fieldMap[fieldName]
|
|
||||||
if !ok || _f == nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
_oe, ok := _f.(field.OrderExpr)
|
|
||||||
return _oe, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *worker) fillFieldMap() {
|
|
||||||
w.fieldMap = make(map[string]field.Expr, 8)
|
|
||||||
w.fieldMap["id"] = w.ID
|
|
||||||
w.fieldMap["created_at"] = w.CreatedAt
|
|
||||||
w.fieldMap["updated_at"] = w.UpdatedAt
|
|
||||||
w.fieldMap["deleted_at"] = w.DeletedAt
|
|
||||||
w.fieldMap["name"] = w.Name
|
|
||||||
w.fieldMap["slug"] = w.Slug
|
|
||||||
w.fieldMap["group"] = w.Group
|
|
||||||
w.fieldMap["status"] = w.Status
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w worker) clone(db *gorm.DB) worker {
|
|
||||||
w.workerDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w worker) replaceDB(db *gorm.DB) worker {
|
|
||||||
w.workerDo.ReplaceDB(db)
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
type workerDo struct{ gen.DO }
|
|
||||||
|
|
||||||
type IWorkerDo interface {
|
|
||||||
gen.SubQuery
|
|
||||||
Debug() IWorkerDo
|
|
||||||
WithContext(ctx context.Context) IWorkerDo
|
|
||||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
||||||
ReplaceDB(db *gorm.DB)
|
|
||||||
ReadDB() IWorkerDo
|
|
||||||
WriteDB() IWorkerDo
|
|
||||||
As(alias string) gen.Dao
|
|
||||||
Session(config *gorm.Session) IWorkerDo
|
|
||||||
Columns(cols ...field.Expr) gen.Columns
|
|
||||||
Clauses(conds ...clause.Expression) IWorkerDo
|
|
||||||
Not(conds ...gen.Condition) IWorkerDo
|
|
||||||
Or(conds ...gen.Condition) IWorkerDo
|
|
||||||
Select(conds ...field.Expr) IWorkerDo
|
|
||||||
Where(conds ...gen.Condition) IWorkerDo
|
|
||||||
Order(conds ...field.Expr) IWorkerDo
|
|
||||||
Distinct(cols ...field.Expr) IWorkerDo
|
|
||||||
Omit(cols ...field.Expr) IWorkerDo
|
|
||||||
Join(table schema.Tabler, on ...field.Expr) IWorkerDo
|
|
||||||
LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerDo
|
|
||||||
RightJoin(table schema.Tabler, on ...field.Expr) IWorkerDo
|
|
||||||
Group(cols ...field.Expr) IWorkerDo
|
|
||||||
Having(conds ...gen.Condition) IWorkerDo
|
|
||||||
Limit(limit int) IWorkerDo
|
|
||||||
Offset(offset int) IWorkerDo
|
|
||||||
Count() (count int64, err error)
|
|
||||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerDo
|
|
||||||
Unscoped() IWorkerDo
|
|
||||||
Create(values ...*models.Worker) error
|
|
||||||
CreateInBatches(values []*models.Worker, batchSize int) error
|
|
||||||
Save(values ...*models.Worker) error
|
|
||||||
First() (*models.Worker, error)
|
|
||||||
Take() (*models.Worker, error)
|
|
||||||
Last() (*models.Worker, error)
|
|
||||||
Find() ([]*models.Worker, error)
|
|
||||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Worker, err error)
|
|
||||||
FindInBatches(result *[]*models.Worker, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
||||||
Pluck(column field.Expr, dest interface{}) error
|
|
||||||
Delete(...*models.Worker) (info gen.ResultInfo, err error)
|
|
||||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
||||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
||||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
||||||
Attrs(attrs ...field.AssignExpr) IWorkerDo
|
|
||||||
Assign(attrs ...field.AssignExpr) IWorkerDo
|
|
||||||
Joins(fields ...field.RelationField) IWorkerDo
|
|
||||||
Preload(fields ...field.RelationField) IWorkerDo
|
|
||||||
FirstOrInit() (*models.Worker, error)
|
|
||||||
FirstOrCreate() (*models.Worker, error)
|
|
||||||
FindByPage(offset int, limit int) (result []*models.Worker, count int64, err error)
|
|
||||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
||||||
Scan(result interface{}) (err error)
|
|
||||||
Returning(value interface{}, columns ...string) IWorkerDo
|
|
||||||
UnderlyingDB() *gorm.DB
|
|
||||||
schema.Tabler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Debug() IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Debug())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) WithContext(ctx context.Context) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.WithContext(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) ReadDB() IWorkerDo {
|
|
||||||
return w.Clauses(dbresolver.Read)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) WriteDB() IWorkerDo {
|
|
||||||
return w.Clauses(dbresolver.Write)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Session(config *gorm.Session) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Session(config))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Clauses(conds ...clause.Expression) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Clauses(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Returning(value interface{}, columns ...string) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Returning(value, columns...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Not(conds ...gen.Condition) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Not(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Or(conds ...gen.Condition) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Or(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Select(conds ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Select(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Where(conds ...gen.Condition) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Where(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Order(conds ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Order(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Distinct(cols ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Distinct(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Omit(cols ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Omit(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Join(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Join(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.LeftJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) RightJoin(table schema.Tabler, on ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.RightJoin(table, on...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Group(cols ...field.Expr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Group(cols...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Having(conds ...gen.Condition) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Having(conds...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Limit(limit int) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Limit(limit))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Offset(offset int) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Offset(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Scopes(funcs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Unscoped() IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Unscoped())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Create(values ...*models.Worker) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return w.DO.Create(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) CreateInBatches(values []*models.Worker, batchSize int) error {
|
|
||||||
return w.DO.CreateInBatches(values, batchSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save : !!! underlying implementation is different with GORM
|
|
||||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
|
||||||
func (w workerDo) Save(values ...*models.Worker) error {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return w.DO.Save(values)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) First() (*models.Worker, error) {
|
|
||||||
if result, err := w.DO.First(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Worker), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Take() (*models.Worker, error) {
|
|
||||||
if result, err := w.DO.Take(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Worker), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Last() (*models.Worker, error) {
|
|
||||||
if result, err := w.DO.Last(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Worker), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Find() ([]*models.Worker, error) {
|
|
||||||
result, err := w.DO.Find()
|
|
||||||
return result.([]*models.Worker), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Worker, err error) {
|
|
||||||
buf := make([]*models.Worker, 0, batchSize)
|
|
||||||
err = w.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
|
||||||
defer func() { results = append(results, buf...) }()
|
|
||||||
return fc(tx, batch)
|
|
||||||
})
|
|
||||||
return results, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) FindInBatches(result *[]*models.Worker, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
||||||
return w.DO.FindInBatches(result, batchSize, fc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Attrs(attrs ...field.AssignExpr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Attrs(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Assign(attrs ...field.AssignExpr) IWorkerDo {
|
|
||||||
return w.withDO(w.DO.Assign(attrs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Joins(fields ...field.RelationField) IWorkerDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
w = *w.withDO(w.DO.Joins(_f))
|
|
||||||
}
|
|
||||||
return &w
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Preload(fields ...field.RelationField) IWorkerDo {
|
|
||||||
for _, _f := range fields {
|
|
||||||
w = *w.withDO(w.DO.Preload(_f))
|
|
||||||
}
|
|
||||||
return &w
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) FirstOrInit() (*models.Worker, error) {
|
|
||||||
if result, err := w.DO.FirstOrInit(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Worker), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) FirstOrCreate() (*models.Worker, error) {
|
|
||||||
if result, err := w.DO.FirstOrCreate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return result.(*models.Worker), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) FindByPage(offset int, limit int) (result []*models.Worker, count int64, err error) {
|
|
||||||
result, err = w.Offset(offset).Limit(limit).Find()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
|
||||||
count = int64(size + offset)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err = w.Offset(-1).Limit(-1).Count()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
||||||
count, err = w.Count()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = w.Offset(offset).Limit(limit).Scan(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Scan(result interface{}) (err error) {
|
|
||||||
return w.DO.Scan(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w workerDo) Delete(models ...*models.Worker) (result gen.ResultInfo, err error) {
|
|
||||||
return w.DO.Delete(models)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *workerDo) withDO(do gen.Dao) *workerDo {
|
|
||||||
w.DO = *do.(*gen.DO)
|
|
||||||
return w
|
|
||||||
}
|
|
|
@ -25,14 +25,19 @@ func UpdateMonitor(ctx context.Context, q *query.Query, monitor *models.Monitor)
|
||||||
_, err := q.Monitor.WithContext(ctx).Where(
|
_, err := q.Monitor.WithContext(ctx).Where(
|
||||||
q.Monitor.Slug.Eq(monitor.Slug),
|
q.Monitor.Slug.Eq(monitor.Slug),
|
||||||
).Updates(monitor)
|
).Updates(monitor)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateMonitorWorkerGroups(ctx context.Context, q *query.Query, monitor *models.Monitor, workerGroups []*models.WorkerGroup) error {
|
||||||
|
return q.Monitor.WorkerGroups.Model(monitor).Replace(workerGroups...)
|
||||||
|
}
|
||||||
|
|
||||||
func GetMonitor(ctx context.Context, q *query.Query, slug string) (*models.Monitor, error) {
|
func GetMonitor(ctx context.Context, q *query.Query, slug string) (*models.Monitor, error) {
|
||||||
return q.Monitor.WithContext(ctx).Where(
|
return q.Monitor.WithContext(ctx).Where(
|
||||||
q.Monitor.Slug.Eq(slug),
|
q.Monitor.Slug.Eq(slug),
|
||||||
q.Monitor.DeletedAt.IsNull(),
|
|
||||||
).Preload(
|
).Preload(
|
||||||
|
q.Monitor.WorkerGroups,
|
||||||
q.Monitor.History,
|
q.Monitor.History,
|
||||||
).First()
|
).First()
|
||||||
}
|
}
|
||||||
|
@ -40,12 +45,16 @@ func GetMonitor(ctx context.Context, q *query.Query, slug string) (*models.Monit
|
||||||
func GetMonitors(ctx context.Context, q *query.Query) ([]*models.Monitor, error) {
|
func GetMonitors(ctx context.Context, q *query.Query) ([]*models.Monitor, error) {
|
||||||
return q.Monitor.WithContext(ctx).Preload(
|
return q.Monitor.WithContext(ctx).Preload(
|
||||||
q.Monitor.History,
|
q.Monitor.History,
|
||||||
).Where(
|
).Preload(
|
||||||
q.Monitor.DeletedAt.IsNull(),
|
q.Monitor.WorkerGroups,
|
||||||
).Find()
|
).Find()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOrUpdateMonitorSchedule(ctx context.Context, t client.Client, monitor *models.Monitor) error {
|
func CreateOrUpdateMonitorSchedule(
|
||||||
|
ctx context.Context,
|
||||||
|
t client.Client,
|
||||||
|
monitor *models.Monitor,
|
||||||
|
) error {
|
||||||
log.Println("Creating or Updating Monitor Schedule")
|
log.Println("Creating or Updating Monitor Schedule")
|
||||||
|
|
||||||
args := make([]interface{}, 0)
|
args := make([]interface{}, 0)
|
||||||
|
@ -53,27 +62,23 @@ func CreateOrUpdateMonitorSchedule(ctx context.Context, t client.Client, monitor
|
||||||
|
|
||||||
for _, group := range monitor.WorkerGroups {
|
for _, group := range monitor.WorkerGroups {
|
||||||
options := client.ScheduleOptions{
|
options := client.ScheduleOptions{
|
||||||
ID: getScheduleId(monitor, group),
|
ID: getScheduleId(monitor, group.Slug),
|
||||||
//SearchAttributes: map[string]interface{}{
|
|
||||||
// "worker-group": group,
|
|
||||||
// "monitor-slug": monitor.Slug,
|
|
||||||
//},
|
|
||||||
Spec: client.ScheduleSpec{
|
Spec: client.ScheduleSpec{
|
||||||
CronExpressions: []string{monitor.Schedule},
|
CronExpressions: []string{monitor.Schedule},
|
||||||
Jitter: time.Second * 10,
|
Jitter: time.Second * 10,
|
||||||
},
|
},
|
||||||
Action: &client.ScheduleWorkflowAction{
|
Action: &client.ScheduleWorkflowAction{
|
||||||
ID: getScheduleId(monitor, group),
|
ID: getScheduleId(monitor, group.Slug),
|
||||||
Workflow: workflows.NewWorkflows(nil).MonitorWorkflowDefinition,
|
Workflow: workflows.NewWorkflows(nil).MonitorWorkflowDefinition,
|
||||||
Args: args,
|
Args: args,
|
||||||
TaskQueue: group,
|
TaskQueue: group.Slug,
|
||||||
RetryPolicy: &temporal.RetryPolicy{
|
RetryPolicy: &temporal.RetryPolicy{
|
||||||
MaximumAttempts: 3,
|
MaximumAttempts: 3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule := t.ScheduleClient().GetHandle(ctx, getScheduleId(monitor, group))
|
schedule := t.ScheduleClient().GetHandle(ctx, getScheduleId(monitor, group.Slug))
|
||||||
|
|
||||||
// If exists, we update
|
// If exists, we update
|
||||||
_, err := schedule.Describe(ctx)
|
_, err := schedule.Describe(ctx)
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package services
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models"
|
|
||||||
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateWorker(ctx context.Context, q *query.Query, worker *models.Worker) error {
|
|
||||||
return q.Worker.WithContext(ctx).Create(worker)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetWorker(ctx context.Context, q *query.Query, slug string) (*models.Worker, error) {
|
|
||||||
log.Println("GetWorker")
|
|
||||||
return q.Worker.WithContext(ctx).Where(
|
|
||||||
q.Worker.Slug.Eq(slug),
|
|
||||||
).First()
|
|
||||||
}
|
|
44
internal/services/worker_group.go
Normal file
44
internal/services/worker_group.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/models"
|
||||||
|
"code.tjo.space/mentos1386/zdravko/internal/models/query"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetOrCreateWorkerGroup(ctx context.Context, q *query.Query, workerGroup models.WorkerGroup) (*models.WorkerGroup, error) {
|
||||||
|
tx := q.Begin()
|
||||||
|
|
||||||
|
if err := tx.WorkerGroup.WithContext(ctx).Clauses(clause.OnConflict{DoNothing: true}).Create(&workerGroup); err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
wg, err := tx.WorkerGroup.WithContext(ctx).Where(
|
||||||
|
q.WorkerGroup.Slug.Eq(workerGroup.Slug),
|
||||||
|
).First()
|
||||||
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return wg, tx.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWorkerGroups(ctx context.Context, q *query.Query) ([]*models.WorkerGroup, error) {
|
||||||
|
return q.WorkerGroup.WithContext(ctx).Preload(q.WorkerGroup.Monitors).Find()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWorkerGroupsBySlug(ctx context.Context, q *query.Query, slugs []string) ([]*models.WorkerGroup, error) {
|
||||||
|
return q.WorkerGroup.WithContext(ctx).Where(
|
||||||
|
q.WorkerGroup.Slug.In(slugs...),
|
||||||
|
).Find()
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWorkerGroup(ctx context.Context, q *query.Query, slug string) (*models.WorkerGroup, error) {
|
||||||
|
return q.WorkerGroup.WithContext(ctx).Where(
|
||||||
|
q.WorkerGroup.Slug.Eq(slug),
|
||||||
|
).First()
|
||||||
|
}
|
|
@ -39,7 +39,7 @@ func ConnectServerToTemporal(cfg *config.ServerConfig) (client.Client, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectWorkerToTemporal(token string, temporalHost string, identity string) (client.Client, error) {
|
func ConnectWorkerToTemporal(token string, temporalHost string) (client.Client, error) {
|
||||||
provider := &AuthHeadersProvider{token}
|
provider := &AuthHeadersProvider{token}
|
||||||
|
|
||||||
// Try to connect to the Temporal Server
|
// Try to connect to the Temporal Server
|
||||||
|
@ -48,7 +48,6 @@ func ConnectWorkerToTemporal(token string, temporalHost string, identity string)
|
||||||
HostPort: temporalHost,
|
HostPort: temporalHost,
|
||||||
HeadersProvider: provider,
|
HeadersProvider: provider,
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
Identity: identity,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to connect to Temporal Server: "+temporalHost)
|
return nil, errors.Wrap(err, "failed to connect to Temporal Server: "+temporalHost)
|
||||||
|
|
4
justfile
4
justfile
|
@ -16,7 +16,9 @@ _default:
|
||||||
|
|
||||||
# Run full development environment
|
# Run full development environment
|
||||||
run:
|
run:
|
||||||
devbox services up
|
watchexec -r -e tmpl,css just _tailwindcss-build | sed -e 's/^/tailwind: /;' &
|
||||||
|
just run-temporal | sed -e 's/^/temporal: /;' &
|
||||||
|
watchexec -r -e go,tmpl,css just run-server
|
||||||
|
|
||||||
# Start worker
|
# Start worker
|
||||||
run-worker:
|
run-worker:
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (s *Server) Name() string {
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
s.echo.Renderer = templates.NewTemplates()
|
s.echo.Renderer = templates.NewTemplates()
|
||||||
s.echo.Use(middleware.Logger())
|
//s.echo.Use(middleware.Logger())
|
||||||
s.echo.Use(middleware.Recover())
|
s.echo.Use(middleware.Recover())
|
||||||
|
|
||||||
db, query, err := internal.ConnectToDatabase(s.cfg.DatabasePath)
|
db, query, err := internal.ConnectToDatabase(s.cfg.DatabasePath)
|
||||||
|
@ -83,10 +83,10 @@ func (s *Server) Start() error {
|
||||||
settings.POST("/monitors/create", h.SettingsMonitorsCreatePOST)
|
settings.POST("/monitors/create", h.SettingsMonitorsCreatePOST)
|
||||||
settings.GET("/monitors/:slug", h.SettingsMonitorsDescribeGET)
|
settings.GET("/monitors/:slug", h.SettingsMonitorsDescribeGET)
|
||||||
settings.POST("/monitors/:slug", h.SettingsMonitorsDescribePOST)
|
settings.POST("/monitors/:slug", h.SettingsMonitorsDescribePOST)
|
||||||
settings.GET("/workers", h.SettingsWorkersGET)
|
settings.GET("/worker-groups", h.SettingsWorkerGroupsGET)
|
||||||
settings.GET("/workers/create", h.SettingsWorkersCreateGET)
|
settings.GET("/worker-groups/create", h.SettingsWorkerGroupsCreateGET)
|
||||||
settings.POST("/workers/create", h.SettingsWorkersCreatePOST)
|
settings.POST("/worker-groups/create", h.SettingsWorkerGroupsCreatePOST)
|
||||||
settings.GET("/workers/:slug", h.SettingsWorkersDescribeGET)
|
settings.GET("/worker-groups/:slug", h.SettingsWorkerGroupsDescribeGET)
|
||||||
settings.Match([]string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"}, "/temporal*", h.Temporal)
|
settings.Match([]string{"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"}, "/temporal*", h.Temporal)
|
||||||
|
|
||||||
// OAuth2
|
// OAuth2
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
|
|
||||||
type ConnectionConfig struct {
|
type ConnectionConfig struct {
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
Slug string `json:"slug"`
|
|
||||||
Group string `json:"group"`
|
Group string `json:"group"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ func getConnectionConfig(token string, apiUrl string) (*ConnectionConfig, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode == http.StatusUnauthorized {
|
if res.StatusCode == http.StatusUnauthorized {
|
||||||
panic("WORKER_TOKEN is invalid. Either it expired or the worker was removed!")
|
panic("WORKER_GROUP_TOKEN is invalid. Either it expired or the worker was removed!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
|
@ -79,10 +78,9 @@ func (w *Worker) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Worker slug:", config.Slug)
|
log.Println("Worker Group:", config.Group)
|
||||||
log.Println("Worker group:", config.Group)
|
|
||||||
|
|
||||||
temporalClient, err := temporal.ConnectWorkerToTemporal(w.cfg.Token, config.Endpoint, config.Slug)
|
temporalClient, err := temporal.ConnectWorkerToTemporal(w.cfg.Token, config.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
version: "0.5"
|
|
||||||
|
|
||||||
processes:
|
|
||||||
server:
|
|
||||||
command: watchexec -r -e go,tmpl,css just run-server
|
|
||||||
availability:
|
|
||||||
restart: "always"
|
|
||||||
temporal:
|
|
||||||
command: just run-temporal
|
|
||||||
availability:
|
|
||||||
restart: "always"
|
|
||||||
tailwind:
|
|
||||||
command: watchexec -r -e go,tmpl,css just _tailwindcss-build
|
|
||||||
availability:
|
|
||||||
restart: "always"
|
|
|
@ -29,11 +29,9 @@ func main() {
|
||||||
|
|
||||||
// Generate default DAO interface for those specified structs
|
// Generate default DAO interface for those specified structs
|
||||||
g.ApplyBasic(
|
g.ApplyBasic(
|
||||||
models.Worker{},
|
|
||||||
models.Monitor{},
|
models.Monitor{},
|
||||||
|
models.WorkerGroup{},
|
||||||
models.MonitorHistory{},
|
models.MonitorHistory{},
|
||||||
models.Cronjob{},
|
|
||||||
models.CronjobHistory{},
|
|
||||||
models.OAuth2State{},
|
models.OAuth2State{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,14 @@ code {
|
||||||
.settings section {
|
.settings section {
|
||||||
@apply relative overflow-x-auto shadow-md sm:rounded-lg text-gray-500 bg-white;
|
@apply relative overflow-x-auto shadow-md sm:rounded-lg text-gray-500 bg-white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings section h2 {
|
.settings section h2 {
|
||||||
@apply flex flex-col text-lg font-semibold text-gray-900;
|
@apply flex flex-col text-lg font-semibold text-gray-900;
|
||||||
}
|
}
|
||||||
.settings section h2 span {
|
.settings section h2 span {
|
||||||
@apply text-sm font-medium text-gray-500;
|
@apply text-sm font-medium text-gray-500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings section form {
|
.settings section form {
|
||||||
@apply grid gap-4 grid-cols-1 sm:grid-cols-[2fr_1fr];
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-[2fr_1fr];
|
||||||
}
|
}
|
||||||
|
@ -104,3 +106,16 @@ code {
|
||||||
@apply text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center;
|
@apply text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center;
|
||||||
@apply sm:col-span-2;
|
@apply sm:col-span-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings section table thead {
|
||||||
|
@apply text-xs text-gray-700 uppercase bg-gray-50;
|
||||||
|
}
|
||||||
|
.settings section table thead th {
|
||||||
|
@apply px-6 py-3 text-center;
|
||||||
|
}
|
||||||
|
.settings section table tbody th {
|
||||||
|
@apply px-6 py-4 font-medium text-gray-900 whitespace-nowrap text-center;
|
||||||
|
}
|
||||||
|
.settings section table tbody tr {
|
||||||
|
@apply px-6 py-4 text-center;
|
||||||
|
}
|
||||||
|
|
|
@ -1509,14 +1509,42 @@ code {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.odd\:bg-white:nth-child(odd) {
|
.settings section table thead {
|
||||||
--tw-bg-opacity: 1;
|
|
||||||
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
|
||||||
}
|
|
||||||
|
|
||||||
.even\:bg-gray-50:nth-child(even) {
|
|
||||||
--tw-bg-opacity: 1;
|
--tw-bg-opacity: 1;
|
||||||
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
|
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
|
||||||
|
font-size: 0.75rem;
|
||||||
|
line-height: 1rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(55 65 81 / var(--tw-text-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings section table thead th {
|
||||||
|
padding-left: 1.5rem;
|
||||||
|
padding-right: 1.5rem;
|
||||||
|
padding-top: 0.75rem;
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings section table tbody th {
|
||||||
|
white-space: nowrap;
|
||||||
|
padding-left: 1.5rem;
|
||||||
|
padding-right: 1.5rem;
|
||||||
|
padding-top: 1rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 500;
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(17 24 39 / var(--tw-text-opacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings section table tbody tr {
|
||||||
|
padding-left: 1.5rem;
|
||||||
|
padding-right: 1.5rem;
|
||||||
|
padding-top: 1rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hover\:bg-blue-800:hover {
|
.hover\:bg-blue-800:hover {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
There are no Incidents, yet.
|
There are no Incidents, yet.
|
||||||
</h1>
|
</h1>
|
||||||
<p class="mb-8 text-l font-normal text-gray-500 lg:text-l sm:px-8 lg:px-40">
|
<p class="mb-8 text-l font-normal text-gray-500 lg:text-l sm:px-8 lg:px-40">
|
||||||
Incidents will allow you to inform your users or co-workers about outages and issues.
|
Incidents will allow you to inform your users or co-worker groups about outages and issues.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{define "settings"}}
|
{{define "settings"}}
|
||||||
|
|
||||||
{{ $description := "Monitors represent periodicly the k6 script, to see if the monitored service is healthy." }}
|
{{ $description := "Monitors are constantly checking weather a service is online and working correctly." }}
|
||||||
|
|
||||||
{{ if eq .MonitorsLength 0 }}
|
{{ if eq .MonitorsLength 0 }}
|
||||||
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
|
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
|
||||||
|
@ -34,37 +34,37 @@
|
||||||
</caption>
|
</caption>
|
||||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col">
|
||||||
Name
|
Name
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col">
|
||||||
Worker Groups
|
Worker Groups
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col">
|
||||||
Status
|
Status
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col">
|
||||||
Schedule
|
Schedule
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th scope="col">
|
||||||
Action
|
Action
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{range .Monitors}}
|
{{range .Monitors}}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="odd:bg-white even:bg-gray-50">
|
<tr>
|
||||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
<th scope="row">
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</th>
|
</th>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
{{range .WorkerGroups}}
|
{{range .WorkerGroups}}
|
||||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
|
||||||
{{ . }}
|
{{ .Name }}
|
||||||
</span>
|
</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
||||||
ACTIVE
|
ACTIVE
|
||||||
</span>
|
</span>
|
||||||
|
@ -72,10 +72,10 @@
|
||||||
PAUSED
|
PAUSED
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
{{.Schedule}}
|
{{.Schedule}}
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
<a href="/settings/monitors/{{.Slug}}" class="link">Details</a>
|
<a href="/settings/monitors/{{.Slug}}" class="link">Details</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
Configuration
|
Configuration
|
||||||
</h2>
|
</h2>
|
||||||
<label for="workergroups">Worker Groups</label>
|
<label for="workergroups">Worker Groups</label>
|
||||||
<input type="text" name="workergroups" id="workergroups" value="{{ StringsJoin .Monitor.WorkerGroups " " }}"/>
|
<input type="text" name="workergroups" id="workergroups" value="{{ range .Monitor.WorkerGroups }}{{.Name}} {{end}}"/>
|
||||||
<p>Worker groups are used to distribute the monitor to specific workers.</p>
|
<p>Worker groups are used to distribute the monitor to specific workers.</p>
|
||||||
<label for="schedule">Schedule</label>
|
<label for="schedule">Schedule</label>
|
||||||
<input type="text" name="schedule" id="schedule" value="{{ .Monitor.Schedule }}"/>
|
<input type="text" name="schedule" id="schedule" value="{{ .Monitor.Schedule }}"/>
|
||||||
|
|
|
@ -9,23 +9,17 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mx-auto max-w-screen-xl flex flex-col sm:flex-row gap-4">
|
<div class="mx-auto max-w-screen-xl flex flex-col sm:flex-row gap-4">
|
||||||
<div class="inline-block bg-white rounded-lg shadow p-5 w-full">
|
<div class="inline-block bg-white rounded-lg shadow p-5 text-center sm:mt-0 sm:ml-2 sm:text-left">
|
||||||
<div class="text-center sm:mt-0 sm:ml-2 sm:text-left">
|
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Workers</h3>
|
||||||
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Workers</h3>
|
<p class="text-3xl font-bold text-black">42</p>
|
||||||
<p class="text-3xl font-bold text-black">42</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="inline-block bg-white rounded-lg shadow p-5 w-full">
|
<div class="inline-block bg-white rounded-lg shadow p-5 text-center sm:mt-0 sm:ml-2 sm:text-left">
|
||||||
<div class="text-center sm:mt-0 sm:ml-2 sm:text-left">
|
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Monitors</h3>
|
||||||
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Monitors</h3>
|
<p class="text-3xl font-bold text-black">42</p>
|
||||||
<p class="text-3xl font-bold text-black">42</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="inline-block bg-white rounded-lg shadow p-5 w-full">
|
<div class="inline-block bg-white rounded-lg shadow p-5 text-center sm:mt-0 sm:ml-2 sm:text-left">
|
||||||
<div class="text-center sm:mt-0 sm:ml-2 sm:text-left">
|
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Notifications</h3>
|
||||||
<h3 class="text-sm leading-6 font-medium text-gray-400">Total Notifications</h3>
|
<p class="text-3xl font-bold text-black">42</p>
|
||||||
<p class="text-3xl font-bold text-black">42</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
{{define "settings"}}
|
{{define "settings"}}
|
||||||
|
|
||||||
{{ $description := "Workers are executing monitors. You can deploy multiple of thems to multiple regions for wider coverage." }}
|
{{ $description := "Worker Groups are used to match multiple workers together. They can be used to difirentiate between regions, environments, networks etc." }}
|
||||||
|
|
||||||
{{ if eq .WorkersLength 0 }}
|
{{ if eq .WorkerGroupsLength 0 }}
|
||||||
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
|
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16">
|
||||||
<h1 class="mb-4 text-2xl font-extrabold tracking-tight leading-none text-gray-900 md:text-3xl lg:text-4xl">
|
<h1 class="mb-4 text-2xl font-extrabold tracking-tight leading-none text-gray-900 md:text-3xl lg:text-4xl">
|
||||||
There are no workers yet.
|
There are no worker groups yet.
|
||||||
</h1>
|
</h1>
|
||||||
<p class="mb-8 text-l font-normal text-gray-500 lg:text-l sm:px-8 lg:px-40">
|
<p class="mb-8 text-l font-normal text-gray-500 lg:text-l sm:px-8 lg:px-40">
|
||||||
{{ $description }}
|
{{ $description }}
|
||||||
</p>
|
</p>
|
||||||
<div class="flex flex-col space-y-4 sm:flex-row sm:justify-center sm:space-y-0">
|
<div class="flex flex-col space-y-4 sm:flex-row sm:justify-center sm:space-y-0">
|
||||||
<a href="/settings/workers/create" class="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
|
<a href="/settings/worker-groups/create" class="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
|
||||||
Create First Worker
|
Create First Worker Group
|
||||||
<svg class="feather ml-1 h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
|
<svg class="feather ml-1 h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,12 +21,12 @@
|
||||||
<section>
|
<section>
|
||||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
<table class="w-full text-sm text-left rtl:text-right text-gray-500">
|
||||||
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white">
|
||||||
List of Workers
|
List of Worker Groups
|
||||||
<div class="mt-1 gap-4 flex justify-between">
|
<div class="mt-1 gap-4 flex justify-between">
|
||||||
<p class="mt-1 text-sm font-normal text-gray-500">
|
<p class="mt-1 text-sm font-normal text-gray-500">
|
||||||
{{ $description }}
|
{{ $description }}
|
||||||
</p>
|
</p>
|
||||||
<a href="/settings/workers/create" class="inline-flex justify-center items-center py-1 px-2 text-sm font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
|
<a href="/settings/worker-groups/create" class="inline-flex justify-center items-center py-1 px-2 text-sm font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300">
|
||||||
Create New
|
Create New
|
||||||
<svg class="feather h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
|
<svg class="feather h-5 w-5 overflow-visible"><use href="/static/icons/feather-sprite.svg#plus" /></svg>
|
||||||
</a>
|
</a>
|
||||||
|
@ -34,41 +34,39 @@
|
||||||
</caption>
|
</caption>
|
||||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th>
|
||||||
Name
|
Name
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th>
|
||||||
Group
|
Workers
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th>
|
||||||
Status
|
Monitors
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th>
|
||||||
Action
|
Action
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{range .Workers}}
|
{{range .WorkerGroups}}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="odd:bg-white even:bg-gray-50">
|
<tr>
|
||||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
<th scope="row">
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</th>
|
</th>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
|
|
||||||
{{.Group}}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4">
|
|
||||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
||||||
ONLINE
|
10 ONLINE
|
||||||
</span>
|
</span>
|
||||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
|
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
|
||||||
OFFLINE
|
NONE
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4">
|
<td>
|
||||||
<a href="/settings/workers/{{.Slug}}" class="link">Details</a>
|
{{ len .Monitors }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/settings/worker-groups/{{.Slug}}" class="link">Details</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
10
web/templates/pages/settings_worker_groups_create.tmpl
Normal file
10
web/templates/pages/settings_worker_groups_create.tmpl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{{define "settings"}}
|
||||||
|
<section class="p-5">
|
||||||
|
<form action="/settings/worker-groups/create" method="post">
|
||||||
|
<label for="name" class="block mb-2 text-sm font-medium text-gray-900">Name</label>
|
||||||
|
<input type="text" name="name" id="name" placeholder="aws-eu-central-1"/>
|
||||||
|
<p>Worker group name can be anything.</p>
|
||||||
|
<button type="submit">Create</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
|
@ -1,23 +1,8 @@
|
||||||
{{define "settings"}}
|
{{define "settings"}}
|
||||||
<section class="p-5">
|
|
||||||
<form action="/settings/workers/{{ .Worker.Slug }}" method="post">
|
|
||||||
<h2>
|
|
||||||
Configuration
|
|
||||||
</h2>
|
|
||||||
<label for="group">Group</label>
|
|
||||||
<input type="text" name="group" id="group" value="{{ .Worker.Group }}"/>
|
|
||||||
<p>
|
|
||||||
Group is used to distinguish between different workers.
|
|
||||||
For example, you can have a group for different regions,
|
|
||||||
different datacenters or different environments.
|
|
||||||
</p>
|
|
||||||
<button type="submit" onclick="save()">Save</button>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
<section class="p-5">
|
<section class="p-5">
|
||||||
<h2>
|
<h2>
|
||||||
Token
|
Token
|
||||||
<span>Use it as <code>WORKER_TOKEN</code> configuration option.</span>
|
<span>Use it as <code>WORKER_GROUP_TOKEN</code> configuration option.</span>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="grid grid-cols-[auto_min-content] gap-2">
|
<div class="grid grid-cols-[auto_min-content] gap-2">
|
||||||
<pre id="token" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 overflow-x-auto">{{ .Worker.Token }}</pre>
|
<pre id="token" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 overflow-x-auto">{{ .Worker.Token }}</pre>
|
|
@ -1,17 +0,0 @@
|
||||||
{{define "settings"}}
|
|
||||||
<section class="p-5">
|
|
||||||
<form action="/settings/workers/create" method="post">
|
|
||||||
<label for="name" class="block mb-2 text-sm font-medium text-gray-900">Name</label>
|
|
||||||
<input type="text" name="name" id="name" placeholder="aws-eu-central-1"/>
|
|
||||||
<p>Worker name can be anything.</p>
|
|
||||||
<label for="group" class="block mb-2 text-sm font-medium text-gray-900">Group</label>
|
|
||||||
<input type="text" name="group" id="group" placeholder="EU"/>
|
|
||||||
<p>
|
|
||||||
Group is used to distinguish between different workers.
|
|
||||||
For example, you can have a group for different regions,
|
|
||||||
different datacenters or different environments.
|
|
||||||
</p>
|
|
||||||
<button type="submit">Create</button>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
{{end}}
|
|
|
@ -38,16 +38,16 @@ func loadSettings(files ...string) *template.Template {
|
||||||
func NewTemplates() *Templates {
|
func NewTemplates() *Templates {
|
||||||
return &Templates{
|
return &Templates{
|
||||||
templates: map[string]*template.Template{
|
templates: map[string]*template.Template{
|
||||||
"404.tmpl": load("pages/404.tmpl"),
|
"404.tmpl": load("pages/404.tmpl"),
|
||||||
"index.tmpl": load("pages/index.tmpl"),
|
"index.tmpl": load("pages/index.tmpl"),
|
||||||
"incidents.tmpl": load("pages/incidents.tmpl"),
|
"incidents.tmpl": load("pages/incidents.tmpl"),
|
||||||
"settings_overview.tmpl": loadSettings("pages/settings_overview.tmpl"),
|
"settings_overview.tmpl": loadSettings("pages/settings_overview.tmpl"),
|
||||||
"settings_workers.tmpl": loadSettings("pages/settings_workers.tmpl"),
|
"settings_worker_groups.tmpl": loadSettings("pages/settings_worker_groups.tmpl"),
|
||||||
"settings_workers_create.tmpl": loadSettings("pages/settings_workers_create.tmpl"),
|
"settings_worker_groups_create.tmpl": loadSettings("pages/settings_worker_groups_create.tmpl"),
|
||||||
"settings_workers_describe.tmpl": loadSettings("pages/settings_workers_describe.tmpl"),
|
"settings_worker_groups_describe.tmpl": loadSettings("pages/settings_worker_groups_describe.tmpl"),
|
||||||
"settings_monitors.tmpl": loadSettings("pages/settings_monitors.tmpl"),
|
"settings_monitors.tmpl": loadSettings("pages/settings_monitors.tmpl"),
|
||||||
"settings_monitors_create.tmpl": loadSettings("pages/settings_monitors_create.tmpl"),
|
"settings_monitors_create.tmpl": loadSettings("pages/settings_monitors_create.tmpl"),
|
||||||
"settings_monitors_describe.tmpl": loadSettings("pages/settings_monitors_describe.tmpl"),
|
"settings_monitors_describe.tmpl": loadSettings("pages/settings_monitors_describe.tmpl"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue