Skip to content

Commit

Permalink
Develop (#8)
Browse files Browse the repository at this point in the history
* Squashed commit of the following:

commit 4c3be07
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Aug 3 11:57:25 2020 +0530

    Bump elliptic from 6.5.2 to 6.5.3 in /client (#6)

    Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.2 to 6.5.3.
    - [Release notes](https://github.com/indutny/elliptic/releases)
    - [Commits](indutny/elliptic@v6.5.2...v6.5.3)

    Signed-off-by: dependabot[bot] <[email protected]>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 3e75da1
Author: sn123 <[email protected]>
Date:   Thu Jul 30 14:56:42 2020 +0530

    Update issue templates

commit 433830e
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Jul 20 10:29:57 2020 +0530

    Bump lodash from 4.17.15 to 4.17.19 in /client (#5)

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.15...4.17.19)

    Signed-off-by: dependabot[bot] <[email protected]>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 202271c
Merge: 8428d98 72c3cbe
Author: sn123 <[email protected]>
Date:   Fri Jun 12 11:45:49 2020 +0530

    Merge pull request #4 from goavega-software/develop

    Change log.Fatal to Println

commit 8428d98
Merge: 4cfaeb0 1297b79
Author: sn123 <[email protected]>
Date:   Thu Jun 11 15:21:22 2020 +0530

    Merge pull request #3 from goavega-software/dependabot/npm_and_yarn/client/websocket-extensions-0.1.4

    Bump websocket-extensions from 0.1.3 to 0.1.4 in /client

commit 1297b79
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Jun 8 02:20:08 2020 +0000

    Bump websocket-extensions from 0.1.3 to 0.1.4 in /client

    Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
    - [Release notes](https://github.com/faye/websocket-extensions-node/releases)
    - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
    - [Commits](faye/websocket-extensions-node@0.1.3...0.1.4)

    Signed-off-by: dependabot[bot] <[email protected]>

commit 4cfaeb0
Merge: 92a58b2 8cb8fa1
Author: sn123 <[email protected]>
Date:   Fri May 29 00:09:41 2020 +0530

    Merge pull request #2 from goavega-software/develop

    Add docker-compose support. Fixes #1

* Configurable jobs (#7)
  • Loading branch information
sn123 authored Aug 14, 2020
1 parent 4c3be07 commit 9ad3613
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ AWS_S3_REGION=AWS_S3_REGION
AWS_S3_BUCKET=AWS_S3_BUCKET
AWS_S3_PREFIX=AWS_S3_FILTER_PREFIX
KAFKA_URL=kafka-broker-url
KAFKA_TOPIC=topic-to-listen
KAFKA_TOPIC=topic-to-listen
JOB_SCHEDULE=[{"name": "flickrshow", "schedule": "@every 1d"}, {"name": "weather", "schedule": "@every 1h"}, ...]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Few widgets and jobs are already included in repository - feel free to use/abuse
* Weather widget - displays weather from OpenWeather and gets the backrground image from flickr for the weather condition
* List widget - cycles through a list of items (title, image and description) on schedule
#### Jobs
Jobs schedule is set using env variable ```JOB_SCHEDULE```. The variable holds an JSON array in below form:
```
[{"name": "name-of-job", "schedule": "schedule-of-job"}, {"name": "weather", "schedule": "@every 1h"}]
```
This allows all jobs to have their job schedule configurable using env. Any job which is not present in JOB_SCHEDULE is disabled. (since 0.3)
* Blogroll - gets RSS feed from a site and converts the URL into a QR Code.
* Weather - gets the current weather from OpenWeather
* Number - gets the number trivia for today's day
Expand Down
49 changes: 49 additions & 0 deletions core/jobfactory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package core

import (
"encoding/json"
"log"
)

type JobFactory struct {
}

type Schedule struct {
Name string `json:"name"`
Schedule string `json:"schedule"`
}

var factory *JobFactory
var advertisedJobs map[string]func() = make(map[string]func())

/*
Process parses the json and only schedules enabled jobs
*/
func (jf JobFactory) Process(schedule string) {
schedules := make([]Schedule, 0)
json.Unmarshal([]byte(schedule), &schedules)
for _, item := range schedules {
value, ok := advertisedJobs[item.Name]
if ok {
log.Printf("%s, %s", item.Schedule, item.Name)
AddJob(item.Schedule, value)
}
}
}

/*
Advertise All jobs should "advertise" themselves with a name and execute function
***/
func (jf JobFactory) Advertise(name string, executor func()) {
advertisedJobs[name] = executor
}

/*
GetFactory a non-thread safe way of getting the factory. It's not called make since it mimics a singleton
*/
func GetFactory() *JobFactory {
if factory == nil {
factory = &JobFactory{}
}
return factory
}
4 changes: 2 additions & 2 deletions jobs/blogroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type blogData struct {
var blogURL = "https://www.goavega.com/feed"

func init() {
mustardcore.AddJob("@every 1h", func() {
mustardcore.GetFactory().Advertise("blogroll", func() {
re := regexp.MustCompile(`<[^>]*>`)
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(blogURL)
Expand All @@ -43,7 +43,7 @@ func init() {
}
blog.Items = items
data := mustardcore.EventData{Event: "blogRoll", Data: blog}

mustardcore.GetEventsManager().Notify(data)
})
}
2 changes: 1 addition & 1 deletion jobs/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var dataURL = "https://pomber.github.io/covid19/timeseries.json"
var country = "India"

func init() {
mustardcore.AddJob("@every 6h", func() {
mustardcore.GetFactory().Advertise("comparison", func() {
resp, err := http.Get(dataURL)
if err != nil {
log.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion jobs/flickrshow.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type slideshow struct {
}

func init() {
mustardcore.AddJob("@every 1d", func() {
mustardcore.GetFactory().Advertise("flickrshow", func() {
flickrUser := mustardcore.GetEnvVariables().FlickrUserID
var items []slide
flickr := mustardcore.Flickr{UserID: flickrUser}
Expand Down
2 changes: 1 addition & 1 deletion jobs/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type number struct {
var numberURL = "http://numbersapi.com/%d"

func init() {
mustardcore.AddJob("@every 2h", func() {
mustardcore.GetFactory().Advertise("number", func() {
now := time.Now()
resp, err := http.Get(fmt.Sprintf(numberURL, now.Day()))
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions jobs/s3show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"os"
)


func init() {
mustardcore.AddJob("@every 4h", func() {
mustardcore.GetFactory().Advertise("s3show", func() {
var items []slide
s3Images := mustardcore.S3Images{Bucket: os.Getenv("AWS_S3_BUCKET"), Region: os.Getenv("AWS_S3_REGION"), Prefix: os.Getenv("")}
slideshow := slideshow{}
Expand Down
2 changes: 1 addition & 1 deletion jobs/weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type outputData struct {
var weatherAPIURL = "http://api.openweathermap.org/data/2.5/weather?id=%d&appid=%s&units=metric"

func init() {
mustardcore.AddJob("@every 1h", func() {
mustardcore.GetFactory().Advertise("weather", func() {
placeID := mustardcore.GetEnvVariables().OpenWeatherPlaceID
apiKey := mustardcore.GetEnvVariables().OpenWeatherKey
resp, err := http.Get(fmt.Sprintf(weatherAPIURL, placeID, apiKey))
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func main() {
eventsManager.Init(e)
eventListener := events.EventListener{URL: os.Getenv("KAFKA_URL"), Topic: os.Getenv("KAFKA_TOPIC"), GroupID: "mustard"}
eventListener.Start()
mustardcore.GetFactory().Process(os.Getenv("JOB_SCHEDULE"))

defer eventsManager.Destroy()
defer mustardcore.DestroyJobs()

Expand Down

0 comments on commit 9ad3613

Please sign in to comment.