lib/rails_cloud_tasks/scheduler.rb in rails-cloud-tasks-0.0.6 vs lib/rails_cloud_tasks/scheduler.rb in rails-cloud-tasks-0.0.7.pre.rc
- old
+ new
@@ -2,21 +2,17 @@
class Scheduler
delegate :project_id, :location_id, :host, :auth, :tasks_path,
:scheduler_file_path, :scheduler_prefix_name,
:service_account_email, to: 'RailsCloudTasks.config'
- attr_reader :client, :credentials, :logger
+ attr_reader :credentials, :logger
def initialize(
- client: Google::Cloud::Scheduler.cloud_scheduler,
credentials: RailsCloudTasks::Credentials.new,
logger: RailsCloudTasks.logger
)
- client.configure do |config|
- config.credentials = credentials.generate(service_account_email)
- end
- @client = client
+ @credentials = credentials
@logger = logger
end
# Create & Update scheduler job on Google Cloud
# TODO: Support to delete scheduled jobs
@@ -24,9 +20,15 @@
result = { success: [], failure: [] }
scheduler_jobs.each do |job|
upsert_job(job) ? (result[:success] << job[:name]) : (result[:failure] << job[:name])
end
log_output(result)
+ end
+
+ def client
+ @client ||= Google::Cloud::Scheduler.cloud_scheduler.configure do |config|
+ config.credentials = credentials.generate(service_account_email)
+ end
end
protected
def location_path