From c6de7a1b2412c2505626146a3a5d3e618f0c7d91 Mon Sep 17 00:00:00 2001 From: Pau Rodriguez-Estivill Date: Tue, 11 Feb 2020 13:22:17 +0100 Subject: [PATCH] Reorganitzation and updated to robfig/cron v3 --- LICENSE | 8 +++++--- Makefile | 16 ---------------- build-docker.sh | 5 +++++ build.sh | 19 +++++++++++++++++++ crane.yml | 14 -------------- go.mod | 5 +++++ go.sum | 2 ++ go-cron.go => gocron/go-cron.go | 2 +- httpserver.go => gocron/httpserver.go | 0 bin/go-cron.go => main.go | 5 +++-- test.sh | 3 +++ test/run | 3 --- 12 files changed, 43 insertions(+), 39 deletions(-) delete mode 100644 Makefile create mode 100755 build-docker.sh create mode 100755 build.sh delete mode 100644 crane.yml create mode 100644 go.mod create mode 100644 go.sum rename go-cron.go => gocron/go-cron.go (98%) rename httpserver.go => gocron/httpserver.go (100%) rename bin/go-cron.go => main.go (91%) create mode 100755 test.sh delete mode 100755 test/run diff --git a/LICENSE b/LICENSE index 31968e9..907cbec 100644 --- a/LICENSE +++ b/LICENSE @@ -1,10 +1,12 @@ -This code is based on the work of Michał Rączka and forked from the -michaloo/go-cron Github project. All extensions were made under same -MIT license. +This code is based on the work of Michał Rączka and Jan Nabbefeld +from their michaloo/go-cron and odise/go-cron Github projects respectively. +All extensions were made under same MIT license. The MIT License (MIT) +Copyright (c) 2014 Michał Rączka Copyright (c) 2014 Jan Nabbefeld +Copyright (c) 2020 Pau Rodriguez-Estivill Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile deleted file mode 100644 index f75f697..0000000 --- a/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOKEN = `cat .token` -REPO := go-cron -USER := odise -VERSION := "v0.0.4" - -build: - mkdir -p out/darwin out/linux - GOOS=darwin go build -o out/darwin/go-cron -ldflags "-X main.build `git rev-parse --short HEAD`" bin/go-cron.go - GOOS=linux go build -o out/linux/go-cron -ldflags "-X main.build `git rev-parse --short HEAD`" bin/go-cron.go - -release: build - rm -f out/darwin/go-cron-osx.gz - gzip -c out/darwin/go-cron > out/darwin/go-cron-osx.gz - rm -f out/linux/go-cron-linux.gz - gzip -c out/linux/go-cron > out/linux/go-cron-linux.gz - diff --git a/build-docker.sh b/build-docker.sh new file mode 100755 index 0000000..6fe6a9d --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,5 @@ +#!/bin/sh -e + +cd $(dirname $0) + +exec docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang ./build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..537e7a4 --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh -e + +TARGETS="linux-amd64 linux-arm64 linux-arm linux-386 darwin-amd64 windows-amd64" +STATIC_TARGETS="linux-amd64 linux-arm64 linux-arm linux-386" +BUILD=`git rev-parse --short HEAD` +VERSION=`git describe --tags` +MAIN_GO="main.go" +DEPS="github.com/robfig/cron" + +cd $(dirname $0) +mkdir -p dist + +for TARGET in $TARGETS; do + GOOS=${TARGET%-*} GOARCH=${TARGET#*-} go build -o dist/go-cron-$TARGET -ldflags "-X main.build=$BUILD -X main.version=$VERSION" "$MAIN_GO" +done +for TARGET in $STATIC_TARGETS; do + CGO_ENABLED=0 GOOS=${TARGET%-*} GOARCH=${TARGET#*-} go build -o dist/go-cron-$TARGET-static -ldflags "-X main.build=$BUILD -X main.version=$VERSION"' -extldflags "-static"' "$MAIN_GO" +done +gzip -v -k -9 dist/go-cron-* diff --git a/crane.yml b/crane.yml deleted file mode 100644 index 1006378..0000000 --- a/crane.yml +++ /dev/null @@ -1,14 +0,0 @@ -containers: - go-cron: - image: michaloo/golangdev - run: - volume: - - ".:/go-cron" - interactive: true - tty: true - workdir: "/go-cron" - entrypoint: /bin/bash - cmd: - - -c - - "bash" - rm: true diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c6d202a --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/prodrigestivill/go-cron + +go 1.12 + +require github.com/robfig/cron/v3 v3.0.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0667807 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= diff --git a/go-cron.go b/gocron/go-cron.go similarity index 98% rename from go-cron.go rename to gocron/go-cron.go index 26c40fe..ecaf889 100644 --- a/go-cron.go +++ b/gocron/go-cron.go @@ -1,7 +1,7 @@ package gocron import ( - "github.com/robfig/cron" + "github.com/robfig/cron/v3" "io" "log" "os" diff --git a/httpserver.go b/gocron/httpserver.go similarity index 100% rename from httpserver.go rename to gocron/httpserver.go diff --git a/bin/go-cron.go b/main.go similarity index 91% rename from bin/go-cron.go rename to main.go index 4f4a447..acbe5b5 100644 --- a/bin/go-cron.go +++ b/main.go @@ -2,7 +2,7 @@ package main import ( "flag" - gocron "github.com/odise/go-cron" + "github.com/prodrigestivill/go-cron/gocron" "log" "os" "os/signal" @@ -10,6 +10,7 @@ import ( ) var build string +var version string func main() { flagArgs, execArgs := splitArgs() @@ -29,7 +30,7 @@ func main() { flag.PrintDefaults() os.Exit(1) } - log.Println("Running version:", build) + log.Println("Running version:", version) c, wg := gocron.Create(*schedule, execArgs[0], execArgs[1:len(execArgs)]) diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..afd1cfc --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +go run ./main.go "* * * * * *" /bin/bash -c "echo 1;" diff --git a/test/run b/test/run deleted file mode 100755 index 06eb595..0000000 --- a/test/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -go run ./go-cron.go "* * * * * *" /bin/bash -c "echo 1;"