Skip to content

Commit cbf626e

Browse files
committed
refactor: Remove incremental import checkpoints and update cron schedule
- Dropped checkpoint management for issue imports; imports now run without persisting cursors. - Adjusted cron job schedule from 5 AM to 1 AM for earlier task execution.
1 parent 42fb6d3 commit cbf626e

2 files changed

Lines changed: 5 additions & 75 deletions

File tree

command/import/import.go

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66
ccsv "cto-stats/connectors/csv"
77
cg "cto-stats/connectors/github"
88
gh "cto-stats/domain/github"
9-
"encoding/json"
109
"flag"
1110
"fmt"
1211
"log/slog"
1312
"os"
14-
"path/filepath"
1513
"strings"
1614
)
1715

@@ -38,51 +36,7 @@ type IssueReport = gh.IssueReport
3836
type CurrentProject = gh.CurrentProject
3937

4038
// checkpoints stores per-repo import progress to allow incremental runs.
41-
type checkpoints struct {
42-
Repos map[string]repoCheckpoint `json:"repos"`
43-
}
44-
45-
type repoCheckpoint struct {
46-
IssuesAfter string `json:"issues_after,omitempty"`
47-
}
48-
49-
func loadCheckpoints(path string) (*checkpoints, error) {
50-
f, err := os.Open(path)
51-
if err != nil {
52-
// If file doesn't exist, return empty
53-
return &checkpoints{Repos: map[string]repoCheckpoint{}}, nil
54-
}
55-
defer f.Close()
56-
var cp checkpoints
57-
if err := json.NewDecoder(f).Decode(&cp); err != nil {
58-
return &checkpoints{Repos: map[string]repoCheckpoint{}}, nil
59-
}
60-
if cp.Repos == nil {
61-
cp.Repos = map[string]repoCheckpoint{}
62-
}
63-
return &cp, nil
64-
}
65-
66-
func saveCheckpoints(path string, cp *checkpoints) error {
67-
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
68-
return err
69-
}
70-
tmp := path + ".tmp"
71-
f, err := os.Create(tmp)
72-
if err != nil {
73-
return err
74-
}
75-
enc := json.NewEncoder(f)
76-
enc.SetIndent("", " ")
77-
if err := enc.Encode(cp); err != nil {
78-
f.Close()
79-
return err
80-
}
81-
if err := f.Close(); err != nil {
82-
return err
83-
}
84-
return os.Rename(tmp, path)
85-
}
39+
// Note: checkpoint management removed. The import now runs without persisting cursors.
8640

8741
// Run executes the import subcommand. It expects flag arguments like: -org, -since, -repo.
8842
func Run(args []string) error {
@@ -142,43 +96,19 @@ func Run(args []string) error {
14296
return err
14397
}
14498

145-
// Load checkpoints to make the import incremental by default
146-
cpPath := "./data/checkpoints.json"
147-
cp, _ := loadCheckpoints(cpPath)
148-
14999
var reports []IssueReport
150100
for _, r := range repos {
151101
if *repoFilter != "" && !allowedRepos[r.Name] {
152102
continue
153103
}
154-
key := r.Owner.Login + "/" + r.Name
155-
after := ""
156-
if rp, ok := cp.Repos[key]; ok {
157-
if strings.TrimSpace(rp.IssuesAfter) != "" {
158-
after = rp.IssuesAfter
159-
slog.Info("checkpoint.issues.cursor.resume", "repo", key, "after", after)
160-
}
161-
}
162-
slog.Info("phase.issues.import.start", "owner", r.Owner.Login, "repo", r.Name, "since", *since, "after", after)
163-
issues, endCursor, err := ghc.ListAllIssues(ctx, r.Owner.Login, r.Name, *since, after)
104+
// No checkpoint resume: always start from the beginning or respect the provided -since filter.
105+
slog.Info("phase.issues.import.start", "owner", r.Owner.Login, "repo", r.Name, "since", *since)
106+
issues, _, err := ghc.ListAllIssues(ctx, r.Owner.Login, r.Name, *since, "")
164107
if err != nil {
165108
slog.Error("phase.issues.fetch.error", "owner", r.Owner.Login, "repo", r.Name, "error", err)
166109
fmt.Fprintf(os.Stderr, "error listing issues for %s/%s: %v\n", r.Owner.Login, r.Name, err)
167110
continue
168111
}
169-
if endCursor != nil {
170-
if cp.Repos == nil {
171-
cp.Repos = map[string]repoCheckpoint{}
172-
}
173-
rc := cp.Repos[key]
174-
rc.IssuesAfter = *endCursor
175-
cp.Repos[key] = rc
176-
if err := saveCheckpoints(cpPath, cp); err != nil {
177-
slog.Warn("checkpoint.save.error", "path", cpPath, "error", err)
178-
} else {
179-
slog.Info("checkpoint.issues.cursor.saved", "repo", key, "after", *endCursor)
180-
}
181-
}
182112
slog.Info("phase.issues.import.fetched", "owner", r.Owner.Login, "repo", r.Name, "count", len(issues))
183113
for _, is := range issues {
184114
// Skip PRs

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ chmod 600 "$ENV_FILE"
1616
CRON_FILE=/etc/crontabs/root
1717
mkdir -p /etc/crontabs
1818
: > "$CRON_FILE"
19-
echo "0 5 * * * /usr/local/bin/run-jobs.sh >> /proc/1/fd/1 2>&1" >> "$CRON_FILE"
19+
echo "0 1 * * * /usr/local/bin/run-jobs.sh >> /proc/1/fd/1 2>&1" >> "$CRON_FILE"
2020
chmod 600 "$CRON_FILE"
2121

2222
# Start cron in background (busybox crond)

0 commit comments

Comments
 (0)