add job hook when post is created

This commit is contained in:
Albert Yi
2019-01-30 10:54:27 -08:00
parent 6243925aeb
commit 2961be636a
2 changed files with 17 additions and 1 deletions

View File

@@ -2,6 +2,10 @@ module Automod
class UpdateDynamoDbJob < Struct.new(:post_id)
extend Memoist
def self.enabled?
Danbooru.config.aws_access_key_id.present?
end
def perform
post = Post.find(post_id)
data = {
@@ -27,7 +31,14 @@ module Automod
end
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
memoize :dynamo_db_client

View File

@@ -90,6 +90,11 @@ class UploadService
end
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
end