add job hook when post is created
This commit is contained in:
@@ -2,6 +2,10 @@ module Automod
|
|||||||
class UpdateDynamoDbJob < Struct.new(:post_id)
|
class UpdateDynamoDbJob < Struct.new(:post_id)
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.aws_access_key_id.present?
|
||||||
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
post = Post.find(post_id)
|
post = Post.find(post_id)
|
||||||
data = {
|
data = {
|
||||||
@@ -27,7 +31,14 @@ module Automod
|
|||||||
end
|
end
|
||||||
|
|
||||||
def dynamo_db_client
|
def dynamo_db_client
|
||||||
Aws::DynamoDB::Client.new(region: "us-west-1")
|
credentials = Aws::Credentials.new(
|
||||||
|
Danbooru.config.aws_access_key_id,
|
||||||
|
Danbooru.config.aws_secret_access_key
|
||||||
|
)
|
||||||
|
Aws::DynamoDB::Client.new(
|
||||||
|
credentials: credentials,
|
||||||
|
region: "us-west-1"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
memoize :dynamo_db_client
|
memoize :dynamo_db_client
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ class UploadService
|
|||||||
end
|
end
|
||||||
|
|
||||||
upload.update(status: "completed", post_id: @post.id)
|
upload.update(status: "completed", post_id: @post.id)
|
||||||
|
|
||||||
|
if @post.is_pending? && Automod::UpdateDynamoDbJob.enabled?
|
||||||
|
Delayed::Job.enqueue(Automod::UpdateDynamoDbJob.new(@post.id), run_at: 84.hours.from_now, queue: "default")
|
||||||
|
end
|
||||||
|
|
||||||
@post
|
@post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user