job

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2024 License: MIT Imports: 4 Imported by: 0

README

job 公共基类

提供以下功能

  • 支持同步执行任务、异步执行任务
  • 收集任务执行结果,推送至监控

接入指南

在main.go中初始化监控包

import "github.com/imkouga/kratos-pkg/inspect"

if err := inspect.Init1("组件名", "推送至监控的metric"); nil != err {
    // do something
}
// job示例

import "github.com/imkouga/kratos-pkg/contrib/job/jobset"

NodeJob struct {
    *BaseSet
}

func NewNodeJob()(*NodeJob,error) {

    js,err := jobset.NewJobSet()
    if nil != err {
        return nil, err
    }

    return &NodeJob{
        js,
    }, nil
}

func (j *NodeJob) CalNodeMinPlanLine(ctx context.Context, payload string) (string, error) {

    // 异步执行
	j.AsyncDo(ctx, "task_ename", "任务中文名", func() (string, error) {
        return "", nil
    }

    // 同步执行
    j.SyncDo(ctx, "task_ename", "任务中文名", func() (string, error) {
        return "", nil
    } 
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobSet

type JobSet struct{}

func NewJobSet

func NewJobSet(opts ...Option) (*JobSet, error)

func (*JobSet) AsyncDo

func (j *JobSet) AsyncDo(ctx context.Context, jobEName, jobName string, fn func() (string, error)) (string, error)

AsyncDo 异步执行

func (*JobSet) SyncDo

func (j *JobSet) SyncDo(ctx context.Context, jobEName, jobName string, fn func() (string, error)) (string, error)

SyncDo 同步执行

type Option

type Option func(j *JobSet)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL