Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rakanalh/scheduler
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1
Choose a base ref
...
head repository: rakanalh/scheduler
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 15, 2017

  1. Add godep files

    rakanalh committed Nov 15, 2017
    Copy the full SHA
    fada1c4 View commit details

Commits on Nov 20, 2017

  1. Copy the full SHA
    f0d21bf View commit details
  2. Merge pull request #2 from hotid/master

    Fix tasks that last>1s started every second
    rakanalh authored Nov 20, 2017
    Copy the full SHA
    3984f4f View commit details
  3. Copy the full SHA
    23a9bee View commit details
  4. Copy the full SHA
    a6ca38b View commit details
  5. Added package comment

    rakanalh committed Nov 20, 2017
    Copy the full SHA
    a26175f View commit details

Commits on Nov 21, 2017

  1. Copy the full SHA
    26f4b13 View commit details

Commits on Nov 26, 2017

  1. Copy the full SHA
    560e31a View commit details
  2. Merge pull request #3 from hotid/master

    return err instead of nil on errors, so we can check for err != nil on scheduler start
    rakanalh authored Nov 26, 2017
    Copy the full SHA
    1df42c5 View commit details

Commits on Mar 11, 2018

  1. Add option to make Start() func silent (#4)

    * Remove silencing and log call
    sinnlosername authored and rakanalh committed Mar 11, 2018
    Copy the full SHA
    110cd62 View commit details

Commits on May 16, 2018

  1. Only build when CGO is enabled

    eelcocramer authored and rakanalh committed May 16, 2018
    Copy the full SHA
    7cd264b View commit details

Commits on May 22, 2018

  1. Fixed several typos in README (#1)

    Davydov Denis authored and rakanalh committed May 22, 2018
    Copy the full SHA
    be46358 View commit details

Commits on Sep 25, 2018

  1. provide task persistent storage by postgres db and close the respecti…

    …ve db conn at the stop of scheduler
    Jnana Sagar committed Sep 25, 2018
    Copy the full SHA
    fc5a235 View commit details

Commits on Sep 30, 2018

  1. store mock to implement TaskStore interface

    Jnana Sagar authored and rakanalh committed Sep 30, 2018
    Copy the full SHA
    3227b00 View commit details
  2. close the underlying DB store in test case

    Jnana Sagar authored and rakanalh committed Sep 30, 2018
    Copy the full SHA
    cf537b2 View commit details

Commits on Oct 2, 2018

  1. Add MongoDB support

    dmitescu authored and rakanalh committed Oct 2, 2018
    Copy the full SHA
    63ce2a8 View commit details

Commits on Oct 3, 2018

  1. Fix imports.

    Fixes #11
    rakanalh committed Oct 3, 2018
    Copy the full SHA
    d081b70 View commit details

Commits on Jan 1, 2019

  1. Fix #14: undefined error - scheduler/storage/mongo.go:77:12: undefine…

    …d: bson.NewDocument
    
    Signed-off-by: Ilya Shindyapin <ilya@shindyapin.com>
    license2e committed Jan 1, 2019
    Copy the full SHA
    d26d521 View commit details
  2. Fix the monogo_test

    Signed-off-by: Ilya Shindyapin <ilya@shindyapin.com>
    license2e committed Jan 1, 2019
    Copy the full SHA
    55bba24 View commit details
  3. Fix the cursor Decode

    Signed-off-by: Ilya Shindyapin <ilya@shindyapin.com>
    license2e committed Jan 1, 2019
    Copy the full SHA
    94864f8 View commit details
  4. Remove port from mongodb test

    Signed-off-by: Ilya Shindyapin <ilya@shindyapin.com>
    license2e committed Jan 1, 2019
    Copy the full SHA
    aa75028 View commit details

Commits on Jan 2, 2019

  1. Merge pull request #15 from license2e/master

    Fix #14: undefined error - scheduler/storage/mongo.go:77:12: undefine…
    rakanalh authored Jan 2, 2019
    Copy the full SHA
    8f5e7f9 View commit details
Showing with 916 additions and 30 deletions.
  1. +3 −1 .gitignore
  2. +1 −0 .travis.yml
  3. +187 −0 Gopkg.lock
  4. +7 −0 Gopkg.toml
  5. +21 −0 LICENSE.md
  6. +2 −2 README.org
  7. +53 −0 _example/mongo/main.go
  8. +53 −0 _example/postgres/main.go
  9. +3 −1 mock.go
  10. +44 −8 scheduler.go
  11. +30 −0 scheduler_test.go
  12. +9 −0 storage/memory.go
  13. +160 −0 storage/mongo.go
  14. +103 −0 storage/mongo_test.go
  15. +9 −0 storage/noop.go
  16. +165 −0 storage/postgres.go
  17. +14 −1 storage/sqlite3.go
  18. +5 −0 storage/store.go
  19. +6 −0 store_test.go
  20. +4 −0 task/mock.go
  21. +17 −8 task/registry.go
  22. +20 −9 task/task.go
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.db
*.out
*.out
vendor
coverage.txt
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: go
services: mongodb
before_install:
- go get github.com/rakanalh/scheduler
script:
187 changes: 187 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[constraint]]
name = "github.com/mattn/go-sqlite3"
version = "1.4.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Rakan Alhneiti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
4 changes: 2 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ and then pass it to the scheduler.

Scheduling tasks can be done in 3 ways:

** Execute a task which after 5 seconds.
** Execute a task after 5 seconds.
#+BEGIN_SRC go
func MyFunc(arg1 string, arg2 string)
taskID := s.RunAfter(5*time.Second, MyFunc, "Hello", "World")
@@ -69,7 +69,7 @@ taskID := s.RunAfter(5*time.Second, MyFunc, "Hello", "World")
** Execute a task at a specific time.
#+BEGIN_SRC go
func MyFunc(arg1 string, arg2 string)
taskID := s.RunAt(Time.Now.Add(24 * time.Hour, MyFunc, "Hello", "World")
taskID := s.RunAt(time.Now().Add(24 * time.Hour), MyFunc, "Hello", "World")
#+END_SRC

** Execute a task every 1 minute.
53 changes: 53 additions & 0 deletions _example/mongo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"log"
"time"

"github.com/rakanalh/scheduler"
"github.com/rakanalh/scheduler/storage"
)

func TaskWithoutArgs() {
log.Println("TaskWithoutArgs is executed")
}

func TaskWithArgs(message string) {
log.Println("TaskWithArgs is executed. message:", message)
}

func main() {
storage := storage.NewMongoDBStorage(
storage.MongoDBConfig{
ConnectionUrl: "mongodb://localhost/example",
Db: "example",
},
)

if err := storage.Connect(); err != nil {
log.Fatal("Could not connect to db", err)
}

if err := storage.Initialize(); err != nil {
log.Fatal("Could not intialize database", err)
}

s := scheduler.New(storage)

// Start a task without arguments
if _, err := s.RunAfter(30*time.Second, TaskWithoutArgs); err != nil {
log.Fatal(err)
}

// Start a task with arguments
if _, err := s.RunEvery(5*time.Second, TaskWithArgs, "Hello from recurring task 1"); err != nil {
log.Fatal(err)
}

// Start the same task as above with a different argument
if _, err := s.RunEvery(10*time.Second, TaskWithArgs, "Hello from recurring task 2"); err != nil {
log.Fatal(err)
}
s.Start()
s.Wait()
}
53 changes: 53 additions & 0 deletions _example/postgres/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"io"
"log"
"time"

"github.com/rakanalh/scheduler"
"github.com/rakanalh/scheduler/storage"
)

