-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
318 additions
and
246 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
kind: pipeline | ||
name: amd64 | ||
|
||
platform: | ||
os: linux | ||
arch: amd64 | ||
|
||
steps: | ||
- name: test | ||
image: golang:1.12.5 | ||
commands: | ||
- make ci | ||
|
||
- name: docker-publish | ||
image: plugins/docker | ||
settings: | ||
username: | ||
from_secret: docker_username | ||
password: | ||
from_secret: docker_password | ||
repo: "jjbubudi/tides" | ||
tag: "${DRONE_TAG}-amd64" | ||
when: | ||
ref: | ||
- refs/head/master | ||
- refs/tags/* | ||
event: | ||
- tag | ||
|
||
--- | ||
kind: pipeline | ||
name: arm64 | ||
|
||
platform: | ||
os: linux | ||
arch: arm64 | ||
|
||
steps: | ||
- name: test | ||
image: golang:1.12.5 | ||
commands: | ||
- make ci | ||
|
||
- name: docker-publish | ||
image: plugins/docker | ||
settings: | ||
username: | ||
from_secret: docker_username | ||
password: | ||
from_secret: docker_password | ||
repo: "jjbubudi/tides" | ||
tag: "${DRONE_TAG}-arm64" | ||
when: | ||
ref: | ||
- refs/head/master | ||
- refs/tags/* | ||
event: | ||
- tag | ||
|
||
--- | ||
kind: pipeline | ||
name: arm | ||
|
||
platform: | ||
os: linux | ||
arch: arm | ||
|
||
steps: | ||
- name: test | ||
image: golang:1.12.5 | ||
commands: | ||
- make ci | ||
|
||
- name: docker-publish | ||
image: plugins/docker | ||
settings: | ||
username: | ||
from_secret: docker_username | ||
password: | ||
from_secret: docker_password | ||
repo: "jjbubudi/tides" | ||
tag: "${DRONE_TAG}-arm" | ||
when: | ||
ref: | ||
- refs/head/master | ||
- refs/tags/* | ||
event: | ||
- tag | ||
|
||
--- | ||
kind: pipeline | ||
name: manifest | ||
steps: | ||
- name: manifest | ||
image: plugins/manifest:1.0.2 | ||
settings: | ||
username: | ||
from_secret: docker_username | ||
password: | ||
from_secret: docker_password | ||
platforms: | ||
- linux/amd64 | ||
- linux/arm64 | ||
- linux/arm | ||
target: "jjbubudi/tides:${DRONE_TAG}" | ||
template: "jjbubudi/tides:${DRONE_TAG}-ARCH" | ||
when: | ||
ref: | ||
- refs/head/master | ||
- refs/tags/* | ||
event: | ||
- tag | ||
|
||
depends_on: | ||
- amd64 | ||
- arm64 | ||
- arm |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, 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,92 @@ | ||
package fetch | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/jjbubudi/tides/internal" | ||
"github.com/jjbubudi/tides/internal/observatory" | ||
"github.com/jjbubudi/tides/internal/tides" | ||
stan "github.com/nats-io/stan.go" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
const ( | ||
pNatsURL = "nats-url" | ||
pNatsClusterID = "nats-cluster-id" | ||
pNatsClientID = "nats-client-id" | ||
) | ||
|
||
// NewFetchCommand creates a new fetch command | ||
func NewFetchCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "fetch", | ||
Usage: "Fetches tidal data", | ||
Subcommands: []cli.Command{ | ||
cli.Command{ | ||
Name: "realtime", | ||
Usage: "Realtime tidal data", | ||
Flags: publisherFlags(), | ||
Action: func(c *cli.Context) error { | ||
nats, err := internal.ConnectToNats( | ||
c.String(pNatsClusterID), | ||
c.String(pNatsClientID), | ||
c.String(pNatsURL), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
defer nats.Close() | ||
return publish(nats, true) | ||
}, | ||
}, | ||
cli.Command{ | ||
Name: "predicted", | ||
Usage: "Predicted tidal data for today", | ||
Flags: publisherFlags(), | ||
Action: func(c *cli.Context) error { | ||
nats, err := internal.ConnectToNats( | ||
c.String(pNatsClusterID), | ||
c.String(pNatsClientID), | ||
c.String(pNatsURL), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
defer nats.Close() | ||
return publish(nats, false) | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func publisherFlags() []cli.Flag { | ||
return []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: pNatsURL, | ||
EnvVar: internal.AutoEnv(pNatsURL), | ||
Required: true, | ||
}, | ||
cli.StringFlag{ | ||
Name: pNatsClusterID, | ||
EnvVar: internal.AutoEnv(pNatsClusterID), | ||
Required: true, | ||
}, | ||
cli.StringFlag{ | ||
Name: pNatsClientID, | ||
EnvVar: internal.AutoEnv(pNatsClientID), | ||
Required: true, | ||
}, | ||
} | ||
} | ||
|
||
func publish(nats stan.Conn, realtime bool) error { | ||
hongKong, _ := time.LoadLocation("Asia/Hong_Kong") | ||
observatory := observatory.New(&http.Client{}) | ||
tidesService := tides.New(observatory.TidalDataAsOf, observatory.TidalPredictionsAsOf, nats.Publish) | ||
if realtime { | ||
return tidesService.PublishRealTimeTidalData(time.Now().In(hongKong)) | ||
} | ||
return tidesService.PublishTidalPredictions(time.Now().In(hongKong)) | ||
} |
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
Oops, something went wrong.