# Cron Generation

## Overview

The function transforms the schedule into node\_cron files, ensuring that all tasks are scheduled accurately. It then performs an axios request to schedule the functions. This axios request is crucial in triggering the agents, who carry out their tasks as expected according to the predefined schedule.

Node\_cron files are integral in setting up the timing for these functions, making sure they run at the right moments. The axios request plays a pivotal role in this process as it communicates with the scheduler to activate the agent's functions accordingly.

In summary, the entire procedure ensures that the scheduled tasks are converted into node\_cron files and the axios request mobilizes the agents, ensuring the process flows seamlessly and as planned.

## Parameters

<table><thead><tr><th width="219">Name</th><th width="101">Type</th><th width="103" data-type="checkbox">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>request</code></td><td>object</td><td>true</td><td>The tool generated in <code>System Analysis</code></td></tr><tr><td><code>host</code></td><td>string</td><td>true</td><td>The data example or parameters for your function to work</td></tr><tr><td><code>api_key</code></td><td>string</td><td>true</td><td>the endpoint for the graphql api to run</td></tr><tr><td><code>api_secret</code></td><td>string</td><td>true</td><td>The error list for the code to catch</td></tr><tr><td><code>schedule</code></td><td>string</td><td>true</td><td>The cron request</td></tr></tbody></table>

## Prompt Example

{% code overflow="wrap" lineNumbers="true" %}

```javascript
request = { "type": "function", "name": "create_post", "description": "creates a new post in the posts collection and returns the id", "return": "post_id", "params": ["title", "content"] }
host= "my_app.uncodie.com"
api_key= "ASFD29E9FVASF92AOIJFVNAPI22FASF"
api_secret= "AS9DSFI9IFJAOIJVNAPOEJO232UFASÑLV"
schedule="All fridays at 10pm"
```

{% endcode %}

## Response Object

<table><thead><tr><th width="242">Name</th><th width="101">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>code</code></td><td>array</td><td>The generated code</td></tr></tbody></table>

## Result Example

{% code overflow="wrap" lineNumbers="true" %}

```json
{ "request": "All fridays at 10pm", "code": "const cron = require('node-cron');\nconst axios = require('axios');\nconst base64 = require('base-64');\n\n// Function to encode API credentials\nconst encodeCredentials = (key, secret) => {\n const credentials = ${key}:${secret};\n return base64.encode(credentials);\n};\n\n// Creating the cron job\ncron.schedule('0 22 * * 5', async () => {\n try {\n // API URL\n const functionPath = '/create_post';\n const apiUrl = https://my_app.uncodie.com${functionPath};\n\n // API credentials\n const apiKey = 'ASFD29E9FVASF92AOIJFVNAPI22FASF';\n const apiSecret = 'AS9DSFI9IFJAOIJVNAPOEJO232UFASÑLV';\n const encodedCredentials = encodeCredentials(apiKey, apiSecret);\n\n // Prepare headers\n const headers = {\n 'Authorization': Basic ${encodedCredentials},\n 'Content-Type': 'application/json'\n };\n\n // Dummy data for post\n const data = {\n 'title': 'Scheduled Post Title',\n 'content': 'This is the content of the scheduled post.'\n };\n\n // Make the HTTP request\n const response = await axios.post(apiUrl, data, { headers });\n\n console.log(Post created with ID: ${response.data.post_id});\n } catch (error) {\n console.error(Error creating post: ${error.message});\n }\n});" }
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uncodie.com/1.0/agentbase/code-generation/agents/cron-generation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
