Skip to content

Commit 7912861

Browse files
committed
chore: lint fixes
1 parent f89adf5 commit 7912861

File tree

13 files changed

+433
-399
lines changed

13 files changed

+433
-399
lines changed

helper/command/command.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ func (c *Command) AddEnv(env string) *Command {
6363
return c
6464
}
6565

66-
func (c *Command) SetStdoutFunc(StdoutFunc ReaderFunc) *Command {
67-
c.stdoutFunc = StdoutFunc
66+
func (c *Command) SetStdoutFunc(stdoutFunc ReaderFunc) *Command {
67+
c.stdoutFunc = stdoutFunc
6868
return c
6969
}
7070

71-
func (c *Command) SetStderrFunc(StderrtFunc ReaderFunc) *Command {
72-
c.stderrFunc = StderrtFunc
71+
func (c *Command) SetStderrFunc(stderrFunc ReaderFunc) *Command {
72+
c.stderrFunc = stderrFunc
7373
return c
7474
}
7575
func (c *Command) Run(opt ...Option) (exitCode int, err error) {
@@ -184,7 +184,8 @@ func StringToSlice(command string) (output []string) {
184184
cutQuote := true
185185
inLineWord := ""
186186
for _, c := range command {
187-
if c == ' ' && cutDoubleQuote && cutQuote {
187+
switch {
188+
case c == ' ' && cutDoubleQuote && cutQuote:
188189
if len(inLineWord) > 0 {
189190
if inLineWord[0] == '\'' {
190191
inLineWord = strings.Trim(inLineWord, "'")
@@ -195,9 +196,9 @@ func StringToSlice(command string) (output []string) {
195196
inLineWord = ""
196197
}
197198
continue
198-
} else if c == '"' {
199+
case c == '"':
199200
cutDoubleQuote = !cutDoubleQuote
200-
} else if c == '\'' {
201+
case c == '\'':
201202
cutQuote = !cutQuote
202203
}
203204
inLineWord += string(c)

model/model.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33
import (
44
"fmt"
55
"github.com/google/uuid"
6+
log "github.com/sirupsen/logrus"
67
"os"
78
"time"
89
"transcoder/helper/max"
@@ -102,8 +103,8 @@ type TaskPGSResponse struct {
102103
Queue string `json:"queue"`
103104
}
104105

105-
func (V TaskEncode) getUUID() uuid.UUID {
106-
return V.Id
106+
func (t TaskEncode) getUUID() uuid.UUID {
107+
return t.Id
107108
}
108109

109110
type TaskEvent struct {
@@ -196,32 +197,32 @@ func (e TaskEvent) IsUploading() bool {
196197
return false
197198
}
198199

199-
func (W *WorkTaskEncode) Clean() error {
200-
//log.Warnf("[%s] Cleaning up Task Workspace", W.TaskEncode.Id.String())
201-
err := os.RemoveAll(W.WorkDir)
200+
func (w *WorkTaskEncode) Clean() error {
201+
log.Debugf("[%s] Cleaning up Task Workspace", w.TaskEncode.Id.String())
202+
err := os.RemoveAll(w.WorkDir)
202203
if err != nil {
203204
return err
204205
}
205206
return nil
206207
}
207208

208-
func (t *TaskEvents) GetLatest() *TaskEvent {
209-
if len(*t) == 0 {
209+
func (t TaskEvents) GetLatest() *TaskEvent {
210+
if len(t) == 0 {
210211
return nil
211212
}
212213
return max.Max(t).(*TaskEvent)
213214
}
214-
func (t *TaskEvents) GetLatestPerNotificationType(notificationType NotificationType) (returnEvent *TaskEvent) {
215+
func (t TaskEvents) GetLatestPerNotificationType(notificationType NotificationType) (returnEvent *TaskEvent) {
215216
eventID := -1
216-
for _, event := range *t {
217+
for _, event := range t {
217218
if event.NotificationType == notificationType && event.EventID > eventID {
218219
eventID = event.EventID
219220
returnEvent = event
220221
}
221222
}
222223
return returnEvent
223224
}
224-
func (t *TaskEvents) GetStatus() NotificationStatus {
225+
func (t TaskEvents) GetStatus() NotificationStatus {
225226
return t.GetLatestPerNotificationType(JobNotification).Status
226227
}
227228

@@ -238,25 +239,25 @@ type JobRequest struct {
238239
TargetPath string
239240
}
240241

241-
func (a TaskEvents) Len() int {
242-
return len(a)
242+
func (t TaskEvents) Len() int {
243+
return len(t)
243244
}
244-
func (a TaskEvents) Less(i, j int) bool {
245-
return a[i].EventID < a[j].EventID
245+
func (t TaskEvents) Less(i, j int) bool {
246+
return t[i].EventID < t[j].EventID
246247
}
247-
func (a TaskEvents) Swap(i, j int) {
248-
a[i], a[j] = a[j], a[i]
248+
func (t TaskEvents) Swap(i, j int) {
249+
t[i], t[j] = t[j], t[i]
249250
}
250-
func (a TaskEvents) GetByEventId(i int) (*TaskEvent, error) {
251-
for _, event := range a {
251+
func (t TaskEvents) GetByEventId(i int) (*TaskEvent, error) {
252+
for _, event := range t {
252253
if event.EventID == i {
253254
return event, nil
254255
}
255256
}
256257
return nil, fmt.Errorf("event not found")
257258
}
258-
func (a TaskEvents) GetLastElement(i int) interface{} {
259-
return a[i]
259+
func (t TaskEvents) GetLastElement(i int) interface{} {
260+
return t[i]
260261
}
261262
func (v *Job) AddEvent(eventType EventType, notificationType NotificationType, notificationStatus NotificationStatus) (newEvent *TaskEvent) {
262263
return v.AddEventComplete(eventType, notificationType, notificationStatus, "")

server/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func init() {
4040

4141
cmd.ViperConfig(&opts)
4242

43-
//Fix Paths
43+
// Fix Paths
4444
serverConfig := opts.Server
4545
serverConfig.Scheduler.SourcePath = filepath.Clean(serverConfig.Scheduler.SourcePath)
4646
helper.CheckPath(serverConfig.Scheduler.SourcePath)
@@ -79,7 +79,7 @@ func main() {
7979
}
8080

8181
func applicationRun(wg *sync.WaitGroup, ctx context.Context, updater *update.Updater) {
82-
//Repository persist
82+
// Repository persist
8383
var repo repository.Repository
8484
repo, err := repository.NewSQLRepository(opts.Server.Database)
8585
if err != nil {
@@ -90,15 +90,15 @@ func applicationRun(wg *sync.WaitGroup, ctx context.Context, updater *update.Upd
9090
log.Panic(err)
9191
}
9292

93-
//Scheduler
94-
scheduler, err := scheduler.NewScheduler(opts.Server.Scheduler, repo)
93+
// Scheduler
94+
sch, err := scheduler.NewScheduler(opts.Server.Scheduler, repo)
9595
if err != nil {
9696
log.Panic(err)
9797
}
98-
scheduler.Run(wg, ctx)
98+
sch.Run(wg, ctx)
9999

100-
//WebConfig Server
101-
webServer := web.NewWebServer(opts.Web, scheduler, updater)
100+
// WebConfig Server
101+
webServer := web.NewWebServer(opts.Web, sch, updater)
102102
webServer.Run(wg, ctx)
103103
}
104104

server/repository/repository.go

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ type SQLTransaction struct {
4545
tx *sql.Tx
4646
}
4747

48-
func (S *SQLTransaction) Exec(query string, args ...interface{}) (sql.Result, error) {
48+
func (s *SQLTransaction) Exec(query string, args ...interface{}) (sql.Result, error) {
4949
log.Debugf("Exec: %s, args: %v", query, args)
50-
return S.tx.Exec(query, args...)
50+
return s.tx.Exec(query, args...)
5151

5252
}
5353

54-
func (S *SQLTransaction) Prepare(query string) (*sql.Stmt, error) {
54+
func (s *SQLTransaction) Prepare(query string) (*sql.Stmt, error) {
5555
log.Debugf("Prepare: %s", query)
56-
return S.tx.Prepare(query)
56+
return s.tx.Prepare(query)
5757
}
5858

59-
func (S *SQLTransaction) Query(query string, args ...interface{}) (*sql.Rows, error) {
59+
func (s *SQLTransaction) Query(query string, args ...interface{}) (*sql.Rows, error) {
6060
log.Debugf("Query: %s, args: %v", query, args)
61-
return S.tx.Query(query, args...)
61+
return s.tx.Query(query, args...)
6262
}
6363

64-
func (S *SQLTransaction) QueryRow(query string, args ...interface{}) *sql.Row {
64+
func (s *SQLTransaction) QueryRow(query string, args ...interface{}) *sql.Row {
6565
log.Debugf("QueryRow: %s, args: %v", query, args)
66-
return S.tx.QueryRow(query, args...)
66+
return s.tx.QueryRow(query, args...)
6767
}
6868

69-
func (S *SQLTransaction) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
69+
func (s *SQLTransaction) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
7070
log.Debugf("QueryContext: %s, args: %v", query, args)
71-
return S.tx.QueryContext(ctx, query, args...)
71+
return s.tx.QueryContext(ctx, query, args...)
7272
}
7373

74-
func (S *SQLTransaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
74+
func (s *SQLTransaction) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
7575
log.Debugf("ExecContext: %s, args: %v", query, args)
76-
return S.tx.ExecContext(ctx, query, args...)
76+
return s.tx.ExecContext(ctx, query, args...)
7777
}
7878

7979
type SQLDatabase struct {
@@ -125,12 +125,12 @@ type SQLRepository struct {
125125
}
126126

127127
type SQLServerConfig struct {
128-
Host string `mapstructure:"host",envconfig:"DB_HOST"`
129-
Port int `mapstructure:"port",envconfig:"DB_PORT"`
130-
User string `mapstructure:"user",envconfig:"DB_USER"`
131-
Password string `mapstructure:"password",envconfig:"DB_PASSWORD"`
132-
Scheme string `mapstructure:"scheme",envconfig:"DB_SCHEME"`
133-
Driver string `mapstructure:"driver",envconfig:"DB_DRIVER"`
128+
Host string `mapstructure:"host" envconfig:"DB_HOST"`
129+
Port int `mapstructure:"port" envconfig:"DB_PORT"`
130+
User string `mapstructure:"user" envconfig:"DB_USER"`
131+
Password string `mapstructure:"password" envconfig:"DB_PASSWORD"`
132+
Scheme string `mapstructure:"scheme" envconfig:"DB_SCHEME"`
133+
Driver string `mapstructure:"driver" envconfig:"DB_DRIVER"`
134134
}
135135

136136
func NewSQLRepository(config *SQLServerConfig) (*SQLRepository, error) {
@@ -142,13 +142,15 @@ func NewSQLRepository(config *SQLServerConfig) (*SQLRepository, error) {
142142
db.SetMaxOpenConns(5)
143143
db.SetConnMaxLifetime(0)
144144
db.SetMaxIdleConns(5)
145+
if log.IsLevelEnabled(log.DebugLevel) {
146+
go func() {
147+
for {
148+
fmt.Printf("In use %d not use %d open %d wait %d\n", db.Stats().Idle, db.Stats().InUse, db.Stats().OpenConnections, db.Stats().WaitCount)
149+
time.Sleep(time.Second * 5)
150+
}
151+
}()
152+
}
145153

146-
//go func() {
147-
// for {
148-
// fmt.Printf("In use %d not use %d open %d wait %d\n", db.Stats().Idle, db.Stats().InUse, db.Stats().OpenConnections, db.Stats().WaitCount)
149-
// time.Sleep(time.Second * 5)
150-
// }
151-
//}()
152154
return &SQLRepository{
153155
db: &SQLDatabase{db},
154156
}, nil
@@ -388,11 +390,9 @@ func (s *SQLRepository) GetJobs(ctx context.Context) (jobs *[]model.Job, returnE
388390
}
389391

390392
func (s *SQLRepository) getJobs(ctx context.Context, tx SQLDBOperations) (*[]model.Job, error) {
391-
query := fmt.Sprintf(`
392-
SELECT v.id, v.source_path,v.source_size, v.target_path,v.target_size, vs.event_time, vs.status, vs.notification_type, vs.message
393+
query := `SELECT v.id, v.source_path,v.source_size, v.target_path,v.target_size, vs.event_time, vs.status, vs.notification_type, vs.message
393394
FROM jobs v
394-
INNER JOIN job_status vs ON v.id = vs.job_id
395-
`)
395+
INNER JOIN job_status vs ON v.id = vs.job_id`
396396
rows, err := tx.QueryContext(ctx, query)
397397
if err != nil {
398398
return nil, err
@@ -564,13 +564,11 @@ func (s *SQLRepository) updateJob(ctx context.Context, tx SQLDBOperations, job *
564564

565565
func (s *SQLRepository) getTimeoutJobs(ctx context.Context, tx SQLDBOperations, timeout time.Duration) ([]*model.TaskEvent, error) {
566566
timeoutDate := time.Now().Add(-timeout)
567-
timeoutDate.Format(time.RFC3339)
568567

569568
rows, err := tx.QueryContext(ctx, "select v.* from job_events v right join "+
570569
"(select job_id,max(job_event_id) as job_event_id from job_events where notification_type='Job' group by job_id) as m "+
571570
"on m.job_id=v.job_id and m.job_event_id=v.job_event_id where status in ('assigned','started') and v.event_time < $1::timestamptz", timeoutDate)
572571

573-
//2020-05-17 20:50:41.428531 +00:00
574572
if err != nil {
575573
return nil, err
576574
}
@@ -619,7 +617,6 @@ func (s *SQLRepository) WithTransaction(ctx context.Context, transactionFunc fun
619617
func (s *SQLRepository) queuedJob(ctx context.Context, tx SQLDBOperations) (*model.Job, error) {
620618
rows, err := tx.QueryContext(ctx, "select job_id, job_event_id from job_status where notification_type='Job' and status='queued' order by event_time asc limit 1")
621619

622-
//2020-05-17 20:50:41.428531 +00:00
623620
if err != nil {
624621
return nil, err
625622
}

0 commit comments

Comments
 (0)