Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F21907395
scheduled_activity_worker.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
scheduled_activity_worker.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Workers.ScheduledActivityWorker
do
@moduledoc
"""
The worker to post scheduled activity.
"""
use
Pleroma.Workers.WorkerHelper
,
queue
:
"scheduled_activities"
alias
Pleroma.Config
alias
Pleroma.ScheduledActivity
alias
Pleroma.User
alias
Pleroma.Web.CommonAPI
require
Logger
@impl
Oban.Worker
def
perform
(%
Job
{
args
:
%{
"activity_id"
=>
activity_id
}})
do
if
Config
.
get
([
ScheduledActivity
,
:enabled
])
do
case
Pleroma.Repo
.
get
(
ScheduledActivity
,
activity_id
)
do
%
ScheduledActivity
{}
=
scheduled_activity
->
post_activity
(
scheduled_activity
)
_
->
Logger
.
error
(
"
#{
__MODULE__
}
Couldn't find scheduled activity:
#{
activity_id
}
"
)
end
end
end
defp
post_activity
(%
ScheduledActivity
{
user_id
:
user_id
,
params
:
params
}
=
scheduled_activity
)
do
params
=
Map
.
new
(
params
,
fn
{
key
,
value
}
->
{
String
.
to_existing_atom
(
key
),
value
}
end
)
with
{
:delete
,
{
:ok
,
_
}}
<-
{
:delete
,
ScheduledActivity
.
delete
(
scheduled_activity
)},
{
:user
,
%
User
{}
=
user
}
<-
{
:user
,
User
.
get_cached_by_id
(
user_id
)},
{
:post
,
{
:ok
,
_
}}
<-
{
:post
,
CommonAPI
.
post
(
user
,
params
)}
do
:ok
else
error
->
Logger
.
error
(
"
#{
__MODULE__
}
Couldn't create a status from the scheduled activity:
#{
inspect
(
error
)
}
"
)
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sun, Dec 28, 1:41 AM (16 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
766816
Default Alt Text
scheduled_activity_worker.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment