Class: Rubino::API::Operations::CronJobs::DeleteOperation

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

Overview

DELETE /v1/jobs/:id Unschedules the cron job from the in-process scheduler before deleting the row, so no stray ticks fire post-delete.

Returns:

  • ([Integer, Hash])

    204 No Content.

Raises:

Instance Method Summary collapse

Constructor Details

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

Accepts an alternate repository and scheduler for tests.



15
16
17
18
# File 'lib/rubino/api/operations/cron_jobs/delete_operation.rb', line 15

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:



20
21
22
23
24
25
26
27
# File 'lib/rubino/api/operations/cron_jobs/delete_operation.rb', line 20

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

  @scheduler.unschedule(id)
  @repository.destroy!(id)
  Responses.no_content
end