Class: Rubino::API::Operations::CronJobs::UpdateOperation

Inherits:
Object
  • Object
show all
Includes:
ScheduleValidation
Defined in:
lib/rubino/api/operations/cron_jobs/update_operation.rb

Overview

PATCH /v1/jobs/:id Applies a partial update and resyncs the scheduler: always unschedule, reschedule only when the resulting row is still enabled.

Raises:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository: nil, scheduler: nil) ⇒ UpdateOperation

Accepts an alternate repository and scheduler for tests.



22
23
24
25
# File 'lib/rubino/api/operations/cron_jobs/update_operation.rb', line 22

def initialize(repository: nil, scheduler: nil)
  @repository = repository || ::Rubino::Jobs::CronJobRepository.new
  @scheduler = scheduler || ::Rubino::Jobs::Scheduler.instance
end

Class Method Details

.call(request) ⇒ Object



17
18
19
# File 'lib/rubino/api/operations/cron_jobs/update_operation.rb', line 17

def self.call(request)
  new.call(request)
end

Instance Method Details

#call(request) ⇒ Object

Raises:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubino/api/operations/cron_jobs/update_operation.rb', line 27

def call(request)
  id = request.params.fetch("id")
  raise NotFoundError.new("cron_job", id) unless @repository.find(id)

  attrs = request.validate!(Schemas::UpdateCronJob)
  validate_schedule!(attrs[:schedule])
  updated = @repository.update(id, attrs)
  @scheduler.unschedule(id)
  @scheduler.schedule(updated) if updated[:enabled]
  [200, Serializer.call(updated)]
end