-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(internal): add cron pkg * feat: add datasets watcher * chore: rm unused file * feat: add const err msg * fix: add err check for run.cron
- Loading branch information
1 parent
52ca292
commit c2b9381
Showing
9 changed files
with
193 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cron | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-co-op/gocron" | ||
) | ||
|
||
type Cron struct { | ||
*gocron.Scheduler | ||
*gocron.Job | ||
} | ||
|
||
func New() (*Cron, error) { | ||
c := new(Cron) | ||
|
||
tz, err := time.LoadLocation("Local") | ||
if err != nil { | ||
return c, err | ||
} | ||
|
||
c.Scheduler = gocron.NewScheduler(tz) | ||
c.Job, err = c.Scheduler.Every(1).Day().At("00:00").WaitForSchedule().Do(task) | ||
|
||
return c, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cron | ||
|
||
import "github.com/kitabisa/teler-waf/threat" | ||
|
||
var task = func() error { | ||
updated, err := threat.IsUpdated() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !updated { | ||
err = threat.Get() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package runner | ||
|
||
const ( | ||
errSomething = "Something went wrong" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package runner | ||
|
||
import "github.com/fsnotify/fsnotify" | ||
|
||
type watcher struct { | ||
config, datasets *fsnotify.Watcher | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters