mileusna / crontab Goto Github PK
View Code? Open in Web Editor NEWGo/Golang crontab ticker
License: MIT License
Go/Golang crontab ticker
License: MIT License
I thank you can use heap, then heap can reduce loss of performance.
// RunScheduled jobs
func (c *Crontab) runScheduled(t time.Time) {
tick := getTick(t)
for _, j := range c.jobs {
if tickJob(tick, j) {
go run(j)
}
}
}
Hi,
I was trying to use this library for my upcoming cron job, but the example itself hits exit(0). I have tried the example as is and even tried same in playground. Code is exiting.
Can you please help, If i need to do anything extra make cron job run?
here is link to play ground https://play.golang.org/p/p2jBT3dm9nw
Can you explain why the crontab logging that? i have no idea why the crontab keep logging kind of that stuff. I saw when crontab execute run(), it defer a function that recover the program with log like "Crontab error runtime error: invalid memory address or nil pointer dereference". thanks in advance.
Given this main file:
package main
import (
"log"
"<PATH_TO>/foostuff"
"github.com/mileusna/crontab"
)
func fooFunc(foo foostuff.Foo) {
log.Println(foo.Bar())
}
func main() {
ctab := crontab.New()
fooStuff := foostuff.NewFoo()
ctab.MustAddJob("* * * * *", fooFunc, fooStuff)
}
And this foostuff
package:
package foostuff
import "fmt"
type foo struct {
fooFoo int
}
type Foo interface {
Bar() string
}
func NewFoo() Foo {
return &foo{
fooFoo: 42,
}
}
func (f *foo) Bar() string {
return fmt.Sprintf("foo: %v", f.fooFoo)
}
Then when executing the main file I get this panic
error message:
panic: Param with index 0 shold be `foostuff.Foo` not `*foostuff.foo`
goroutine 1 [running]:
github.com/mileusna/crontab.(*Crontab).MustAddJob(0xc420014540, 0x510ffe, 0x9, 0x4e9380, 0x518388, 0xc42000e3c0, 0x1, 0x1)
<GOPATH>/src/github.com/mileusna/crontab/crontab.go:130 +0xae
main.main()
<GOPATH>/src/<PATH_TO_MAIN>/main.go:19 +0xf5
exit status 2
I can see around line crontab.go:106
there's a check via reflection about the input types for the function to be executed, but I think returning a struct
compliant with the interface
is supposed to be fine.
Is this intended behavior? Is there a work around?
Thanks
Maybe like this:
loc, _ := time.LoadLocation("Asia/Taipei")
ctab.SetLocation(loc)
It would be good to add one more function to directly add job struct, in case i have already parsed expression (i.e. i have int day, hour, week and so), or event better to schedule job at specific go time
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.