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.
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.
18 19 20 21 |
# File 'lib/rubino/api/operations/cron_jobs/create_operation.rb', line 18 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rubino/api/operations/cron_jobs/create_operation.rb', line 23 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 |