Skip to content

Commit

Permalink
add a simple entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pitluga committed Jan 7, 2016
1 parent e1e5a1b commit 0f3cc2d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion executor.go → crony/executor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cron
package crony

type Executor interface {
Execute(command string) error
Expand Down
2 changes: 1 addition & 1 deletion job.go → crony/job.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cron
package crony

type Job struct {
Schedule Schedule
Expand Down
2 changes: 1 addition & 1 deletion pattern.go → crony/pattern.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cron
package crony

import(
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pattern_test.go → crony/pattern_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cron
package crony

import(
"testing"
Expand Down
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"github.com/pitluga/crony/crony"
"github.com/pitluga/crony/server"
"time"
)

func main() {
done := make(chan string)
server.Start(
crony.CreateFakeExecutor(),
[]crony.Job{
crony.Job{crony.Parse("* * * * * *"), "echo hi"},
},
time.Minute,
)

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

fmt.Print(<-done)
}
19 changes: 10 additions & 9 deletions server.go → server/server.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package cron
package server

import(
import (
"github.com/pitluga/crony/crony"
"time"
)

type Server struct {
executor Executor
ticker *time.Ticker
jobs []Job
executor crony.Executor
ticker *time.Ticker
jobs []crony.Job
}

func Start(executor Executor, jobs []Job, interval time.Duration) *Server {
func Start(executor crony.Executor, jobs []crony.Job, interval time.Duration) *Server {
ticker := time.NewTicker(interval)

server := &Server{
executor: executor,
jobs: jobs,
ticker: ticker,
jobs: jobs,
ticker: ticker,
}

go func () {
go func() {
for now := range ticker.C {
server.Once(now)
}
Expand Down
22 changes: 11 additions & 11 deletions server_test.go → server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package cron
package server

import(
import (
"github.com/pitluga/crony/crony"
"testing"
"time"
)


func TestOnceWithNoJobsDoesNothing(t *testing.T) {
executor := CreateFakeExecutor()
executor := crony.CreateFakeExecutor()
server := &Server{
executor: executor,
jobs: make([]Job, 0),
jobs: make([]crony.Job, 0),
}

server.Once(time.Now())
Expand All @@ -21,11 +21,11 @@ func TestOnceWithNoJobsDoesNothing(t *testing.T) {
}

func TestOnceWithAWildcardJobRunsIt(t *testing.T) {
executor := CreateFakeExecutor()
executor := crony.CreateFakeExecutor()
server := &Server{
executor: executor,
jobs: []Job{
Job{Parse("* * * * * *"), "echo hi"},
jobs: []crony.Job{
crony.Job{crony.Parse("* * * * * *"), "echo hi"},
},
}

Expand All @@ -41,11 +41,11 @@ func TestOnceWithAWildcardJobRunsIt(t *testing.T) {
}

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

timer := time.NewTimer(time.Millisecond * 12)
Expand Down

0 comments on commit 0f3cc2d

Please sign in to comment.