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 🙏

© 2026 – Pkg Stats / Ryan Hefner

semo-plugin-cron

v2.0.1

Published

A Semo plugin to provide simple cron job.

Readme

semo-plugin-cron

A Semo plugin to provide simple cron job.

Usage

$ npm install semo-plugin-cron
$ semo generate cron
$ semo cron

You need to add related settigns for cron working in .semorc.yml

cronDir:
cronMakeDir:

You can implement hook_cron_redis to provide a redis lock and unlock, so you can run cron job in multiple instances.

// In your project Semo hook file: hooks/index


import { redis } from 'semo-plugin-redis'
const redisInstance = await redis.load('redisKey')

// Redis锁,加锁
const lock = async function(redisKey: string, redisValue: any, timeout: number) {
  return await redisInstance.eval(
    'return redis.call("set", KEYS[1], ARGV[1], "NX", "PX", ARGV[2])',
    1,
    redisKey,
    redisValue,
    timeout
  )
}

// Redis锁,解锁
const unlock = async function(redisKey: string, redisValue: any) {
  return await redisInstance.eval(
    'if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end',
    1,
    redisKey,
    redisValue
  )
}

const hook_cron_redis_lock = {
  'semo-plugin-cron': () => {
    return { lock, unlock }
  }
}

Sometimes, we use Semo cron with Semo scripts and Semo commands, so the main logic will be in scripts and commands not in cron job file, it's up to you to choose how to use Semo cron.

You can generate cron job template by Semo generators command:

semo generate cron YOUR_CRON_JOB_NAME

Then you can get code template like this, depends on whether you use typescript or not:

// Pure ES version
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

// 示例 Job Actions
const demoAction = async function demo() {
  console.log('Demo job action')
  await sleep(1000)
}

export const schedule = '* * * * * *'
export const duration = 1000
export const actions = [demoAction]
export const disabled = false

NOTE: Here actions is an array, so it means you can set multiple different purpose actions in one job, and the action can be a shell command, that is useful in some cases.

The format for shell command action should be in array style:

...
exports.actions = [['ls', '-l']]
...

Maybe you want to use string style shell command, it works only for simple command without string options with blanks.

...
exports.actions = [['ls -l']] // work
exports.actions = [['grep "a b c"']] // not work
...

License

MIT