func TaskWithoutArgs() {
log.Println("TaskWithoutArgs is executed")
}

func TaskWithArgs(message string) {
log.Println("TaskWithArgs is executed. message:", message)
}

func main() {
storage, err := storage.NewPostgresStorage(
storage.PostgresDBConfig{
DbURL: "postgresql://<db-username>:<db-password>@localhost:5432/scheduler?sslmode=disable",
},
)
if err != nil {
log.Fatalf("Couldn't create scheduler storage : %v", err)
}

s := scheduler.New(storage)

go func(s scheduler.Scheduler, store io.Closer) {
time.Sleep(time.Second * 10)
// store.Close()
s.Stop()
}(s, storage)
// Start a task without arguments
if _, err := s.RunAfter(60*time.Second, TaskWithoutArgs); err != nil {
log.Fatal(err)
}

// Start a task with arguments
if _, err := s.RunEvery(5*time.Second, TaskWithArgs, "Hello from recurring task 1"); err != nil {
log.Fatal(err)
}

// Start the same task as above with a different argument
if _, err := s.RunEvery(10*time.Second, TaskWithArgs, "Hello from recurring task 2"); err != nil {
log.Fatal(err)
}
s.Start()
s.Wait()
}
4 changes: 3 additions & 1 deletion mock.go
Original file line number Diff line number Diff line change
@@ -90,7 +90,9 @@ func (s *storeMock) Fetch() ([]storage.TaskAttributes, error) {
func (s *storeMock) Remove(task storage.TaskAttributes) error {
return nil
}

func (s *storeMock) Close() error {
return nil
}
func mockFunction(a string, b int) {

}
Loading