Class: WolfCore::JobSchedulerDataSource
- Inherits:
-
Object
- Object
- WolfCore::JobSchedulerDataSource
- Defined in:
- lib/wolf_core/infrastructure/job_scheduler_data_source.rb
Instance Attribute Summary collapse
-
#default_group_name ⇒ Object
readonly
Returns the value of attribute default_group_name.
-
#default_timezone ⇒ Object
readonly
Returns the value of attribute default_timezone.
Instance Method Summary collapse
- #cancel_schedule(job_id:, options: {}) ⇒ Object
- #get_schedule(job_id:, options: {}) ⇒ Object
-
#initialize(region: "us-east-1", client: nil, default_group_name: "default", default_timezone: "UTC") ⇒ JobSchedulerDataSource
constructor
A new instance of JobSchedulerDataSource.
- #schedule_at(job_id:, run_at:, target:, config: {}) ⇒ Object
- #schedule_recurring(job_id:, schedule:, target:, config: {}) ⇒ Object
Constructor Details
#initialize(region: "us-east-1", client: nil, default_group_name: "default", default_timezone: "UTC") ⇒ JobSchedulerDataSource
Returns a new instance of JobSchedulerDataSource.
11 12 13 14 15 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 11 def initialize(region: "us-east-1", client: nil, default_group_name: "default", default_timezone: "UTC") @client = client || Aws::Scheduler::Client.new(region: region) @default_group_name = default_group_name @default_timezone = default_timezone end |
Instance Attribute Details
#default_group_name ⇒ Object (readonly)
Returns the value of attribute default_group_name.
9 10 11 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 9 def default_group_name @default_group_name end |
#default_timezone ⇒ Object (readonly)
Returns the value of attribute default_timezone.
9 10 11 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 9 def default_timezone @default_timezone end |
Instance Method Details
#cancel_schedule(job_id:, options: {}) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 38 def cancel_schedule(job_id:, options: {}) Result.try do response = @client.delete_schedule( name: job_id, group_name: [:group_name] || default_group_name ) Result.success(data: { response: response }) end end |
#get_schedule(job_id:, options: {}) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 48 def get_schedule(job_id:, options: {}) Result.try do response = @client.get_schedule( name: job_id, group_name: [:group_name] || default_group_name ) Result.success(data: { schedule: response }) end end |
#schedule_at(job_id:, run_at:, target:, config: {}) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 17 def schedule_at(job_id:, run_at:, target:, config: {}) Result.try do job_id = shorten_job_id(job_id) if config[:can_shorten_job_id] expr = at_expression(run_at) normalized_target = normalize_target(target) response = schedule_with_expression(job_id: job_id, expr: expr, target: normalized_target, config: config) Result.success(data: { response: response }) end end |
#schedule_recurring(job_id:, schedule:, target:, config: {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wolf_core/infrastructure/job_scheduler_data_source.rb', line 27 def schedule_recurring(job_id:, schedule:, target:, config: {}) Result.try do job_id = shorten_job_id(job_id) if config[:can_shorten_job_id] expr = expression_from_schedule!(schedule) normalized_target = normalize_target(target) response = schedule_with_expression(job_id: job_id, expr: expr, target: normalized_target, config: config) Result.success(data: { response: response }) end end |