Class: Activity::AutoChainCloser
- Inherits:
-
BaseService
- Object
- BaseService
- Activity::AutoChainCloser
- Defined in:
- app/services/activity/auto_chain_closer.rb
Overview
Responsible for auto closing activities which have an auto close rule setup
in their activity chain result types. This functionality aids in creating
escalation or email drip campaigns type workflows when paired with email templates.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#load_activities_to_auto_close ⇒ Object
33 34 35 |
# File 'app/services/activity/auto_chain_closer.rb', line 33 def load_activities_to_auto_close Activity.overdue_activities.joins(activity_type: :activity_chain_types).merge(ActivityChainType.due_date) end |
#process(activities: nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/activity/auto_chain_closer.rb', line 10 def process(activities: nil) # Load activities eligible for an auto close failed_activities = [] auto_closed_activities = [] load_activities_to_auto_close.find_each(batch_size: 100) do |activity| begin result = activity.auto_close_if_applicable if result == :overdue_auto_close auto_closed_activities << { activity_id: activity.id, result: activity.activity_result_type&.result_code } else # Our query should have filtered out these, if they end up here they are to be considered failed failed_activities << { activity_id: activity.id, error: result } end rescue StandardError => exc = activity.errors_to_s failed_activities << { activity_id: activity.id, error: } ErrorReporting.error(exc, "Cannot auto close activity id #{activity.id}, errors: #{}") end end Result.new(auto_closed_activities: auto_closed_activities, failed_activities: failed_activities) end |