├── .gitignore ├── Gruntfile.js ├── package.json ├── LICENSE ├── README.md └── tasks └── iron-worker.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | // Project configuration. 4 | grunt.initConfig({ 5 | pkg: grunt.file.readJSON('package.json'), 6 | watch: { 7 | files: '', 8 | tasks: 'default' 9 | }, 10 | 11 | jshint: { 12 | options: { 13 | curly: true, 14 | eqeqeq: true, 15 | immed: true, 16 | latedef: true, 17 | newcap: true, 18 | noarg: true, 19 | sub: true, 20 | undef: true, 21 | boss: true, 22 | eqnull: true, 23 | node: true, 24 | es5: true, 25 | globals: {} 26 | }, 27 | 28 | files: ['grunt.js', 'tasks/**/*.js'] 29 | } 30 | }); 31 | 32 | // Load local tasks. 33 | grunt.loadTasks('tasks'); 34 | grunt.loadNpmTasks('grunt-contrib-jshint'); 35 | 36 | // Default task. 37 | grunt.registerTask('default', 'jshint'); 38 | }; 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-iron-worker", 3 | "description": "Grunt plugin for managing Iron.io workers", 4 | "version": "0.0.5", 5 | "homepage": "https://github.com/ekryski/grunt-iron-worker", 6 | "author": { 7 | "name": "Eric Kryski", 8 | "url": "http://erickryski.com/" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git@github.com:ekryski/grunt-iron-worker.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/ekryski/grunt-iron-worker/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/ekryski/grunt-iron-worker/blob/master/LICENSE" 21 | } 22 | ], 23 | "main": "Gruntfile.js", 24 | "engines": { 25 | "node": ">= 0.8.0" 26 | }, 27 | "scripts": { 28 | "test": "grunt test" 29 | }, 30 | "devDependencies": { 31 | "grunt-contrib-jshint": "~0.2.0", 32 | "grunt": "~0.4.0" 33 | }, 34 | "peerDependencies": { 35 | "grunt": "~0.4.0" 36 | }, 37 | "keywords": [ 38 | "gruntplugin" 39 | ] 40 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Eric Kryski, contributors 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grunt-iron-worker 2 | 3 | A grunt plugin to manage your iron workers. It currently just uses the iron.io CLI. Therefore you need to `gem install iron_worker_ng`. For more details or troubleshooting refer to [http://dev.iron.io/worker/reference/cli/](http://dev.iron.io/worker/reference/cli/). 4 | 5 | ## Getting Started 6 | This plugin requires Grunt `~0.4.0` 7 | 8 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: 9 | 10 | ```shell 11 | npm install grunt-iron-worker --save-dev 12 | ``` 13 | 14 | Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: 15 | 16 | ```js 17 | grunt.loadNpmTasks('grunt-iron-worker'); 18 | ``` 19 | 20 | 21 | 22 | 23 | ## Iron Worker Task 24 | _Run this task with the `grunt ironworker` command._ 25 | 26 | Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. 27 | 28 | ### Options 29 | 30 | TODO: Fill this guy in 31 | 32 | ### Usage Examples 33 | 34 | ```js 35 | ironworker: { 36 | options: { 37 | worker: '<%= pkg.name %>.worker', 38 | payloadFile: 'config.json', 39 | payload: {}, 40 | projectId: 'xxxxxxx' 41 | environment: 'Production' 42 | }, 43 | run: {}, 44 | upload: { 45 | name: 'foo', // Override code name 46 | concurrency: 1, // Max number of concurrent users 47 | retries: 1, // Max number of auto retries on task fail 48 | retriesDelay: 1, // Delay between auto retry 49 | host: 'http://example.com', 50 | async: false, // Don't wait for package build 51 | fullRemoteBuild: false // Do a complete remote rebuild 52 | }, 53 | queue: { 54 | priority: 0, // 0|1|2 55 | timeout: 3600, // In seconds 56 | delay: 5, // In seconds 57 | }, 58 | schedule: { 59 | priority: 0, // 0|1|2 60 | timeout: 3600, // In seconds 61 | delay: 5, // In seconds 62 | start: new Date(), // ISO Date 2013-01-01T00:00:00-04:00 63 | end: new Date(), // ISO Date 2013-01-01T00:00:00-04:00 64 | runTimes: 0, // Run every n times 65 | runEvery: 0, // Run every n seconds 66 | } 67 | } 68 | ``` 69 | 70 | 71 | ## Release History 72 | 73 | * 2013-04-03   v0.0.1   First Version. Woo! -------------------------------------------------------------------------------- /tasks/iron-worker.js: -------------------------------------------------------------------------------- 1 | /* 2 | * grunt-iron-worker 3 | * 4 | * Copyright (c) 2013 Eric Kryski. 5 | * MIT Licensed 6 | */ 7 | 8 | 'use strict'; 9 | 10 | module.exports = function(grunt) { 11 | 12 | // TODO: Update the task to use node-ironio or ruby gem CLI 13 | var exec = require('child_process').exec; 14 | var path = require('path'); 15 | 16 | var optionsMapping = { 17 | payloadFile: '--payload-file', 18 | payload: '--payload', 19 | projectId: '--project-id', 20 | environment: '--env', 21 | name: '--name', 22 | concurrency: '--max-concurrency', 23 | retries: '--retries', 24 | retriesDelay: '--retries-delay', 25 | host: '--host', 26 | async: '--async', 27 | fullRemoteBuild: '--full-remote-build', 28 | priority: '--priority', 29 | timeout: '--timeout', 30 | delay: '--delay', 31 | start: '--start-at', 32 | workerConfig: '--worker-config', 33 | end: '--end-at', 34 | runTimes: '--run-times', 35 | runEvery: '--run-every' 36 | }; 37 | 38 | function generateOptionsString(target, options, data){ 39 | var string = []; 40 | var key; 41 | 42 | for (key in options){ 43 | // Skip payload and payload file options for upload targets 44 | if (target === 'upload' && (key === 'payloadFile' || key === 'payload')){ 45 | continue; 46 | } 47 | 48 | if (optionsMapping[key]) { 49 | string.push(optionsMapping[key]); 50 | } 51 | 52 | if (optionsMapping[key] || key === 'worker') { 53 | 54 | // Need to remove '.worker' extension for scheduling 55 | if (target === 'schedule' && key === 'worker'){ 56 | options[key] = options[key].split('.')[0]; 57 | } 58 | string.push(options[key]); 59 | } 60 | } 61 | 62 | for (key in data){ 63 | if (optionsMapping[key]) { 64 | if (data[key] || data[key] === 0){ 65 | string.push(optionsMapping[key]); 66 | } 67 | 68 | // async and full remote build are just flags, they have no values 69 | if (key !== 'async' && key !== 'fullRemoteBuild'){ 70 | 71 | // If it is a date convert it to ISO string format 72 | // and wrap in quotes. Like so "2013-04-03T20:00:00.000Z" 73 | if (key === 'start' || key === 'end'){ 74 | var date = new Date(data[key]); 75 | data[key] = '"' + date.toISOString() + '"'; 76 | } 77 | 78 | string.push(data[key]); 79 | } 80 | } 81 | } 82 | 83 | return string.join(' '); 84 | } 85 | 86 | grunt.registerMultiTask('ironworker', 'Grunt iron_worker interface', function() { 87 | // Merge task-specific and/or target-specific options with these defaults. 88 | var options = this.options({}); 89 | var callback = this.async(); 90 | 91 | var target = this.target; 92 | var data = this.data; 93 | 94 | if(this.args.length > 0){ 95 | target = this.args[0]; 96 | data = this.data[target]; 97 | } 98 | 99 | grunt.verbose.writeflags(options, 'Options'); 100 | 101 | var cmd = grunt.template.process(['iron_worker', target, generateOptionsString(target, options, data)].join(' ')); 102 | 103 | grunt.verbose.writeln('Command:', cmd.yellow); 104 | 105 | var worker = exec(cmd, function (err, stdout, stderr) { 106 | if (err) grunt.warn(err); 107 | 108 | callback(); 109 | }); 110 | 111 | worker.stdout.pipe(process.stdout); 112 | worker.stderr.pipe(process.stderr); 113 | }); 114 | }; 115 | --------------------------------------------------------------------------------