-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abca67d
Showing
18 changed files
with
1,236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
VERSION := $(shell jq -r .version <package.json) | ||
|
||
APP := $(shell jq -r .name <package.json) | ||
PACKAGES := $(shell go list -f {{.Dir}} ./...) | ||
GOFILES := $(addsuffix /*.go,$(PACKAGES)) | ||
GOFILES := $(wildcard $(GOFILES)) | ||
|
||
.PHONY: clean release README.md | ||
|
||
clean: | ||
rm -rf binaries/ | ||
rm -rf release/ | ||
|
||
release-exists: | ||
hub release show "$(VERSION)" | ||
|
||
release: README.md zip | ||
git add package.json | ||
git add README.md | ||
git add Makefile | ||
git commit -am "Release $(VERSION)" || true | ||
git push | ||
hub release create $(VERSION) -m "$(VERSION)" -a release/$(APP)_$(VERSION)_osx_x86_64.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_64.zip -a release/$(APP)_$(VERSION)_linux_x86_64.tar.gz -a release/$(APP)_$(VERSION)_osx_x86_32.tar.gz -a release/$(APP)_$(VERSION)_windows_x86_32.zip -a release/$(APP)_$(VERSION)_linux_x86_32.tar.gz -a release/$(APP)_$(VERSION)_linux_arm64.tar.gz | ||
|
||
README.md: | ||
go get github.com/keilerkonzept/$(APP) && <README.template.md subst \ | ||
VERSION="$(VERSION)" APP="$(APP)" USAGE="$$($(APP) -h 2>&1)" > README.md | ||
|
||
zip: release/$(APP)_$(VERSION)_osx_x86_64.tar.gz release/$(APP)_$(VERSION)_windows_x86_64.zip release/$(APP)_$(VERSION)_linux_x86_64.tar.gz release/$(APP)_$(VERSION)_osx_x86_32.tar.gz release/$(APP)_$(VERSION)_windows_x86_32.zip release/$(APP)_$(VERSION)_linux_x86_32.tar.gz release/$(APP)_$(VERSION)_linux_arm64.tar.gz | ||
|
||
binaries: binaries/osx_x86_64/$(APP) binaries/windows_x86_64/$(APP).exe binaries/linux_x86_64/$(APP) binaries/osx_x86_32/$(APP) binaries/windows_x86_32/$(APP).exe binaries/linux_x86_32/$(APP) | ||
|
||
release/$(APP)_$(VERSION)_osx_x86_64.tar.gz: binaries/osx_x86_64/$(APP) | ||
mkdir -p release | ||
tar cfz release/$(APP)_$(VERSION)_osx_x86_64.tar.gz -C binaries/osx_x86_64 $(APP) | ||
|
||
binaries/osx_x86_64/$(APP): $(GOFILES) | ||
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/osx_x86_64/$(APP) . | ||
|
||
release/$(APP)_$(VERSION)_windows_x86_64.zip: binaries/windows_x86_64/$(APP).exe | ||
mkdir -p release | ||
cd ./binaries/windows_x86_64 && zip -r -D ../../release/$(APP)_$(VERSION)_windows_x86_64.zip $(APP).exe | ||
|
||
binaries/windows_x86_64/$(APP).exe: $(GOFILES) | ||
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/windows_x86_64/$(APP).exe . | ||
|
||
release/$(APP)_$(VERSION)_linux_x86_64.tar.gz: binaries/linux_x86_64/$(APP) | ||
mkdir -p release | ||
tar cfz release/$(APP)_$(VERSION)_linux_x86_64.tar.gz -C binaries/linux_x86_64 $(APP) | ||
|
||
binaries/linux_x86_64/$(APP): $(GOFILES) | ||
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/linux_x86_64/$(APP) . | ||
|
||
release/$(APP)_$(VERSION)_osx_x86_32.tar.gz: binaries/osx_x86_32/$(APP) | ||
mkdir -p release | ||
tar cfz release/$(APP)_$(VERSION)_osx_x86_32.tar.gz -C binaries/osx_x86_32 $(APP) | ||
|
||
binaries/osx_x86_32/$(APP): $(GOFILES) | ||
GOOS=darwin GOARCH=386 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/osx_x86_32/$(APP) . | ||
|
||
release/$(APP)_$(VERSION)_windows_x86_32.zip: binaries/windows_x86_32/$(APP).exe | ||
mkdir -p release | ||
cd ./binaries/windows_x86_32 && zip -r -D ../../release/$(APP)_$(VERSION)_windows_x86_32.zip $(APP).exe | ||
|
||
binaries/windows_x86_32/$(APP).exe: $(GOFILES) | ||
GOOS=windows GOARCH=386 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/windows_x86_32/$(APP).exe . | ||
|
||
release/$(APP)_$(VERSION)_linux_x86_32.tar.gz: binaries/linux_x86_32/$(APP) | ||
mkdir -p release | ||
tar cfz release/$(APP)_$(VERSION)_linux_x86_32.tar.gz -C binaries/linux_x86_32 $(APP) | ||
|
||
binaries/linux_x86_32/$(APP): $(GOFILES) | ||
GOOS=linux GOARCH=386 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/linux_x86_32/$(APP) . | ||
|
||
release/$(APP)_$(VERSION)_linux_arm64.tar.gz: binaries/linux_arm64/$(APP) | ||
mkdir -p release | ||
tar cfz release/$(APP)_$(VERSION)_linux_arm64.tar.gz -C binaries/linux_arm64 $(APP) | ||
|
||
binaries/linux_arm64/$(APP): $(GOFILES) | ||
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=$(VERSION) -X main.app=$(APP)" -o binaries/linux_arm64/$(APP) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# wait-for-cron-expression-match | ||
|
||
A tiny tool that waits until a given cron expression would trigger, and then just exits. If multiple expressions are given, it waits until the _first_ (earliest) match. | ||
|
||
## Example | ||
|
||
|
||
```sh | ||
$ wait-for-cron-expression-match "*/5 * * * * *" | ||
2020/07/08 17:57:17 waiting 2.998536s until next match (2020-07-08T17:57:20+02:00) of cron expression "*/5 * * * * *" | ||
$ # 2.998s later | ||
``` | ||
## Contents | ||
- [Get it](#get-it) | ||
- [Usage](#usage) | ||
## Get it | ||
Using go get: | ||
```bash | ||
go get -u github.com/keilerkonzept/wait-for-cron-expression-match | ||
``` | ||
Or [download the binary for your platform](https://github.com/keilerkonzept/wait-for-cron-expression-match/releases/latest) from the releases page. | ||
## Usage | ||
```text | ||
wait-for-cron-expression-match [CRON_EXPRESSION [CRON_EXPRESSIONS...]] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ${APP} | ||
|
||
A tiny tool that waits until a given cron expression would trigger, and then just exits. If multiple expressions are given, it waits until the _first_ (earliest) match. | ||
|
||
## Example | ||
|
||
|
||
```sh | ||
$ ${APP} "*/5 * * * * *" | ||
2020/07/08 17:57:17 waiting 2.998536s until next match (2020-07-08T17:57:20+02:00) of cron expression "*/5 * * * * *" | ||
$ # 2.998s later | ||
``` | ||
## Contents | ||
- [Get it](#get-it) | ||
- [Usage](#usage) | ||
## Get it | ||
Using go get: | ||
```bash | ||
go get -u github.com/keilerkonzept/${APP} | ||
``` | ||
Or [download the binary for your platform](https://github.com/keilerkonzept/${APP}/releases/latest) from the releases page. | ||
## Usage | ||
```text | ||
${APP} [CRON_EXPRESSION [CRON_EXPRESSIONS...]] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/keilerkonzept/wait-for-cron-expression-match | ||
|
||
go 1.14 | ||
|
||
require github.com/robfig/cron v1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= | ||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/robfig/cron" | ||
) | ||
|
||
var config struct { | ||
cronExpressions []string | ||
schedules []cron.Schedule | ||
evaluationInterval time.Duration | ||
} | ||
|
||
var app = "wait-for-cron-expression-match" | ||
|
||
func init() { | ||
log.SetFlags(log.Ltime | log.Ldate | log.Lmicroseconds) | ||
log.SetPrefix(fmt.Sprintf("[%s] ", app)) | ||
flag.Parse() | ||
|
||
config.evaluationInterval = 250 * time.Millisecond | ||
config.cronExpressions = flag.Args() | ||
|
||
if len(config.cronExpressions) == 0 { | ||
log.Fatal("at least one expression is required") | ||
} | ||
for _, e := range config.cronExpressions { | ||
schedule, err := cron.Parse(e) | ||
if err != nil { | ||
log.Fatalf("parse cron expression %q: %v", e, err) | ||
} | ||
config.schedules = append(config.schedules, schedule) | ||
} | ||
} | ||
|
||
func main() { | ||
now := time.Now() | ||
tickInterval := config.evaluationInterval | ||
var next time.Time | ||
for i, s := range config.schedules { | ||
nextNew := s.Next(now) | ||
if i == 0 || nextNew.Before(next) { | ||
next = nextNew | ||
} | ||
} | ||
delta := next.Sub(now) | ||
if delta < tickInterval { | ||
tickInterval = delta | ||
} | ||
tick := time.Tick(tickInterval) | ||
|
||
plural := "" | ||
if len(config.cronExpressions) > 1 { | ||
plural = "s" | ||
} | ||
log.Printf("waiting %v until next match (%v) of cron expression%s %q", delta, next.Format(time.RFC3339Nano), plural, config.cronExpressions) | ||
defer log.Print("done") | ||
for now = range tick { | ||
if now.After(next) { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "wait-for-cron-expression-match", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"config:base" | ||
], | ||
"automerge": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.