Skip to content

Commit 71bde49

Browse files
committed
gh workflow pricing
Signed-off-by: pranjalg1331 <[email protected]>
1 parent 78a15d8 commit 71bde49

File tree

4 files changed

+62
-17
lines changed

4 files changed

+62
-17
lines changed

.github/workflows/pricing.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Dynamic Pricing
2+
3+
on:
4+
schedule:
5+
- cron: "0 */6 * * *" # every 6 hours
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-pricing:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.22"
19+
20+
- name: Build pricing service
21+
run: go build -o pricing ./cmd/pricing
22+
23+
- name: Run pricing adjustment
24+
env:
25+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
26+
run: ./pricing

cmd/api/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/pranjalg1331/event-management/handlers"
1111
"github.com/pranjalg1331/event-management/middleware"
1212
"github.com/pranjalg1331/event-management/models"
13-
"github.com/pranjalg1331/event-management/services"
1413
redisclient "github.com/pranjalg1331/event-management/services/redis"
1514
"gorm.io/driver/postgres"
1615
"gorm.io/gorm"
@@ -53,8 +52,6 @@ func main() {
5352
redisclient.InitRedis(redisURL, redisPassword)
5453
log.Println("Redis connected!")
5554

56-
services.StartPriceScheduler(db)
57-
5855
// ------------------------
5956
// 3️⃣ Setup Gin routes
6057
// ------------------------

cmd/pricing/pricing.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
7+
"github.com/pranjalg1331/event-management/services"
8+
"gorm.io/driver/postgres"
9+
"gorm.io/gorm"
10+
)
11+
12+
func main() {
13+
// ------------------------
14+
// 1️⃣ Load DB connection
15+
// ------------------------
16+
dsn := os.Getenv("DATABASE_URL")
17+
if dsn == "" {
18+
log.Fatal("DATABASE_URL is not set")
19+
}
20+
21+
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
22+
if err != nil {
23+
log.Fatalf("Failed to connect to database: %v", err)
24+
}
25+
26+
log.Println("Database connected! Running pricing adjustment...")
27+
28+
// ------------------------
29+
// 2️⃣ Run pricing logic
30+
// ------------------------
31+
if err := services.AdjustEventPrices(db); err != nil {
32+
log.Fatalf("Pricing adjustment failed: %v", err)
33+
}
34+
35+
log.Println("✅ Pricing adjustment completed successfully")
36+
}

services/dynamic-pricing.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package services
33

44
import (
55
"fmt"
6-
"log"
76
"time"
87

98
"github.com/pranjalg1331/event-management/models"
@@ -90,16 +89,3 @@ func applyPricingRules(e models.Event, utilization float64,isPopular bool) float
9089
}
9190

9291

93-
// services/pricing.go
94-
func StartPriceScheduler(db *gorm.DB) {
95-
ticker := time.NewTicker(6 * time.Hour)
96-
go func() {
97-
for {
98-
<-ticker.C
99-
log.Println("Running dynamic pricing update...")
100-
if err := AdjustEventPrices(db); err != nil {
101-
log.Printf("Dynamic pricing failed: %v", err)
102-
}
103-
}
104-
}()
105-
}

0 commit comments

Comments
 (0)