npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-plugin-tasks

v0.0.36

Published

An interface for configuring scheduled tasks in Strapi.

Downloads

52

Readme

Strapi Plugin - Tasks

Installation

npm install strapi-plugin-tasks
yarn add strapi-plugin-tasks

Example

Code

To register an "exampleTask" task, you need to register the task's code.

First, import the CronTasks type from the strapi-plugin-tasks package and extended the Strapi interface definition:

// ./src/index.ts

import { Strapi } from '@strapi/strapi'
import { CronTasks } from 'strapi-plugin-tasks/server/models'

declare module '@strapi/strapi' {
    interface Strapi {
        tasks: CronTasks
    }
}

Next, you need to register your tasks in the exported Strapi register function:

// ./src/index.ts

register({ strapi }: { strapi: Strapi }) {
    strapi.tasks = {

        // the "key" (eg. "exampleTask") needs to match the name
        // property of the targeted task in the Strapi Content Manager.
        "exampleTask": async () => {

            // Enter example task code here.
            console.log('"exampleTask" task executed!')

            return
        }
    }
}

The complete file would then look like this:

// ./src/index.ts

import { Strapi } from '@strapi/strapi'
import { CronTasks } from 'strapi-plugin-tasks/server/models'

declare module '@strapi/strapi' {
    interface Strapi {
        tasks: CronTasks
    }
}

export default {
    /**
    * An asynchronous register function that runs before
    * your application is initialized.
    *
    * This gives you an opportunity to extend code.
    */
    register({ strapi }: { strapi: Strapi }) {
        strapi.tasks = {

            // the [key] (eg. "exampleTask") needs to match the name property of the targeted task in the Strapi Content Types plugin.
            "exampleTask": async () => {

                // Enter example task code here.
                console.log('"exampleTask" task executed!')
                
                return
            }
        }
    },

    /**
    * An asynchronous bootstrap function that runs before
    * your application gets started.
    *
    * This gives you an opportunity to set up your data model,
    * run jobs, or perform some special logic.
    */
    async bootstrap({ strapi }: { strapi: Strapi }) {},
}

Strapi CMS

Lastly, you need to create a Task in the Strapi CMS.

First, launch your Strapi project in develop mode:

npm start develop
yarn develop

Next, navigate to the Strapi Content Manager and select the Task collection type. Create a new entry, enter the required fields and ensure that the:

  • name property is set to the task "key" (eg. "exampleTask") defined in the strapi.tasks object registerd in the Strapi register function.
  • executeStart property is set to a date in the past.
  • executionPeriod is set to the desired frequency unit.
  • executionFrequency is set to the desired frequency with the executionPeriod property value in mind.
  • executeFrom and executeTo property values are set to a time range within which you wish the task to execute.
  • enabled property is set to true.

Finally, navigate to the Tasks Settings in Strapi Settings and ensure that the tasks engine is enabled.

Execution

Once the configuration steps have been followed above the below should be logged to your Strapi applications console when the task successfully executes:

"exampleTask" task executed!