Tutorial: Create a daily job with a Cron handler
Now that we're storing requests, we can use a scheduled job (a "Cron", named
after the Unix cron utility) to create a report of all requests per day.
- Hit the plus (
+) button (or use the omnibox) to create a new Cron. Set it to run daily, and with the nameDailyReport.

-
To know if a request was executed today, we compare it to the current time. Let's assign the current time in seconds to a variable
timeSeconds. The current time in seconds isDate::now, piped intoDate::toSeconds. (Note: to create a pipe, type|>after theDate::nowfunction).Run the
Date::nowfunction to see a live value for your code.

- Next, we'll need to filter the reports to just today's reports. Set
allRequeststoDB::getAll Requests. Run the function to the live value forallRequests.

- To see only today's requests, use
List::filter.List::filtertakes two arguments - the list to filter (in this caseallRequests) and an anonymous function that determines if each element of the list element should be includes in the new list.List::filteris similar toList::mapand the concept is explained in more detail here.

- We want to keep only reports that occurred today, meaning we want to compare
the report's time to
timeSecondsthat we created earlier. Let's convert the time of the request into seconds so that both times have the same units.

- Next, we calculate the difference from the current time; this tells us if it happened today (in the last 86,400 seconds).

- To see this work, it's helpful to have a recent request. If you paused in the
tutorial, re-run the
HttpClient::postfunction from the REPL. Then, when you place your cursor intodayRequestsorList::filteryou'll see a list of requests from the last 24 hours.

- Finally, let's emit today's requests to a background worker, using the
emitkeyword.emittakes two arguments, and in this case we're sendingtodayRequeststo a not-yet-created worker namedstoreReport.

- To have our first report run, hit the "replay" button in the upper right of
the Cron. This creates a 404 in the sidebar for the Worker
storeReport.