Working with Cron Functions

Build a web news application that automatically fetches news from a third-party service periodically using Catalyst Cron, a Cron Function, and an Advanced I/O Function.

Test the Application

Before you deploy the application to the remote console, you can test the application on a local server and check if everything works fine using the Catalyst CLI.

We will first test the cron function using the functions shell in the CLI, and then serve the Advanced I/O function and the client locally to test the frontend of the application.

To open the functions shell in your CLI, execute the following command from your project directory (CATALYST_PROJECT_HOME):

$ catalyst functions:shell

This will open the functions shell for the cron function in the CLI where you can test its execution.

To invoke the function, enter NewsFetch() in the shell if you configured it in Java or newsapp() in the case of Node.js and press Enter. This will make the API call to NewsAPI and fetch the news items from each category, and populate them in the Data Store.

The CLI will display the status of the function execution. The CLI will display the status of the function execution. You can exit the functions shell by killing the terminal command based on your local environment.

Now, let's host the client component locally and check the frontend of the application.

To serve the Catalyst project locally, execute the following command from your project directory (CATALYST_PROJECT_HOME):

$ catalyst serve

The news application will now be served at default port 3000. The local endpoint URLs of the components are displayed.

Note: Every time you access the homepage or any of the sub-pages of your client or the function, the CLI will display a live log of the URL accessed, along with the HTTP request method.

You can now open the application in a browser using the local URL of the client displayed in the CLI.

The news application displays the general news headlines in the index page. You can click a topic on the left to check the latest headlines in that category. You can open the original news article by clicking on a headline.

You can also open your Catalyst console to check the data populated in the tables in the Data Store. Click on a table's name in the Data Store, and click Data View to check the records.

If this setup is working correctly, we can deploy the application to production.

You can quit the serve command session in your terminal by pressing Ctrl+C keys twice.