Class: RailsCloudTasks::Scheduler
- Inherits:
-
Object
- Object
- RailsCloudTasks::Scheduler
- Defined in:
- lib/rails_cloud_tasks/scheduler.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(credentials: RailsCloudTasks::Credentials.new, logger: RailsCloudTasks.logger) ⇒ Scheduler
constructor
A new instance of Scheduler.
-
#upsert ⇒ Object
Create & Update scheduler job on Google Cloud TODO: Support to delete scheduled jobs.
Constructor Details
#initialize(credentials: RailsCloudTasks::Credentials.new, logger: RailsCloudTasks.logger) ⇒ Scheduler
Returns a new instance of Scheduler.
9 10 11 12 13 14 15 |
# File 'lib/rails_cloud_tasks/scheduler.rb', line 9 def initialize( credentials: RailsCloudTasks::Credentials.new, logger: RailsCloudTasks.logger ) @credentials = credentials @logger = logger end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
7 8 9 |
# File 'lib/rails_cloud_tasks/scheduler.rb', line 7 def credentials @credentials end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/rails_cloud_tasks/scheduler.rb', line 7 def logger @logger end |
Instance Method Details
#client ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rails_cloud_tasks/scheduler.rb', line 27 def client configure = lambda { |client| client.configure.credentials = credentials.generate(service_account_email) } @client ||= Google::Cloud::Scheduler.cloud_scheduler.tap(&configure) end |
#upsert ⇒ Object
Create & Update scheduler job on Google Cloud TODO: Support to delete scheduled jobs
19 20 21 22 23 24 25 |
# File 'lib/rails_cloud_tasks/scheduler.rb', line 19 def upsert result = { success: [], failure: [] } scheduler_jobs.each do |job| upsert_job(job) ? (result[:success] << job[:name]) : (result[:failure] << job[:name]) end log_output(result) end |