// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package job

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RefreshWorkerJobLockLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRefreshWorkerJobLockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshWorkerJobLockLogic {
	return &RefreshWorkerJobLockLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RefreshWorkerJobLockLogic) RefreshWorkerJobLock(req *types.WorkerHeartbeatReq) (resp *types.WorkerOKData, err error) {
	ttl := req.TTLSeconds
	if ttl <= 0 {
		ttl = 300
	}
	err = l.svcCtx.Job.RefreshRunLock(l.ctx, req.ID, req.WorkerID, ttl)
	return &types.WorkerOKData{OK: err == nil}, err
}
