Add base site, needs clean-up

This commit is contained in:
2021-12-26 00:02:51 +01:00
parent ed4475149a
commit ec313045f1
28 changed files with 2806 additions and 18 deletions

View File

@@ -12,4 +12,5 @@ type Repository interface {
Get(ctx context.Context, active bool) ([]*entities.Download, error)
GetOldOrStuck(ctx context.Context) ([]*entities.Download, error)
BatchDelete(ctx context.Context, requests []*entities.Download) error
GetDone(ctx context.Context) ([]*entities.Download, error)
}

View File

@@ -80,13 +80,22 @@ func (r repository) Update(ctx context.Context, download *entities.Download) err
func (r repository) Get(ctx context.Context, active bool) ([]*entities.Download, error) {
var downloads []Download
err := r.db.NewSelect().
query := r.db.NewSelect().
Model(&downloads).
Column("id", "status", "link").
Where("status LIKE ?", "in-progress%").
Limit(20).
Order("created_at ASC").
Scan(ctx)
Column("id", "status", "link")
var err error
if active {
err = query.
Where("status LIKE ? OR status = ?", "in-progress%", "scheduled").
Order("created_at ASC").
Scan(ctx)
} else {
err = query.
Order("created_at ASC").
Scan(ctx)
}
if err != nil {
return nil, err
}
@@ -109,7 +118,7 @@ func (r repository) GetOldOrStuck(ctx context.Context) ([]*entities.Download, er
err := r.db.NewSelect().
Model(&downloads).
Column("id", "status", "link").
Where("status LIKE ?", "in-progress%").
Where("status LIKE ? OR status = ?", "in-progress%", "scheduled").
Where("updated_at < now() - interval '1 minutes'").
Limit(20).
Order("created_at ASC").
@@ -152,3 +161,28 @@ func (r repository) BatchDelete(ctx context.Context, requests []*entities.Downlo
return nil
}
func (r repository) GetDone(ctx context.Context) ([]*entities.Download, error) {
var downloads []Download
err := r.db.NewSelect().
Model(&downloads).
Column("id", "status", "link").
Where("status = ?", "done").
Order("created_at ASC").
Scan(ctx)
if err != nil {
return nil, err
}
var responseDownloads []*entities.Download
for _, download := range downloads {
responseDownloads = append(responseDownloads, &entities.Download{
ID: download.ID,
Status: download.Status,
Link: download.Link,
})
}
return responseDownloads, nil
}

View File

@@ -35,5 +35,8 @@ func (l localSourceHandler) Prepare(link string) (string, error) {
}
func (l localSourceHandler) CleanUp(sourcePath string) error {
return os.Remove(sourcePath)
if _, err := os.Stat(sourcePath); os.IsNotExist(err) {
return nil
}
return os.RemoveAll(sourcePath)
}