-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduled post #848
base: master
Are you sure you want to change the base?
Scheduled post #848
Changes from all commits
22cdf28
4341570
f51ece6
28a8187
18fd076
1e816df
a89e45f
532675b
4f500e3
6394486
d37d54e
b862d79
3e0bf55
2e439ab
a48e09a
1e2606e
8096d4a
054353f
1c9a250
f249da9
fe0df4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package simulcontroller | ||
|
||
import ( | ||
"fmt" | ||
"github.com/mattermost/mattermost-load-test-ng/loadtest" | ||
"github.com/mattermost/mattermost-load-test-ng/loadtest/control" | ||
"github.com/mattermost/mattermost-load-test-ng/loadtest/user" | ||
"github.com/mattermost/mattermost/server/public/model" | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
func (c *SimulController) createScheduledPost(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ScheduledPostsEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "scheduled posts not enabled"} | ||
} | ||
|
||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
var rootId = "" | ||
if rand.Float64() < 0.25 { | ||
post, err := u.Store().RandomPostForChannel(channel.Id) | ||
if err == nil { | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should handle the error case. |
||
if post.RootId != "" { | ||
rootId = post.RootId | ||
} else { | ||
rootId = post.Id | ||
} | ||
} | ||
} | ||
|
||
if err := sendTypingEventIfEnabled(u, channel.Id); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
message, err := createMessage(u, channel, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume we can schedule replies as well. A case to consider adding. |
||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
scheduledPost := &model.ScheduledPost{ | ||
Draft: model.Draft{ | ||
Message: message, | ||
ChannelId: channel.Id, | ||
RootId: rootId, | ||
CreateAt: model.GetMillis(), | ||
}, | ||
ScheduledAt: loadtest.RandomFutureTime(time.Hour*24*2, time.Hour*24*10), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really welcome named constants to make it straightforward to read, e.g. |
||
} | ||
|
||
if rand.Float64() < probabilityAttachFileToPost { | ||
if err := control.AttachFilesToDraft(u, &scheduledPost.Draft); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
} | ||
|
||
if err := u.CreateScheduledPost(channel.TeamId, scheduledPost); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post created in channel with id %s", channel.Id)} | ||
} | ||
|
||
func (c *SimulController) updateScheduledPost(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ScheduledPostsEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "scheduled posts not enabled"} | ||
} | ||
|
||
scheduledPost, err := u.Store().GetRandomScheduledPost() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we ensuring |
||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
if scheduledPost == nil { | ||
return control.UserActionResponse{Info: "no scheduled posts found"} | ||
} | ||
|
||
channel, err := u.Store().CurrentChannel() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
message, err := createMessage(u, channel, false) | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
scheduledPost.Message = message | ||
scheduledPost.ScheduledAt = loadtest.RandomFutureTime(time.Hour*24*2, time.Hour*24*10) | ||
|
||
if err := u.UpdateScheduledPost(channel.TeamId, scheduledPost); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post updated in channel with id %s", channel.Id)} | ||
} | ||
|
||
func (c *SimulController) deleteScheduledPost(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ScheduledPostsEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "scheduled posts not enabled"} | ||
} | ||
|
||
scheduledPost, err := u.Store().GetRandomScheduledPost() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
if scheduledPost == nil { | ||
return control.UserActionResponse{Info: "no scheduled posts found"} | ||
} | ||
|
||
if err := u.DeleteScheduledPost(scheduledPost); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post with id %s deleted", scheduledPost.Id)} | ||
} | ||
|
||
func (c *SimulController) sendScheduledPostNow(u user.User) control.UserActionResponse { | ||
if ok, resp := control.ScheduledPostsEnabled(u); resp.Err != nil { | ||
return resp | ||
} else if !ok { | ||
return control.UserActionResponse{Info: "scheduled posts not enabled"} | ||
} | ||
|
||
scheduledPost, err := u.Store().GetRandomScheduledPost() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
if scheduledPost == nil { | ||
return control.UserActionResponse{Info: "no scheduled posts found"} | ||
} | ||
|
||
post, err := scheduledPost.ToPost() | ||
if err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
if _, err := u.CreatePost(post); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
if err := u.DeleteScheduledPost(scheduledPost); err != nil { | ||
return control.UserActionResponse{Err: control.NewUserError(err)} | ||
} | ||
|
||
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post with id %s manually sent now", scheduledPost.Id)} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary log?