稳定发布1.0.0

This commit is contained in:
2025-02-27 17:41:14 +08:00
parent b36e67f826
commit f251df5ce3
7 changed files with 47 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
location: wushan # 项目名称
point: 2 # 点位
point: 3 # 点位
relay:
maxTimeout: 60 # 单位 s必须大于 0
log:

View File

@@ -35,6 +35,7 @@ func Pause(ctrl *common.CtrlWait) leaf.HandlerFunc {
for {
select {
case <-originalCtx.Done():
cancel()
zap.S().Infoln("待机控制器监听结束")
return
case <-ctrl.R:

View File

@@ -12,7 +12,7 @@ func Unique(stopper common.Stopper) leaf.HandlerFunc {
var lock sync.Mutex
return func(c *leaf.Context) {
if !lock.TryLock() {
zap.S().Infoln("尝试加锁失败,执行停止任务")
zap.S().Infoln("停止之前的任务,再尝试加锁")
stopper.Stop()
lock.Lock()
}

View File

@@ -31,6 +31,9 @@ func runAction(c *leaf.Context, item schema.WaitItemModel, rootRules []cronrange
return
}
a := make(chan bool)
defer close(a)
// 等待组
var wait sync.WaitGroup
defer wait.Wait()
@@ -38,47 +41,58 @@ func runAction(c *leaf.Context, item schema.WaitItemModel, rootRules []cronrange
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
ctx, cancel := context.WithCancel(context.TODO())
var run bool
wait.Add(1)
go func() {
defer wait.Done()
for {
select {
case <-c.Done():
cancel()
return
case <-ticker.C:
if cronrange.Match(rules, time.Now()) && cronrange.Match(rootRules, time.Now()) {
run = true
a <- true
} else {
run = false
cancel()
a <- false
}
}
}
}()
var cancel context.CancelFunc
var m sync.Mutex
for {
select {
case <-c.Done():
if cancel != nil {
cancel()
}
return
default:
if run {
case r := <-a:
if r {
if ok := m.TryLock(); ok {
ctx, cc := context.WithCancel(context.TODO())
cancel = cc
wait.Add(1)
go func() {
defer wait.Done()
defer m.Unlock()
defer func() { cancel = nil }()
err := play(ctx, item)
if err != nil {
zap.S().Errorln("执行动作异常: ", err)
<-time.After(time.Minute)
}
} else {
select {
case <-c.Done():
case <-ctx.Done():
return
case <-time.After(time.Second):
case <-time.After(time.Minute):
}
}
}()
}
} else if cancel != nil {
cancel()
cancel = nil
}
}
}
}

View File

@@ -29,16 +29,14 @@ func Play(ctx context.Context, file string) error {
var wait sync.WaitGroup
defer wait.Wait()
a := make(chan struct{})
defer close(a)
wait.Add(1)
go func() {
defer wait.Done()
reader := bufio.NewReader(pipe)
for {
select {
case <-a:
case <-ctx.Done():
return
default:
line, _, err := reader.ReadLine()
if err != nil {

View File

@@ -127,7 +127,7 @@ Payload:
```json lines
{
// 执行的时间区间
// 执行的时间区间(需要系统配置正确时区)
"cron": "17:20-21:35 1-5 * *",
// 执行项
"items": [
@@ -148,6 +148,11 @@ Payload:
> 同一个类型的待机任务只能有一个,当有新的任务到达时会覆盖之前的任务
### 配置时区
```bash
sudo timedatectl set-timezone Asia/Shanghai
```
### Cron Format
The format consists of four fields separated by whitespace:

View File

@@ -106,6 +106,8 @@ ExecStart=-/sbin/agetty --autologin <your_username> --noclear %I $TERM
# }
```
如果没有 `~/.config/i3/config` 文件,需要重启系统,进入 i3 后,根据提示创建默认的配置文件
### 配置 i3
安装 `unclutter`