1
0
Fork 0

Add trigger post jobs when post is created

Dieser Commit ist enthalten in:
Angus McLeod 2020-05-04 19:02:49 +10:00
Ursprung dd3875840b
Commit 9383695c5b
3 geänderte Dateien mit 42 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -10,6 +10,7 @@ class CustomWizard::Action
@user = params[:user] @user = params[:user]
@data = params[:data] @data = params[:data]
@log = [] @log = []
@result = CustomWizard::ActionResult.new
end end
def perform def perform
@ -17,15 +18,11 @@ class CustomWizard::Action
self.send(action['type'].to_sym) self.send(action['type'].to_sym)
end end
log = "wizard: #{@wizard.id}; action: #{action['type']}; user: #{user.username}" if creates_post? && @result.success?
@result.handler.enqueue_jobs
if @log.any?
@log.each do |item|
log << "; #{item.to_s}"
end
end end
CustomWizard::Log.create(log) save_log
end end
def mapper def mapper
@ -51,6 +48,7 @@ class CustomWizard::Action
if creator.errors.blank? if creator.errors.blank?
log_success("created topic", "id: #{post.topic.id}") log_success("created topic", "id: #{post.topic.id}")
result.handler = creator
end end
else else
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}") log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
@ -88,6 +86,7 @@ class CustomWizard::Action
if creator.errors.blank? if creator.errors.blank?
log_success("created message", "id: #{post.topic.id}") log_success("created message", "id: #{post.topic.id}")
result.handler = creator
end end
else else
log_error( log_error(
@ -320,6 +319,10 @@ class CustomWizard::Action
add_custom_fields(params) add_custom_fields(params)
end end
def creates_post?
[:create_topic, :send_message].include?(action['type'].to_sym)
end
def profile_url_fields def profile_url_fields
['profile_background', 'card_background'] ['profile_background', 'card_background']
end end
@ -371,13 +374,27 @@ class CustomWizard::Action
def log_success(message, detail = nil) def log_success(message, detail = nil)
@log.push("success: #{message} - #{detail}") @log.push("success: #{message} - #{detail}")
@result.success = true
end end
def log_error(message, detail = nil) def log_error(message, detail = nil)
@log.push("error: #{message} - #{detail}") @log.push("error: #{message} - #{detail}")
@result.success = false
end end
def log_info(message, detail = nil) def log_info(message, detail = nil)
@log.push("info: #{message} - #{detail}") @log.push("info: #{message} - #{detail}")
end end
def save_log
log = "wizard: #{@wizard.id}; action: #{action['type']}; user: #{user.username}"
if @log.any?
@log.each do |item|
log << "; #{item.to_s}"
end
end
CustomWizard::Log.create(log)
end
end end

Datei anzeigen

@ -0,0 +1,15 @@
class CustomWizard::ActionResult
attr_accessor :success, :handler
def initialize
@success = false
end
def success?
@success
end
def failed?
!success
end
end

Datei anzeigen

@ -55,6 +55,7 @@ after_initialize do
../jobs/clear_after_time_wizard.rb ../jobs/clear_after_time_wizard.rb
../jobs/refresh_api_access_token.rb ../jobs/refresh_api_access_token.rb
../jobs/set_after_time_wizard.rb ../jobs/set_after_time_wizard.rb
../lib/custom_wizard/action_result.rb
../lib/custom_wizard/action.rb ../lib/custom_wizard/action.rb
../lib/custom_wizard/builder.rb ../lib/custom_wizard/builder.rb
../lib/custom_wizard/field.rb ../lib/custom_wizard/field.rb