{"id":17685632,"url":"https://github.com/ghaiklor/sails-hook-cron","last_synced_at":"2025-04-07T06:10:38.249Z","repository":{"id":36354135,"uuid":"40658910","full_name":"ghaiklor/sails-hook-cron","owner":"ghaiklor","description":"Sails hook for running cron tasks","archived":false,"fork":false,"pushed_at":"2024-09-21T12:00:08.000Z","size":925,"stargazers_count":89,"open_issues_count":1,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-30T21:15:58.916Z","etag":null,"topics":["cron","cron-tasks","hook","sails","sails-hook","sails-hook-cron"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghaiklor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-13T12:59:50.000Z","updated_at":"2024-07-05T08:45:13.000Z","dependencies_parsed_at":"2024-06-18T18:11:56.533Z","dependency_job_id":"6dc86444-8af0-4d51-a9e1-137a49c65e0c","html_url":"https://github.com/ghaiklor/sails-hook-cron","commit_stats":{"total_commits":320,"total_committers":9,"mean_commits":35.55555555555556,"dds":0.565625,"last_synced_commit":"8c8fc14e1e73987ba72a378b2262569f8e42dbfc"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghaiklor%2Fsails-hook-cron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghaiklor%2Fsails-hook-cron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghaiklor%2Fsails-hook-cron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghaiklor%2Fsails-hook-cron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghaiklor","download_url":"https://codeload.github.com/ghaiklor/sails-hook-cron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","cron-tasks","hook","sails","sails-hook","sails-hook-cron"],"created_at":"2024-10-24T10:28:30.013Z","updated_at":"2025-04-07T06:10:38.229Z","avatar_url":"https://github.com/ghaiklor.png","language":"JavaScript","funding_links":[],"categories":["Hooks"],"sub_categories":["Free"],"readme":"# sails-hook-cron\n\n![Build Status](https://img.shields.io/travis/ghaiklor/sails-hook-cron.svg)\n![Coverage](https://img.shields.io/coveralls/ghaiklor/sails-hook-cron.svg)\n![Downloads](https://img.shields.io/npm/dm/sails-hook-cron.svg)\n![Downloads](https://img.shields.io/npm/dt/sails-hook-cron.svg)\n![npm version](https://img.shields.io/npm/v/sails-hook-cron.svg)\n\n[![GitHub followers](https://img.shields.io/github/followers/ghaiklor.svg?label=Follow\u0026style=social)](https://github.com/ghaiklor)\n[![Twitter Follow](https://img.shields.io/twitter/follow/ghaiklor.svg?label=Follow\u0026style=social)](https://twitter.com/ghaiklor)\n\nSails hook for running cron tasks.\n\n## Getting Started\n\nInstall it via npm:\n\n```shell\nnpm install sails-hook-cron\n```\n\nConfigure `config/cron.js` in your project:\n\n```javascript\nmodule.exports.cron = {\n  myFirstJob: {\n    schedule: '* * * * * *',\n    onTick: function () {\n      console.log('You will see this every second');\n      console.log(`Also, sails object is available as this, e.g. ${this.config.environment}`);\n    }\n  }\n};\n```\n\n## Examples\n\nSchedule field syntax is:\n\n```javascript\n\n// ['seconds', 'minutes', 'hours', 'dayOfMonth', 'month', 'dayOfWeek']\n\nmodule.exports.cron = {\n  firstJob: {\n    schedule: '30 47 15 17 may *',\n    // in May 17 15:47:30 GMT-0300 (BRT)\n    onTick: function() {\n      console.log('I will trigger in May 17 15:47:30');\n    },\n    timezone: 'America/Sao_Paulo'\n    // timezone Brazil example\n  }\n};\n```\n\nYou can define cron tasks only with required fields:\n\n```javascript\nmodule.exports.cron = {\n  firstJob: {\n    schedule: '* * * * * *',\n    onTick: function() {\n      console.log('I am triggering every second');\n    }\n  },\n\n  secondJob: {\n    schedule: '*/5 * * * * *',\n    onTick: function() {\n      console.log('I am triggering every five seconds');\n    }\n  }\n};\n```\n\nYou can define advanced fields:\n\n```javascript\nmodule.exports.cron = {\n  myJob: {\n    schedule: '* * * * * *',\n    onTick: function() {\n      console.log('I am triggering when time is come');\n    },\n    onComplete: function() {\n      console.log('I am triggering when job is complete');\n    },\n    start: true, // Start task immediately\n    timezone: 'Ukraine/Kiev', // Custom timezone\n    context: undefined, // Custom context for onTick callback\n    runOnInit: true // Will fire your onTick function as soon as the request initialization has happened.\n  }\n};\n```\n\nYou can get created jobs and start\\stop them when you wish:\n\n```javascript\n// config/cron.js\nmodule.exports.cron = {\n  myJob: {\n    schedule: '* * * * * *',\n    onTick: function() {\n      console.log('I am triggering when time is come');\n    },\n    start: false\n  }\n};\n\n// api/controllers/SomeController.js\nmodule.exports = {\n  someAction: function(req, res) {\n    sails.hooks.cron.jobs.myJob.start();\n    sails.hooks.cron.jobs.myJob.stop();\n  }\n};\n```\n\n## Context\n\nThere are three states for the context, i.e. this on `onTick` call:\n\n- When you don’t declare context - `this` points to the Sails object.\n- If you declare it as a null (`context: null`), `this` points to the original context from the cron library.\n- Otherwise, if you declare a context with some object (`context: {foo: 'bar'}`), `this` will point to the object instead.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghaiklor%2Fsails-hook-cron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghaiklor%2Fsails-hook-cron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghaiklor%2Fsails-hook-cron/lists"}