Skip to content

Commit

Permalink
Add cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
yulii committed Aug 14, 2017
1 parent 7ec5103 commit 74f4926
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
15 changes: 15 additions & 0 deletions bin/circleci
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

CIRCLE_API_URL="https://circleci.com/api/v1.1/project/${CIRCLE_VCS_TYPE:-github}/${CIRCLE_USERNAME:-yulii}/${CIRCLE_PROJECT}/tree/${CIRCLE_BRANCH:-master}?circle-token=${CIRCLE_TOKEN}"
CIRCLE_BUILD_PARAMETERS='{ "build_parameters": { "CIRCLE_JOB": "update", "JOB_USER": "'${JOB_USER:-sh}'" } }'

test -z \
"$(
curl -s -X POST \
-H "Content-Type: application/json" \
-d "${CIRCLE_BUILD_PARAMETERS}" \
"${CIRCLE_API_URL}" \
| jq -r 'select(.build_url == null)' \
)"
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"url": "https://github.com/github/hubot.git"
},
"dependencies": {
"child_process": "^1.0.2",
"cron": "^1.2.1",
"david": "^7.0.0",
"hubot": ">= 2.16.0 < 3.0.0",
"hubot-heroku-keepalive": "^1.0.2",
Expand Down
20 changes: 20 additions & 0 deletions scripts/cron.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cron = require('cron').CronJob
child_process = require 'child_process'

module.exports = (robot) ->

new cron '0 0 0 * * 1-7', () =>
child_process.exec "CIRCLE_PROJECT=yulii.github.io JOB_USER=hubot bin/circleci", (error, stdout, stderr) ->
if !error
robot.send { room: "#devops" }, "Kick yulii.github.io update"
else
robot.send "Error yulii.github.io update"
, null, true

new cron '0 0 0 * * 1-7', () =>
child_process.exec "CIRCLE_PROJECT=hubot-scripts JOB_USER=hubot bin/circleci", (error, stdout, stderr) ->
if !error
robot.send { room: "#devops" }, "Kick hubot-scripts update"
else
robot.send "Error hubot-scripts update"
, null, true
58 changes: 24 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ amdefine@>=0.0.4:
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"

ansi-regex@*:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-regex@^2.0.0, ansi-regex@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
Expand Down Expand Up @@ -261,6 +257,10 @@ chalk@^1.0.0, chalk@^1.1.1:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

child_process@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/child_process/-/child_process-1.0.2.tgz#b1f7e7fc73d25e7fd1d455adc94e143830182b5a"

chownr@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181"
Expand Down Expand Up @@ -509,6 +509,12 @@ crc@3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/crc/-/crc-3.3.0.tgz#fa622e1bc388bf257309082d6b65200ce67090ba"

cron@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/cron/-/cron-1.2.1.tgz#3a86c09b41b8f261ac863a7cc85ea4735857eab2"
dependencies:
moment-timezone "^0.5.x"

cryptiles@2.x.x:
version "2.0.5"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"
Expand Down Expand Up @@ -569,7 +575,7 @@ debug@2.6.8, debug@^2.2.0:
dependencies:
ms "2.0.0"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"

Expand Down Expand Up @@ -1102,7 +1108,7 @@ iferr@^0.1.5, iferr@~0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

Expand Down Expand Up @@ -1301,39 +1307,17 @@ lockfile@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/lockfile/-/lockfile-1.0.3.tgz#2638fc39a0331e9cac1a04b71799931c9c50df79"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
dependencies:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"

lodash._root@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
Expand All @@ -1342,10 +1326,6 @@ lodash.clonedeep@~4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

lodash.union@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88"
Expand Down Expand Up @@ -1496,6 +1476,16 @@ mocha@^2.3.3:
supports-color "1.2.0"
to-iso-string "0.0.2"

moment-timezone@^0.5.x:
version "0.5.13"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.13.tgz#99ce5c7d827262eb0f1f702044177f60745d7b90"
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0":
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

morgan@~1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.6.1.tgz#5fd818398c6819cba28a7cd6664f292fe1c0bbf2"
Expand Down Expand Up @@ -2009,7 +1999,7 @@ readable-stream@~2.1.5:
string_decoder "~0.10.x"
util-deprecate "~1.0.1"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
dependencies:
Expand Down Expand Up @@ -2516,7 +2506,7 @@ uuid@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

validate-npm-package-license@*, validate-npm-package-license@^3.0.1:
validate-npm-package-license@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
dependencies:
Expand Down

0 comments on commit 74f4926

Please sign in to comment.