Class: Rubino::API::Operations::CronJobs::CreateOperation
- Inherits:
-
Object
- Object
- Rubino::API::Operations::CronJobs::CreateOperation
- Includes:
- ScheduleValidation
- Defined in:
- lib/rubino/api/operations/cron_jobs/create_operation.rb
Overview
POST /v1/jobs Creates a cron job row and registers it with the in-process scheduler. New jobs default to deliver=“local” when the client omits it.
Class Method Summary collapse
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(repository: nil, scheduler: nil) ⇒ CreateOperation
constructor
Accepts an alternate repository and scheduler for tests.
Constructor Details
#initialize(repository: nil, scheduler: nil) ⇒ CreateOperation
Accepts an alternate repository and scheduler for tests.
22 23 24 25 |
# File 'lib/rubino/api/operations/cron_jobs/create_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/create_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 38 39 40 41 |
# File 'lib/rubino/api/operations/cron_jobs/create_operation.rb', line 27 def call(request) attrs = request.validate!(Schemas::CreateCronJob) validate_schedule!(attrs[:schedule]) job = @repository.create( name: attrs[:name], schedule: attrs[:schedule], prompt: attrs[:prompt], skills: attrs[:skills] || [], model: attrs[:model], provider: attrs[:provider], deliver: attrs[:deliver] || "local" ) @scheduler.schedule(job) [201, Serializer.call(job)] end |