Skip to content

Commit

Permalink
get rid of unused timeout configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
utkuufuk committed Sep 24, 2021
1 parent 759ebaa commit d415f23
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 21 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ go run ./cmd/entrello -c /path/to/config/file

Most of the configuration parameters are self explanatory, so the following only covers the important ones:

### Global Timeout
You can edit the `timeout_secs` config value in order to update global timeout (in seconds) for a single execution.

The execution will not terminate until the timeout is reached, so it's important that the timeout is shorter than the cron job period.

### Trello
You need to set your [Trello API key & token](https://trello.com/app-key) in the configuraiton file, as well as the Trello board ID.

Expand Down
12 changes: 2 additions & 10 deletions cmd/entrello/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"flag"
"log"
"sync"
Expand All @@ -14,7 +13,6 @@ import (

var (
logger syslog.Logger
now time.Time
)

func main() {
Expand All @@ -37,15 +35,9 @@ func main() {
if err != nil {
logger.Fatalf("Invalid timezone location: %v", loc)
}
now = time.Now().In(loc)

// set global timeout
timeout := time.Second * time.Duration(cfg.TimeoutSeconds)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

// get a list of sources and the corresponding labels for each source
sources, labels := getSources(cfg.Sources)
sources, labels := getSources(cfg.Sources, time.Now().In(loc))
if len(sources) == 0 {
return
}
Expand All @@ -65,7 +57,7 @@ func main() {
var wg sync.WaitGroup
wg.Add(len(sources))
for _, src := range sources {
go process(src, ctx, client, &wg)
go process(src, client, &wg)
}
wg.Wait()
}
7 changes: 3 additions & 4 deletions cmd/entrello/source.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -14,7 +13,7 @@ import (
)

// getSources returns a slice of sources & their labels as a separate slice
func getSources(cfg config.Sources) (sources []config.Source, labels []string) {
func getSources(cfg config.Sources, now time.Time) (sources []config.Source, labels []string) {
arr := []config.Source{
cfg.GithubIssues,
cfg.TodoDock,
Expand Down Expand Up @@ -66,12 +65,12 @@ func shouldQuery(src config.Source, date time.Time) (bool, error) {

// process fetches cards from the source and creates the ones that don't already exist,
// also deletes the stale cards if strict mode is enabled
func process(src config.Source, ctx context.Context, client trello.Client, wg *sync.WaitGroup) {
func process(src config.Source, client trello.Client, wg *sync.WaitGroup) {
defer wg.Done()

resp, err := http.Get(src.Endpoint)
if err != nil {
logger.Errorf("could not send POST request to source '%s' endpoint: %v", src.Name, err)
logger.Errorf("could not make GET request to source '%s' endpoint: %v", src.Name, err)
return
}
defer resp.Body.Close()
Expand Down
1 change: 0 additions & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
timezone_location: Europe/Istanbul
timeout_secs: 45

trello:
api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Expand Down
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Telegram struct {

type Config struct {
TimezoneLocation string `yaml:"timezone_location"`
TimeoutSeconds int `yaml:"timeout_secs"`
Trello Trello `yaml:"trello"`
Sources Sources `yaml:"sources"`
Telegram Telegram `yaml:"telegram"`
Expand Down

0 comments on commit d415f23

Please sign in to comment.