Class: Rubino::API::Operations::CronJobs::UpdateOperation
- Inherits:
-
Object
- Object
- Rubino::API::Operations::CronJobs::UpdateOperation
- 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.
Class Method Summary collapse
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(repository: nil, scheduler: nil) ⇒ UpdateOperation
constructor
Accepts an alternate repository and scheduler for tests.
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
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 |