Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job now prints full output for all api calls. Next step, extract just… #166

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/api_keys.rb

# ignore local database.yml
/config/database.yml
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/stock_prices_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ class StockPricesUpdateJob < ApplicationJob
def perform(*args)
# For each stock symbol, request the latest closing cost
# update the stocks table with each new closing cost
stock_symbols = ["KO", "SNE", "TWX", "DIS", "SIRI", "F", "EA", "FB", "UA", "LUV", "GPS"]
stock_symbols.each do |symbol|
api_request(symbol)
stock_db = Stock.find_by(ticker: symbol)
end
Comment on lines +7 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ensure the stock can be found in the DB before we request the stock? As written, would this cause the job to abort if the stock with one of the tickers can't be found, skipping the processing of any further stocks in the list

Copy link
Member

@abachman abachman Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.find_by is okay here, since it returns nil instead of raising NotFoundError

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot about that, thanks.

This means we'll have to do nil checks, though

end

private

def api_request(symbol)
url = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=#{symbol}&apikey=#{API_KEY}"
uri = URI.parse(url)
print Net::HTTP.get(uri)
end
end