diff --git a/docs/features/cron-jobs.md b/docs/features/cron-jobs.md new file mode 100644 index 0000000..c4af358 --- /dev/null +++ b/docs/features/cron-jobs.md @@ -0,0 +1,71 @@ +--- +description: A scheduled method or a cron job is a function that will run periodically. By using a specific syntax, you can define the frequency and timing for each method. +--- + +# Crons + + + Crons | Genezio Documentation + + +A scheduled method or a cron job is a function that will run periodically. By using a specific cron syntax, you can define the frequency and timing for each method. You can use Genezio functions to define cron jobs in your project. + +## Create a cron job + +To create a cron job, you will need a function that will run periodically. You can define the function in your code and then add the cron job in the configuration file. To learn more about Genezio functions, check the [functions documentation](../tutorials/how-to-deploy-a-serverless-function.md). + +```yaml title="genezio.yaml" +name: cron-getting-started +region: us-east-1 +yamlVersion: 2 +backend: + path: ./ + language: + name: js + packageManager: npm + functions: + - name: my-function + path: ./ + handler: handler + entry: app.mjs +services: + crons: + - name: my-cron + function: ${{backend.functions.my-function.name}} + schedule: "* * * * *" + endpoint: "/my-cron" +``` + +This configuration file specifies the project name, deployment region, and details about the backend. It also specifies the cron job name, the name of function that will called, the schedule, and the endpoint. In this example, the cron job will run every minute and will call the url provided by your backend function at the specifed endpoint. The `endpoint` field is optional, if it is not provided, the cron job will call the base url of your function. + +If you want to learn more about cron strings and how to define a valid schedule, check https://crontab.guru/. + +:::info +You can also specify the function name manually like so: + +```yaml title="genezio.yaml" +services: + crons: + - name: my-cron + function: my-function + schedule: "* * * * *" + endpoint: "/my-cron" +``` + +::: + +## Testing + +### Local + +To test your crons locally you can simply run `genezio local` and check the terminal logs to see if the cron job is being executed. + +### Remote + +:::warning +Deploying your project will **sync** the state of the crons with what is in the `genezio.yaml` file. This means that if you delete a cron job from the file and deploy the project, it will be deleted from the cloud as well. Before deploying, make sure that the state provided in the `genezio.yaml` file is your desired output state after deployment. +::: + +Simply run `genezio deploy` to deploy your project. + +To test if your cron job was succesfully created, you can check the logs of the function that the cron job is calling to see if it is being executed. diff --git a/docs/frameworks/django.md b/docs/frameworks/django.md index dad275f..6e32a5d 100644 --- a/docs/frameworks/django.md +++ b/docs/frameworks/django.md @@ -15,7 +15,7 @@ Django is a popular Python web application framework that simplifies the develop provides a robust set of features for building web servers and APIs. :::tip -Get started in no time with the [Django template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/django-getting-started)) +Get started in no time with the [Django template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/django-getting-started) ::: # Deployment diff --git a/docs/frameworks/fastapi.md b/docs/frameworks/fastapi.md index 0488d29..2db59ea 100644 --- a/docs/frameworks/fastapi.md +++ b/docs/frameworks/fastapi.md @@ -14,7 +14,7 @@ import TabItem from '@theme/TabItem'; FastAPI is a modern Python web application framework that simplifies the development of server-side applications. It provides a robust set of features for building web servers and APIs. :::tip -Get started in no time with the [FastAPI template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/fastapi-getting-started)). +Get started in no time with the [FastAPI template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/fastapi-getting-started). ::: # Deployment diff --git a/docs/frameworks/flask.md b/docs/frameworks/flask.md index 9ac14bc..1ff34bc 100644 --- a/docs/frameworks/flask.md +++ b/docs/frameworks/flask.md @@ -15,7 +15,7 @@ Flask is a popular Python web application framework that simplifies the developm provides a robust set of features for building web servers and APIs. :::tip -Get started in no time with the [Flask template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/flask-getting-started)). +Get started in no time with the [Flask template](https://app.genez.io/start/deploy?repository=https://github.com/Genez-io/flask-getting-started). ::: # Deployment diff --git a/docs/genezio-typesafe/cron-methods.md b/docs/genezio-typesafe/cron-methods.md index e52c506..c1ab731 100644 --- a/docs/genezio-typesafe/cron-methods.md +++ b/docs/genezio-typesafe/cron-methods.md @@ -18,7 +18,7 @@ The time specified in the cron strings is in UTC. You can use this [converter](h ## Use scheduled methods in your project -There are two ways to declare a scheduled method: +There are two ways to declare a scheduled method in a Genezio typsafe project: - Using decorators (only available for TypeScript, JavaScript and Go projects) - Using the `genezio.yaml` configuration file (available for all supported languages, including TypeScript, JavaScript, Go) diff --git a/sidebars.js b/sidebars.js index c63034c..bbe2fd5 100644 --- a/sidebars.js +++ b/sidebars.js @@ -25,9 +25,9 @@ const sidebars = { link: { type: "doc", id: "getting-started/README" }, items: [ "getting-started/use-a-template", - "getting-started/import-existing-project" + "getting-started/import-existing-project", ], - collapsed: false + collapsed: false, }, { type: "category", @@ -48,7 +48,7 @@ const sidebars = { "frameworks/refine", "frameworks/svelte", "frameworks/typesafe-project", - "frameworks/vue" + "frameworks/vue", ], }, { @@ -68,31 +68,30 @@ const sidebars = { label: "Create your first Web3 App", // The link label href: "https://genezio.com/blog/create-your-first-web3-app/", // The external URL description: - "In this tutorial, you will learn how to create your first Web3 application on Ethereum using genezio and Blast API. You don’t have to know anything beforehand to follow along. I will introduce you to the most basic blockchain concepts and tools to get you from zero to hero in Web3 development. Excited? Let’s get started 🤩" + "In this tutorial, you will learn how to create your first Web3 application on Ethereum using genezio and Blast API. You don’t have to know anything beforehand to follow along. I will introduce you to the most basic blockchain concepts and tools to get you from zero to hero in Web3 development. Excited? Let’s get started 🤩", }, { type: "link", label: "Create your first Chat GPT App", // The link label href: "https://genezio.com/blog/create-your-first-app-using-chatgpt/", // The external URL description: - "In this tutorial, you will learn how to create an app called the Rephrasing App. The app that you are going to build has a simple UI written in React, uses the ChatGPT API and is deployed on genezio." + "In this tutorial, you will learn how to create an app called the Rephrasing App. The app that you are going to build has a simple UI written in React, uses the ChatGPT API and is deployed on genezio.", }, { type: "link", label: "Implement a Shopping Cart", // The link label - href: - "https://genezio.com/blog/implement-a-shopping-cart-using-typescript-redis-and-react/", // The external URL + href: "https://genezio.com/blog/implement-a-shopping-cart-using-typescript-redis-and-react/", // The external URL description: - "In this tutorial, you will learn how to use Redis, NodeJs, and React to easily implement a shopping cart for your online store." + "In this tutorial, you will learn how to use Redis, NodeJs, and React to easily implement a shopping cart for your online store.", }, { type: "link", label: "Integrate Stripe Payments", // The link label href: "https://genezio.com/blog/integrate-stripe-payments/", // The external URL description: - "This guide will walk you through integrating Stripe payments using a genezio backend and a React frontend." - } - ] + "This guide will walk you through integrating Stripe payments using a genezio backend and a React frontend.", + }, + ], }, { type: "category", @@ -102,7 +101,7 @@ const sidebars = { "deploy/backend", "deploy/frontend", "deploy/serverless-containers", - ] + ], }, { type: "category", @@ -111,14 +110,15 @@ const sidebars = { items: [ "features/databases", "features/authentication", + "features/cron-jobs", "features/testing", "features/deployment-environments", "features/email-service", "features/custom-domain-configuration", "features/project-collaboration", "features/check-genezio-dashboard", - "features/genezio-deploy-button" - ] + "features/genezio-deploy-button", + ], }, { type: "category", @@ -132,8 +132,8 @@ const sidebars = { "genezio-typesafe/cron-methods", "genezio-typesafe/genezio-decorators", "genezio-typesafe/project-template", - "genezio-typesafe/genezio-context" - ] + "genezio-typesafe/genezio-context", + ], }, { type: "category", @@ -142,8 +142,8 @@ const sidebars = { items: [ "project-structure/genezio-configuration-file", "project-structure/.genezioignore", - "project-structure/backend-environment-variables" - ] + "project-structure/backend-environment-variables", + ], }, { type: "category", @@ -170,12 +170,12 @@ const sidebars = { "cli-tool/cli-commands/delete", "cli-tool/cli-commands/login", "cli-tool/cli-commands/account", - "cli-tool/cli-commands/logout" - ] + "cli-tool/cli-commands/logout", + ], }, "cli-tool/install", "cli-tool/update", - ] + ], }, { type: "category", @@ -185,8 +185,8 @@ const sidebars = { "integrations/github-action", "integrations/upstash-redis", "integrations/neon-postgres", - "integrations/upstash-qstash" - ] + "integrations/upstash-qstash", + ], }, { type: "category", @@ -207,8 +207,8 @@ const sidebars = { "examples/typescript/trivia-application", "examples/typescript/crud-application", "examples/typescript/shopping-cart", - "examples/typescript/webhook-example" - ] + "examples/typescript/webhook-example", + ], }, { type: "category", @@ -225,24 +225,24 @@ const sidebars = { "examples/javascript/blockchain-app", "examples/javascript/chatgpt-project", "examples/javascript/stripe-integration", - "examples/javascript/html-example" - ] - } - ] + "examples/javascript/html-example", + ], + }, + ], }, { type: "category", label: "Learn more", link: { type: "doc", id: "learn-more/README" }, - items: ["learn-more/upgrading-to-v1", "learn-more/supported-languages"] + items: ["learn-more/upgrading-to-v1", "learn-more/supported-languages"], }, "troubleshooting", { type: "link", label: "Release Notes", // The link label - href: "https://github.com/Genez-io/genezio/releases" // The external URL - } - ] + href: "https://github.com/Genez-io/genezio/releases", // The external URL + }, + ], }; export default sidebars;