Example #1
0
func TestStartStopWithSingleJob(t *testing.T) {
	executor := crony.CreateFakeExecutor()
	server := Start(
		executor,
		[]crony.Job{crony.Job{crony.Parse("* * * * * *"), "echo hi"}},
		time.Millisecond*10,
	)

	timer := time.NewTimer(time.Millisecond * 15)
	<-timer.C

	server.Stop()

	if len(executor.Commands) != 1 {
		t.Error("Should have run 1 command")
	}

	if executor.Commands[0] != "echo hi" {
		t.Error("Should have run 'echo hi'")
	}

	timer = time.NewTimer(time.Millisecond * 12)
	<-timer.C
	if len(executor.Commands) != 1 {
		t.Error("Should have run 1 command")
	}
}
Example #2
0
func main() {
	done := make(chan string)
	server.Start(
		crony.NewLocalExecutor(
			crony.NewStdoutPipe("stdout"),
			crony.NewStdoutPipe("stderr"),
		),
		[]crony.Job{
			crony.Job{crony.Parse("* * * * * *"), "echo hi"},
		},
		time.Minute,
	)

	fmt.Print("Server Started...\n")

	fmt.Print(<-done)
}
Example #3
0
func TestOnceWithAWildcardJobRunsIt(t *testing.T) {
	executor := crony.CreateFakeExecutor()
	server := &Server{
		executor: executor,
		jobs: []crony.Job{
			crony.Job{crony.Parse("* * * * * *"), "echo hi"},
		},
	}

	server.Once(time.Now())

	if len(executor.Commands) != 1 {
		t.Error("Should have run 1 command")
	}

	if executor.Commands[0] != "echo hi" {
		t.Error("Should have run 'echo hi'")
	}
}