Class: Rubino::API::Operations::CronJobs::PauseOperation

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

Overview

POST /v1/jobs/:id/pause Flips enabled=false on the cron job and unschedules its tick. Idempotent.

Raises:

Instance Method Summary collapse

Constructor Details

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

Accepts an alternate repository and scheduler for tests.



13
14
15
16
# File 'lib/rubino/api/operations/cron_jobs/pause_operation.rb', line 13

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

Instance Method Details

#call(request) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
# File 'lib/rubino/api/operations/cron_jobs/pause_operation.rb', line 18

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

  updated = @repository.update(id, enabled: false)
  @scheduler.unschedule(id)
  [200, Serializer.call(updated)]
end