Skip to content

Commit eb264de

Browse files
authored
Merge pull request #105 from fmotalleb/vars
2 parents 81d445e + 0768dda commit eb264de

File tree

18 files changed

+153
-83
lines changed

18 files changed

+153
-83
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"envFile": "${workspaceFolder}/.env",
1515
"args": [
1616
"-c",
17-
"config.local.yaml"
17+
"config.local.yaml",
18+
"-v"
1819
]
1920
},
2021
{

CHANGELOG.md

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,81 @@
1+
12
# Changelog
23

3-
## 0.2
4-
5-
* Docker integration
6-
* Execute the command inside a running container (using attach)
7-
* Create new container (using given image name) and then run the command inside it
8-
9-
* Command execution credentials (unix only)
10-
11-
## v0.1
12-
13-
* Initial release
14-
* Added support for multiple scheduler methods:
15-
* Cron string (with seconds)
16-
* Interval (duration)
17-
* At (time)
18-
* Tasks:
19-
* Built-in http request methods (get,post)
20-
* Can invoke external commands (same as cron)
21-
* Supports setting environments variable
22-
* Can be configured to use any terminal/shell you want such as sh,bash,nu,cmd,powershell,...
23-
* Can have retries per task (on commands exit-code !=0 or http request errors)
24-
* Support for hooks, for both when tasks fail or they finish successfully (structure is the same as a task)
25-
* Multiple scheduler for each job
26-
* Multiple task for each job
27-
* Logging:
28-
* File logging
29-
* ansi/plain/json log formatter
4+
This file summarizes notable changes for each released tag. Trivial noise (merge commits, many dependabot lines and minor chore commits) has been removed to keep the history focused.
5+
6+
## v0.1 (2024-06-06)
7+
8+
- MVP and core features: command implementation, get/post/executable tasks, file log writer, compiler for Task.
9+
- Schedulers: initial support for interval, cron and at schedulers.
10+
- Config and validation: initial config structure and config validation added.
11+
12+
## v0.1.1 (2024-06-07)
13+
14+
- Improvements to concurrency and task-runner: concurrency lock, concurrency config field and sync.Locker implementation.
15+
- Cron improvements: optional seconds field, macros support and docs updates.
16+
- Added config schema and miscellaneous optimizations.
17+
18+
## v0.2 (2024-06-12)
19+
20+
- Docker connection: create containers from images and a fully functional docker connection implementation.
21+
- Per-task hooks and dynamic task connections.
22+
- Credential manager + validator and other robustness fixes.
23+
24+
## v0.4 (2024-06-30)
25+
26+
- Integrated cron parser and sanitizer.
27+
- Webserver and HTTP event listener added.
28+
- Notable breaking change: scheduler renamed to event.
29+
- Various fixes and race-condition fixes in concurrent pool and test coverage improvements.
30+
31+
## v0.4.1 — v0.4.5 (2024-07-01 → 2024-07-02)
32+
33+
- Releases focused on Docker-related fixes, CI tweaks, and stability fixes (docker image/ghcr, docker API migration, CI updates).
34+
35+
## v0.5.0 (2024-07-06)
36+
37+
- Metrics/exporters: added basic exporters including command status and event counter exporter.
38+
- Fixes for global context and concurrency behavior.
39+
40+
## v0.6.0-alpha → v0.6.0 (2024-07-13 → 2024-07-29)
41+
42+
- Docker event listener and utilities added.
43+
- Exported/overhauled some functionalities and various dependency bumps for docker-related modules.
44+
45+
## v0.7.x (2024-08-17 → 2024-09-10)
46+
47+
- Improvements: environ key handling, logfile watcher, command event arg mode.
48+
- Multiple dependency updates and bug fixes; numerous small improvements and tests.
49+
50+
## v0.7.4 → v0.7.6 (2025-02-17 → 2025-05-12)
51+
52+
- Tooling updates: Go version bumped to 1.24, multiple dependabot dependency bumps and CI/tooling maintenance.
53+
- Fixes: deadlock and race-condition fixes.
54+
55+
## v0.8.x (2025-05-20 → 2025-07-26)
56+
57+
- Major refactor and system design improvements: generator-based approach, redesigned template engine, command context immutability.
58+
- CI/CD and goreleaser/workflow fixes and simplifications. Docker and template-related fixes.
59+
60+
## v0.9.0 (2025-09-27)
61+
62+
- Template engine: switched to go-tools version and added query params support.
63+
- Various dependency bumps and tooling updates.
64+
65+
## v0.9.1 (2025-11-04)
66+
67+
- Versioning and release tweaks; added version data to CLI command.
68+
- Dependency/tooling bumps (CodeQL, actions, docker, etc.).
69+
70+
## v0.9.2 (2025-11-08)
71+
72+
- Bump: docker to latest version.
73+
- Hotfix: added buffer size to zip channel (10 items per input).
74+
- Feature: added signal handling.
75+
- Fix: concurrent write exception fix.
76+
77+
## v0.10.0 (2025-11-08)
78+
79+
- Feature: per-task variables that can be used in hooks.
80+
- Chore: switch logger to zap logger.
81+
- Fix: remove redundant println in cron registration.

cmd/parser/cron_string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ func (s *CronString) parseAsSpec(
6868
specs := make([]cronSpec, 0)
6969
lines := s.sanitize().lines()
7070
matcher, parser, err := buildMapper(hasUser, pattern)
71-
log.Debug("parsing lines using line matcher", zap.String("matcher", matcher.String()))
7271
if err != nil {
7372
return []cronSpec{}, err
7473
}
74+
log.Debug("parsing lines using line matcher", zap.String("matcher", matcher.String()))
7575
for num, line := range lines {
7676
l := cronLine{line}
7777
if env, err := l.exportEnv(); len(env) > 0 {

cmd/parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func run(cmd *cobra.Command, _ []string) {
5454
}
5555

5656
func writeOutput(log *zap.Logger, cfg *parserConfig, result string) {
57-
outputFile, err := os.OpenFile(cfg.output, os.O_WRONLY|os.O_CREATE, 0o644)
57+
outputFile, err := os.OpenFile(cfg.output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
5858
if err != nil {
5959
log.Panic("failed to open output file", zap.Error(err))
6060
}

config.local.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
jobs:
44
- name: echo
55
tasks:
6-
- command: echo {{ now | date "2006-01-02_15-04-05" }}
6+
- command: echo {{ .Vars.name }}; sleep 5sec
7+
vars:
8+
name: '{{ now | date "2006-01-02_15-04-05" }}'
79
env:
810
COLE: test
911
on-done:
10-
- command: echo test $env.COLE
12+
- command: echo {{ .Vars.name }}
1113
# connections:
1214
# - image: "library/alpine"
1315

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ type Task struct {
8888
// Hooks
8989
OnDone []Task `mapstructure:"on-done" json:"on-done,omitempty"`
9090
OnFail []Task `mapstructure:"on-fail" json:"on-fail,omitempty"`
91+
92+
// Misc
93+
Vars map[string]string `mapstructure:"vars" json:"vars,omitempty"`
9194
}
9295

9396
// TaskConnection represents the connection configuration for a task.

core/cmd_connection/command/command.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package command
44
import (
55
"context"
66
"fmt"
7+
"maps"
78
"os"
89
"strings"
910

@@ -59,6 +60,14 @@ func (ctx Ctx) getEnv() map[string]string {
5960
return env
6061
}
6162

63+
func (ctx Ctx) getVars() map[string]string {
64+
env, ok := ctx.Value(ctxutils.Vars).(map[string]string)
65+
if !ok {
66+
return map[string]string{}
67+
}
68+
return env
69+
}
70+
6271
func (ctx Ctx) envReshape() []string {
6372
env := ctx.getEnv()
6473
result := make([]string, 0, len(env))
@@ -108,7 +117,10 @@ func (ctx Ctx) applyEventTemplate(src string) (string, error) {
108117
ctx.logger.Warn("Event not found in context")
109118
return src, nil
110119
}
111-
return applyTemplate(ctx.logger, src, event.GetData())
120+
data := maps.Clone(event.GetData())
121+
vars := ctx.getVars()
122+
data["Vars"] = vars
123+
return applyTemplate(ctx.logger, src, data)
112124
}
113125

114126
func (ctx Ctx) tryTemplate(src string) string {

core/cmd_connection/docker_attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (d *DockerAttachConnection) Execute() ([]byte, error) {
133133
d.log.Debug("output of stdout is fetched", zap.Int64("bytes", wrote))
134134
if err != nil {
135135
d.log.Debug("copy of std is failed", zap.Int64("until-err", wrote), zap.Error(err))
136-
return nil, err
136+
return writer.Bytes(), err
137137
}
138138
return writer.Bytes(), nil
139139
}

core/common/retry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ func IncreaseRetry(ctx context.Context) context.Context {
5252
}
5353

5454
func ResetRetries(ctx context.Context) context.Context {
55-
return context.WithValue(ctx, ctxutils.RetryCountKey, 0)
55+
return context.WithValue(ctx, ctxutils.RetryCountKey, RetryCount(0))
5656
}

core/event/logfile.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ func (lf *LogFile) BuildTickChannel() abstraction.EventChannel {
100100
}
101101
for {
102102
data, err := reader.ReadString(byte(0))
103-
lf.logger.Debug("failed to read line", zap.String("data", data), zap.Error(err))
104103
if err != nil && err != io.EOF {
105104
lf.logger.Error("error reading log file", zap.Error(err))
106105
return

0 commit comments

Comments
 (0)