@@ -38,24 +38,28 @@ func (s *service) DestroyPersistentCacheTask(ctx context.Context, schedulerClust
38
38
}
39
39
40
40
// GetPersistentCacheTask retrieves a persistent cache task from Redis based on query parameters.
41
- func (s * service ) GetPersistentCacheTask (ctx context.Context , schedulerClusterID uint , id string ) (* types.PersistentCacheTask , error ) {
41
+ func (s * service ) GetPersistentCacheTask (ctx context.Context , schedulerClusterID uint , id string ) (types.PersistentCacheTask , error ) {
42
42
return s .loadTask (ctx , schedulerClusterID , id )
43
43
}
44
44
45
45
// GetPersistentCacheTasks retrieves persistent cache tasks from Redis based on query parameters.
46
- func (s * service ) GetPersistentCacheTasks (ctx context.Context , q types.GetPersistentCacheTasksQuery ) ([]* types.PersistentCacheTask , int64 , error ) {
46
+ func (s * service ) GetPersistentCacheTasks (ctx context.Context , q types.GetPersistentCacheTasksQuery ) ([]types.PersistentCacheTask , int64 , error ) {
47
47
tasks , err := s .loadAllTasks (ctx , q .SchedulerClusterID )
48
48
if err != nil {
49
49
return nil , 0 , err
50
50
}
51
51
52
+ if len (tasks ) == 0 {
53
+ return []types.PersistentCacheTask {}, 0 , nil
54
+ }
55
+
52
56
return tasks , int64 (len (tasks )), nil
53
57
}
54
58
55
59
// loadAllTasks loads all persistent cache tasks from Redis based on the provided scheduler cluster ID.
56
- func (s * service ) loadAllTasks (ctx context.Context , schedulerClusterID uint ) ([]* types.PersistentCacheTask , error ) {
60
+ func (s * service ) loadAllTasks (ctx context.Context , schedulerClusterID uint ) ([]types.PersistentCacheTask , error ) {
57
61
var (
58
- tasks []* types.PersistentCacheTask
62
+ tasks []types.PersistentCacheTask
59
63
cursor uint64
60
64
)
61
65
@@ -126,18 +130,18 @@ func (s *service) loadAllTasks(ctx context.Context, schedulerClusterID uint) ([]
126
130
}
127
131
128
132
// loadTask loads a task from Redis based on the provided key.
129
- func (s * service ) loadTask (ctx context.Context , schedulerClusterID uint , id string ) (* types.PersistentCacheTask , error ) {
133
+ func (s * service ) loadTask (ctx context.Context , schedulerClusterID uint , id string ) (types.PersistentCacheTask , error ) {
130
134
taskKey := pkgredis .MakePersistentCacheTaskKeyInScheduler (schedulerClusterID , id )
131
135
rawTask , err := s .rdb .HGetAll (ctx , taskKey ).Result ()
132
136
if err != nil {
133
- return nil , err
137
+ return types. PersistentCacheTask {} , err
134
138
}
135
139
136
140
if len (rawTask ) == 0 {
137
- return nil , errors .New ("task not found" )
141
+ return types. PersistentCacheTask {} , errors .New ("task not found" )
138
142
}
139
143
140
- task := & types.PersistentCacheTask {
144
+ task := types.PersistentCacheTask {
141
145
ID : rawTask ["id" ],
142
146
Tag : rawTask ["tag" ],
143
147
Application : rawTask ["application" ],
@@ -147,55 +151,55 @@ func (s *service) loadTask(ctx context.Context, schedulerClusterID uint, id stri
147
151
// Parse PersistentReplicaCount.
148
152
persistentReplicaCount , err := strconv .ParseUint (rawTask ["persistent_replica_count" ], 10 , 64 )
149
153
if err != nil {
150
- return nil , err
154
+ return types. PersistentCacheTask {} , err
151
155
}
152
156
task .PersistentReplicaCount = persistentReplicaCount
153
157
154
158
// Parse PieceLength.
155
159
pieceLength , err := strconv .ParseUint (rawTask ["piece_length" ], 10 , 64 )
156
160
if err != nil {
157
- return nil , err
161
+ return types. PersistentCacheTask {} , err
158
162
}
159
163
task .PieceLength = pieceLength
160
164
161
165
// Parse ContentLength.
162
166
contentLength , err := strconv .ParseUint (rawTask ["content_length" ], 10 , 64 )
163
167
if err != nil {
164
- return nil , err
168
+ return types. PersistentCacheTask {} , err
165
169
}
166
170
task .ContentLength = contentLength
167
171
168
172
// Parse TotalPieceCount.
169
173
totalPieceCount , err := strconv .ParseUint (rawTask ["total_piece_count" ], 10 , 32 )
170
174
if err != nil {
171
- return nil , err
175
+ return types. PersistentCacheTask {} , err
172
176
}
173
177
task .TotalPieceCount = uint32 (totalPieceCount )
174
178
175
179
// Parse TTL.
176
180
ttl , err := strconv .ParseInt (rawTask ["ttl" ], 10 , 64 )
177
181
if err != nil {
178
- return nil , err
182
+ return types. PersistentCacheTask {} , err
179
183
}
180
184
task .TTL = time .Duration (ttl )
181
185
182
186
// Parse CreatedAt.
183
187
createdAt , err := time .Parse (time .RFC3339 , rawTask ["created_at" ])
184
188
if err != nil {
185
- return nil , err
189
+ return types. PersistentCacheTask {} , err
186
190
}
187
191
task .CreatedAt = createdAt
188
192
189
193
// Parse UpdatedAt.
190
194
updatedAt , err := time .Parse (time .RFC3339 , rawTask ["updated_at" ])
191
195
if err != nil {
192
- return nil , err
196
+ return types. PersistentCacheTask {} , err
193
197
}
194
198
task .UpdatedAt = updatedAt
195
199
196
200
peers , err := s .loadAllPeersByTaskID (ctx , schedulerClusterID , task .ID )
197
201
if err != nil {
198
- return nil , err
202
+ return types. PersistentCacheTask {} , err
199
203
}
200
204
task .Peers = peers
201
205
return task , nil
0 commit comments