Cron Generation

Executes scheduled functions

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

Name
Type
Required
Description

request

object

The tool generated in System Analysis

host

string

The data example or parameters for your function to work

api_key

string

the endpoint for the graphql api to run

api_secret

string

The error list for the code to catch

schedule

string

The cron request

Prompt Example

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"

Response Object

Name
Type
Description

code

array

The generated code

Result Example

{ "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});" }

Last updated

Was this helpful?