-
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
10 changed files
with
531 additions
and
6 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,16 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE TABLE IF NOT EXISTS tap ( | ||
id INTEGER PRIMARY KEY, | ||
order_id INTEGER NOT NULL, | ||
order_created_at TIMESTAMP NOT NULL, | ||
name TEXT NOT NULL, | ||
category TEXT NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
) | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
DROP TABLE IF EXISTS tap; | ||
-- +goose StatementEnd |
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,43 @@ | ||
-- CRUD | ||
|
||
-- name: GetAllTaps :many | ||
SELECT * | ||
FROM tap; | ||
|
||
-- name: GetTapByID :one | ||
SELECT * | ||
FROM tap | ||
WHERE id = ?; | ||
|
||
-- name: CreateTap :one | ||
INSERT INTO tap (order_id, order_created_at, name, category) | ||
VALUES (?, ?, ?, ?) | ||
RETURNING *; | ||
|
||
-- name: UpdateTap :one | ||
UPDATE tap | ||
SET order_id = ?, order_created_at = ?, name = ?, category = ? | ||
WHERE id = ? | ||
RETURNING *; | ||
|
||
-- name: DeleteTap :execrows | ||
DELETE FROM tap | ||
WHERE id = ?; | ||
|
||
-- Other | ||
|
||
-- name: GetTapByOrderID :one | ||
SELECT * | ||
FROM tap | ||
WHERE order_id = ?; | ||
|
||
-- name: GetTapByCategory :many | ||
SELECT * | ||
FROM tap | ||
WHERE category = ?; | ||
|
||
-- name: GetLastOrder :one | ||
SELECT * | ||
FROM tap | ||
ORDER BY id DESC | ||
LIMIT 1; |
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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/zeusWPI/scc/internal/pkg/tap" | ||
"github.com/zeusWPI/scc/pkg/config" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func tapCmd(tap *tap.Tap) chan bool { | ||
done := make(chan bool) | ||
|
||
go tapPeriodicUpdate(tap, done) | ||
|
||
return done | ||
} | ||
|
||
func tapPeriodicUpdate(tap *tap.Tap, done chan bool) { | ||
interval := config.GetDefaultInt("tap.interval_s", 60) | ||
zap.S().Info("Tap: Starting periodic update with an interval of ", interval, " seconds") | ||
|
||
ticker := time.NewTicker(time.Duration(interval) * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-done: | ||
zap.S().Info("Tap: Stopping periodic update") | ||
return | ||
case <-ticker.C: | ||
// Update tap | ||
zap.S().Info("Tap: Updating tap") | ||
err := tap.Update() | ||
if err != nil { | ||
zap.S().Error("Tap: Error updating tap\n", err) | ||
} | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.