Skip to content

Commit c0a2526

Browse files
committed
add delay to sources fetch from webhook
1 parent 4c47d20 commit c0a2526

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

app/controllers/inbound_webhooks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class InboundWebhooksController < ::ActionController::Base # rubocop: disable Ra
33
before_action :verify!
44

55
def trigger
6-
::Task::Starter.new(webhook.project).call
6+
::Task::Starter.new(webhook.project).call(sources_fetch_delay: 20.seconds)
77
head(:ok)
88
rescue ::ActiveRecord::RecordInvalid
99
head(:unprocessable_entity)

app/jobs/sources_fetch_job.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ class SourcesFetchJob < ::ApplicationJob
22
queue_as :long
33

44
class << self
5-
def start(project, task = nil)
5+
def start(project, task = nil, delay: nil)
66
return if project.fetching?
77
return if task && !task.pending_fetch?
88

99
project.fetching!
10-
perform_later(project.id, task&.id)
10+
if delay
11+
set(wait: delay).perform_later(project.id, task&.id)
12+
else
13+
perform_later(project.id, task&.id)
14+
end
1115
end
1216
end
1317

app/models/task/starter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def initialize(project, skip_fetch: false, distro_ids: nil)
66
@skip_fetch = skip_fetch
77
end
88

9-
def call # rubocop: disable Metrics/MethodLength
9+
def call(sources_fetch_delay: nil) # rubocop: disable Metrics/MethodLength
1010
create_source_tarball_if_not_exists
1111

1212
task = project.tasks.build(distro_ids: distro_ids)
@@ -17,7 +17,7 @@ def call # rubocop: disable Metrics/MethodLength
1717
task.state = 'pending_fetch'
1818
end
1919
if task.save && task.pending_fetch?
20-
::SourcesFetchJob.start(project, task)
20+
::SourcesFetchJob.start(project, task, delay: sources_fetch_delay)
2121
end
2222
task
2323
end

0 commit comments

Comments
 (0)