Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
cache
Commits
e047b6f7
Commit
e047b6f7
authored
Feb 01, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add subscribe for task update
parent
cb54fe8c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
cache.go
cachedata/cache.go
+1
-0
task.go
cachedata/task.go
+19
-0
No files found.
cachedata/cache.go
View file @
e047b6f7
...
@@ -51,5 +51,6 @@ func NewCacheData(ctx context.Context, options RedisConnParam, mysqlConfig model
...
@@ -51,5 +51,6 @@ func NewCacheData(ctx context.Context, options RedisConnParam, mysqlConfig model
for
i
:=
0
;
i
<
cache
.
maxRoutine
;
i
++
{
for
i
:=
0
;
i
<
cache
.
maxRoutine
;
i
++
{
go
cache
.
queryRoutine
()
go
cache
.
queryRoutine
()
}
}
go
cache
.
SubscribeTaskUpdate
()
return
cache
return
cache
}
}
cachedata/task.go
View file @
e047b6f7
package
cachedata
package
cachedata
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"github.com/odysseus/payment/model"
"github.com/odysseus/payment/model"
"strconv"
"strconv"
...
@@ -108,3 +109,21 @@ func (c *CacheData) SetTaskDataToRedis(task *model.TaskType) error {
...
@@ -108,3 +109,21 @@ func (c *CacheData) SetTaskDataToRedis(task *model.TaskType) error {
return
err
return
err
}
}
}
}
const
(
TASKUPDATECHANNEL
=
"task-update"
)
func
(
c
*
CacheData
)
SubscribeTaskUpdate
()
{
ch
:=
TASKUPDATECHANNEL
sub
:=
c
.
rdb
.
Subscribe
(
context
.
Background
(),
ch
)
defer
sub
.
Close
()
for
msg
:=
range
sub
.
Channel
()
{
taskPath
:=
msg
.
Payload
c
.
pathLru
.
Remove
(
taskPath
)
}
}
func
(
c
*
CacheData
)
PublichTaskUpdate
(
path
string
)
error
{
return
c
.
rdb
.
Publish
(
c
.
ctx
,
TASKUPDATECHANNEL
,
path
)
.
Err
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment