summaryrefslogtreecommitdiff
path: root/app/services/clusters/agents/create_activity_event_service.rb
blob: 87554f0e4954c4d6438c3c81aa5f68f78626659c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Clusters
  module Agents
    class CreateActivityEventService
      def initialize(agent, **params)
        @agent = agent
        @params = params
      end

      def execute
        agent.activity_events.create!(params)

        DeleteExpiredEventsWorker.perform_at(schedule_cleanup_at, agent.id)

        ServiceResponse.success
      rescue StandardError => e
        Gitlab::ErrorTracking.track_exception(e, agent_id: agent.id)

        ServiceResponse.error(message: e.message)
      end

      private

      attr_reader :agent, :params

      def schedule_cleanup_at
        1.hour.from_now.change(min: agent.id % 60)
      end
    end
  end
end