Class: RunPipelineScheduleWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, PipelineQueue
Defined in:
app/workers/run_pipeline_schedule_worker.rb

Constant Summary

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_CONCURRENCY_LIMIT_PERCENTAGE_BY_URGENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#perform(schedule_id, user_id, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/workers/run_pipeline_schedule_worker.rb', line 16

def perform(schedule_id, user_id, options = {})
  schedule = Ci::PipelineSchedule.find_by_id(schedule_id)
  user = User.find_by_id(user_id)

  return unless schedule_valid?(schedule, schedule_id, user, options)

  update_next_run_at_for(schedule) if options['scheduling']

  response = run_pipeline_schedule(schedule, user)
  log_error(schedule.id, response.message) if response&.error?

  response
end

#run_pipeline_schedule(schedule, user) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'app/workers/run_pipeline_schedule_worker.rb', line 70

def run_pipeline_schedule(schedule, user)
  Ci::CreatePipelineService
    .new(schedule.project, user, ref: schedule.ref)
    .execute(
      :schedule,
      save_on_errors: true, ignore_skip_ci: true,
      schedule: schedule, inputs: schedule.inputs_hash
    )
rescue StandardError => e
  error(schedule, e)
end

#schedule_valid?(schedule, schedule_id, user, options) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/workers/run_pipeline_schedule_worker.rb', line 30

def schedule_valid?(schedule, schedule_id, user, options)
  unless schedule
    log_error(schedule_id, "Schedule not found")
    return false
  end

  unless schedule.project
    log_error(schedule_id, "Project not found for schedule")
    return false
  end

  if schedule.project.self_or_ancestors_archived?
    log_error(schedule_id, "Project or ancestors are archived")
    return false
  end

  if schedule.project.deletion_in_progress_or_scheduled_in_hierarchy_chain?
    log_error(schedule_id, "Project, namespace or ancestors are scheduled for deletion")
    return false
  end

  if schedule_owner_not_available?(schedule)
    log_error(schedule_id, "Pipeline schedule owner is no longer available to schedule the pipeline")
    notify_project_owner_and_deactivate_schedule(schedule)
    return false
  end

  unless user
    log_error(schedule_id, "User not found")
    return false
  end

  if options['scheduling'] && schedule.next_run_at.future?
    log_error(schedule_id, "Schedule next run time is in future")
    return false
  end

  true
end