Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
twitter_syncer
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
twitter_syncer
Commits
7bc8253a
Commit
7bc8253a
authored
Aug 19, 2024
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retweet wait 5m
parent
fa3106c2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
29 deletions
+50
-29
api_service.go
api_service.go
+8
-1
client.go
client.go
+18
-18
swagger.yaml
docs/swagger.yaml
+1
-2
syncer
syncer
+0
-0
task.go
task.go
+23
-8
No files found.
api_service.go
View file @
7bc8253a
...
...
@@ -88,7 +88,7 @@ func Project(c *fiber.Ctx) error {
}
cli
:=
NewClient
(
req
.
Config
)
cli
:=
NewClient
(
req
.
Config
,
nil
)
me
,
err
:=
cli
.
Me
()
...
...
@@ -264,6 +264,13 @@ func TaskStop(c *fiber.Ctx) error {
})
}
if
err
:=
Worker
.
StopJob
(
req
.
User
,
req
.
TaskType
);
err
!=
nil
{
return
c
.
JSON
(
Res
{
Code
:
500
,
Msg
:
err
.
Error
(),
})
}
err
:=
StopTaskUpdate
(
req
)
if
err
!=
nil
{
...
...
client.go
View file @
7bc8253a
...
...
@@ -38,7 +38,7 @@ PER USER
*/
var
LikeRateLimit
*
rate
.
Limiter
=
rate
.
NewLimiter
(
rate
.
Every
(
3
*
time
.
Minute
),
1
)
var
RetweetRateLimit
*
rate
.
Limiter
=
rate
.
NewLimiter
(
rate
.
Every
(
3
*
time
.
Minute
),
1
)
var
RetweetRateLimit
*
rate
.
Limiter
=
rate
.
NewLimiter
(
rate
.
Every
(
5
*
time
.
Minute
),
1
)
type
authorize
struct
{
Token
string
...
...
@@ -65,17 +65,17 @@ type Config struct {
Token
string
`json:"token"`
}
//
func NewLikeClient(cfg Config) *Client {
//
return NewClient(cfg, LikeRateLimit)
//
}
func
NewLikeClient
(
cfg
Config
)
*
Client
{
return
NewClient
(
cfg
,
LikeRateLimit
)
}
//
func NewRetweeterClient(cfg Config) *Client {
//
return NewClient(cfg, RetweetRateLimit)
//
}
func
NewRetweeterClient
(
cfg
Config
)
*
Client
{
return
NewClient
(
cfg
,
RetweetRateLimit
)
}
//
func NewClient(cfg Config, rts *rate.Limiter) *Client {
func
NewClient
(
cfg
Config
,
rts
*
rate
.
Limiter
)
*
Client
{
func
NewClient
(
cfg
Config
)
*
Client
{
//
func NewClient(cfg Config) *Client {
//twitterAPIKey := "lVnj6Ox9HPcI4LwArSSYU7Pba" //os.Getenv("TWITTER_API_KEY")
//twitterAPIKeySecret := "QMSnWG4QwyXWBVW2hQazzxhw9cSjd32CDfXGkg2DEaUUdscCRZ" //os.Getenv("TWITTER_API_KEY_SECRET")
...
...
@@ -100,10 +100,10 @@ func NewClient(cfg Config) *Client {
}
return
&
Client
{
Client
:
twitterClient
,
// Ratelimiter:
rts,
RetweeterRatelimiter
:
RetweetRateLimit
,
LikingUserRatelimiter
:
LikeRateLimit
,
Client
:
twitterClient
,
Ratelimiter
:
rts
,
//
RetweeterRatelimiter: RetweetRateLimit,
//
LikingUserRatelimiter: LikeRateLimit,
}
}
...
...
@@ -142,9 +142,9 @@ func (c *Client) Retweeters(tweetId string, next string) ([]*twitter.UserObj, st
// TODO: Fix performance by removing unneeded allocaton here
ctx
:=
context
.
Background
()
//
err := c.Ratelimiter.Wait(ctx) // This is a blocking call.
err
:=
c
.
Ratelimiter
.
Wait
(
ctx
)
// This is a blocking call.
err
:=
c
.
RetweeterRatelimiter
.
Wait
(
ctx
)
// This is a blocking call.
//
err := c.RetweeterRatelimiter.Wait(ctx) // This is a blocking call.
if
err
!=
nil
{
return
nil
,
""
,
nil
,
err
}
...
...
@@ -169,8 +169,8 @@ func (c *Client) TweetLikingUsers(tweetId string, next string) ([]*twitter.UserO
// TODO: Fix performance by removing unneeded allocaton here
ctx
:=
context
.
Background
()
//
err := c.Ratelimiter.Wait(ctx) // This is a blocking call.
err
:=
c
.
LikingUserRatelimiter
.
Wait
(
ctx
)
// This is a blocking call.
err
:=
c
.
Ratelimiter
.
Wait
(
ctx
)
// This is a blocking call.
//
err := c.LikingUserRatelimiter.Wait(ctx) // This is a blocking call.
if
err
!=
nil
{
return
nil
,
""
,
nil
,
err
}
...
...
@@ -192,7 +192,7 @@ func (c *Client) TweetLikingUsers(tweetId string, next string) ([]*twitter.UserO
}
func
(
c
*
Client
)
M
e
()
(
map
[
string
]
*
twitter
.
UserDictionary
,
error
)
{
func
(
c
*
Client
)
Usag
e
()
(
map
[
string
]
*
twitter
.
UserDictionary
,
error
)
{
// ctx is generated here only to use with Ratelimiter
// TODO: Fix performance by removing unneeded allocaton here
...
...
docs/swagger.yaml
View file @
7bc8253a
...
...
@@ -358,7 +358,7 @@ components:
example
:
"
1800805503066661056"
StopTaskReq
:
required
:
-
task
_id
-
user
_id
-
task_type
type
:
object
properties
:
...
...
@@ -374,7 +374,6 @@ components:
type
:
string
example
:
"
1800805503066661056"
user_id
:
description
:
方便识别用户身份信息
type
:
string
example
:
"
1783145144700874752"
# start:
...
...
syncer
View file @
7bc8253a
No preview for this file type
task.go
View file @
7bc8253a
...
...
@@ -9,19 +9,35 @@ import (
type
Work
struct
{
Lock
sync
.
Mutex
Task
map
[
string
]
chan
<-
interface
{}
userClient
map
[
string
]
*
Client
Task
map
[
string
]
chan
<-
interface
{}
//
userClient map[string]*Client
}
var
Worker
Work
func
init
()
{
Worker
=
Work
{
Task
:
make
(
map
[
string
]
chan
<-
interface
{}),
userClient
:
make
(
map
[
string
]
*
Client
),
Task
:
make
(
map
[
string
]
chan
<-
interface
{}),
//
userClient: make(map[string]*Client),
}
}
func
(
w
*
Work
)
StopJob
(
userId
,
taskType
string
)
error
{
w
.
Lock
.
Lock
()
if
v
,
ok
:=
w
.
Task
[
userId
+
"-"
+
taskType
];
ok
{
close
(
v
)
}
else
{
return
fmt
.
Errorf
(
"%s do not run"
,
userId
+
"-"
+
taskType
)
}
// done := w.RunJob(t)
// w.Task[t.UserId+"-"+t.TaskType] = done
w
.
Lock
.
Unlock
()
return
nil
}
func
(
w
*
Work
)
AddJob
(
t
TaskJob
)
error
{
w
.
Lock
.
Lock
()
...
...
@@ -44,11 +60,10 @@ func (w *Work) RunJob(t TaskJob) chan<- interface{} {
go
func
()
{
var
cli
*
Client
if
v
,
ok
:=
w
.
userClient
[
t
.
UserId
];
ok
{
cli
=
v
if
t
.
TaskType
==
RetweetType
{
cli
=
NewRetweeterClient
(
t
.
Config
)
}
else
{
cli
=
NewClient
(
t
.
Config
)
w
.
userClient
[
t
.
UserId
]
=
cli
cli
=
NewLikeClient
(
t
.
Config
)
}
page
:=
NewPageUsers
(
NewIdx
(
t
.
Idx
))
...
...
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