Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jobrunner

import (
"fmt"
"log"
"time"

"github.com/robfig/cron/v3"
Expand All @@ -25,19 +25,19 @@ var (
magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
reset = string([]byte{27, 91, 48, 109})

functions =[]interface{}{makeWorkPermits,isSelfConcurrent}
functions = []interface{}{makeWorkPermits, isSelfConcurrent}
)

func makeWorkPermits(bufferCapacity int) {
if bufferCapacity <=0 {
if bufferCapacity <= 0 {
workPermits = make(chan struct{}, DEFAULT_JOB_POOL_SIZE)
} else {
workPermits = make(chan struct{}, bufferCapacity)
}
}

func isSelfConcurrent(cocnurrencyFlag int) {
if cocnurrencyFlag <=0 {
func isSelfConcurrent(concurrencyFlag int) {
if concurrencyFlag <= 0 {
selfConcurrent = false
} else {
selfConcurrent = true
Expand All @@ -47,14 +47,13 @@ func isSelfConcurrent(cocnurrencyFlag int) {
func Start(v ...int) {
MainCron = cron.New()

for i,option := range v {
for i, option := range v {
functions[i].(func(int))(option)
}


MainCron.Start()

fmt.Printf("%s[JobRunner] %v Started... %s \n",
log.Printf("%s[JobRunner] %v Started... %s \n",
magenta, time.Now().Format("2006/01/02 - 15:04:05"), reset)

}
6 changes: 2 additions & 4 deletions jobrunner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jobrunner

import (
"bytes"
"log"
"reflect"
"runtime/debug"
Expand Down Expand Up @@ -50,9 +49,8 @@ func (j *Job) Run() {
// Don't let the whole process die.
defer func() {
if err := recover(); err != nil {
var buf bytes.Buffer
logger := log.New(&buf, "JobRunner Log: ", log.Lshortfile)
logger.Panic(err, "\n", string(debug.Stack()))
log.Printf("[JobRunner] %v Job %q Panicked:\n%s\n",
time.Now().Format("2006/01/02 - 15:04:05"), j.Name, string(debug.Stack()))
}
}()

Expand Down