Skip to content

Commit 577cab5

Browse files
Release_2025-07-01
Release 2025 07 01
2 parents 12ee6c9 + 9e67566 commit 577cab5

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Travis::API::V3
2+
class Renderer::CsvExports < ModelRenderer
3+
representation(:minimal, :status, :message, :owner_id, :owner_type)
4+
representation(:standard, :status, :message, :owner_id, :owner_type)
5+
end
6+
end

lib/travis/api/v3/routes.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ module Routes
169169
route '/executions_per_sender'
170170
get :for_owner_per_sender
171171
end
172+
173+
resource :csv_exports do
174+
route '/csv_exports'
175+
post :create
176+
end
172177
end
173178

174179
resource :credits_calculator do

lib/travis/api/v3/services.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Services
2424
CreditsCalculator = Module.new { extend Services }
2525
Cron = Module.new { extend Services }
2626
Crons = Module.new { extend Services }
27+
CsvExports = Module.new { extend Services }
2728
CustomKey = Module.new { extend Services }
2829
CustomKeys = Module.new { extend Services }
2930
EmailSubscription = Module.new { extend Services }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Travis::API::V3
2+
module Services::CsvExports
3+
class Create < Service
4+
params :report_type, :recipient_email, :expires_in, :start_date, :end_date, prefix: :csv_export
5+
6+
def run!
7+
owner = query(:owner).find
8+
raise NotFound, 'Owner not found' unless owner
9+
10+
csv_export_data = get_csv_export_data
11+
enqueue_csv_export(owner, csv_export_data)
12+
13+
recipient_email = csv_export_data['recipient_email']
14+
15+
response = OpenStruct.new(
16+
status: 202,
17+
message: "CSV export job enqueued. You will receive an email at #{recipient_email} when it's ready.",
18+
owner_id: owner.id,
19+
owner_type: owner.class.name
20+
)
21+
22+
result(response)
23+
end
24+
25+
private
26+
27+
def get_csv_export_data
28+
input_json = @env['travis.input.json'] if @env
29+
input_json&.dig('csv_export') || {}
30+
end
31+
32+
def enqueue_csv_export(owner, csv_export_data)
33+
payload = {
34+
'owner_id' => owner.id,
35+
'owner_type' => owner.class.name,
36+
'report_type' => csv_export_data['report_type'],
37+
'recipient_email' => csv_export_data['recipient_email'],
38+
'expires_in' => csv_export_data['expires_in'],
39+
'start_date' => csv_export_data['start_date'],
40+
'end_date' => csv_export_data['end_date']
41+
}
42+
43+
Sidekiq::Client.push(
44+
'queue' => 'billing',
45+
'class' => 'Travis::Billing::Worker',
46+
'args' => [
47+
nil,
48+
'Travis::Billing::Services::Executions::CsvExport',
49+
'perform',
50+
payload
51+
].map(&:to_json)
52+
)
53+
54+
Travis.logger.info "CSV export job enqueued with payload: #{payload}"
55+
end
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)