Learn more >
Get the code
View the demo
by Anthony Amanse | Published November 6, 2018
For a long time, cloud computing has helped developers move from an on-premises solution to a managed server to deploy apps. Moving apps to the cloud saves both money and time. Now, with serverless computing, developers no longer need to manage servers. All you need to do is push your code in a serverless platform and it runs on the events that you want, or you can run them directly with REST APIs. With this approach, you can quickly bring your code into production. You have more time to spend on programming your application, and after your app is done, you don’t need to worry putting it in the cloud, or managing a server for your app.
Compared to other cloud computing solutions, a serverless approach not only saves time. It also saves costs of provisioning and running a server on the cloud. Your code is run only when your app is in use, and you are not charged for idle time. You only pay for the resources you use when the code runs. A serverless platform is beneficial for startups that expect a low user base on early stages of their apps, and for all developers who are working to meet their customers’ needs.
This code pattern demonstrates one of the many use cases of serverless computing with an example of a stock market application. The code uses a time-based schedule to run the serverless functions. Serverless cron jobs (using the cron software utility) are useful for processing data at rest (for example, data in a Cloudant database). The application stores the stocks that your application users choose to follow in the database. A serverless function is configured to run every day at a specific time (although the users can change it.) One serverless function calls an external API to get market prices of the stocks and news about the stocks that the users followed. It notifies the users of the changes on the market prices on the stocks with the option to choose a threshold. The users are notified through Slack or an SMS that uses the Twilio API. This code pattern also uses Watson Natural Language Understanding to gain sentiments and emotions on the news articles about the stocks the users follow.
You can try working with this code pattern and see how you might implement your own cron jobs using serverless functions.
The application demonstrates IBM Cloud Functions (based on Apache OpenWhisk) with cron jobs with data at rest in a Cloudant database. The use case demonstrates how actions work with data services and execute logic at specific times in the cron job configuration.
One function, or action, is triggered by an event (in this use case, cron triggers). This action gets data from the database and gets the news and stock market data of the companies from an external API (the IEX API). The action invokes two more functions. One function passes the news to Watson Natural Language Understanding to get its sentiments and emotions found in the article. The other function notifies the user of the app about the recent change of price in either SMS (Twilio) , Slack, or both.
When you use this code pattern, you learn the following skills:
Find detailed technical steps for this code pattern in the README.md file in the GitHub repository.
October 4, 2019
This tutorial shows how to build and test cloud functions that connect devices and applications to your blockchain.
September 14, 2019
Back to top