-
Notifications
You must be signed in to change notification settings - Fork 12
/
gruntfile.js
146 lines (135 loc) · 4.39 KB
/
gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var grunt = require('grunt')
, fs = require('fs')
, path = require('path')
var actionheroRoot = function(){
var rv
if(fs.existsSync(__dirname + '/actionhero.js')){
// in the actionhero project itself
rv = __dirname
} else if(fs.existsSync(__dirname + '/../actionhero.js')){
// running from /grunt in the actionhero project itself
rv = __dirname + '/../'
} else if(fs.existsSync(__dirname + '/node_modules/actionhero/actionhero.js')){
// running from a project's node_modules (bin or actionhero)
rv = __dirname + '/node_modules/actionhero'
} else {
// installed globally
rv = path.normalize(__dirname)
}
return rv
}
var init = function(fn, configChanges){
var root = actionheroRoot()
, ActionHeroPrototype = require(root + '/actionhero.js').actionheroPrototype
, actionhero = new ActionHeroPrototype()
if(configChanges == null){
configChanges = {
logger: {
transports: null
}
}
}
actionhero.initialize({configChanges: configChanges}, function(err, api){
fn(api, actionhero)
})
}
grunt.registerTask('list','List your actions and metadata',function(){
var done = this.async()
init(function(api){
for(var actionName in api.actions.actions){
grunt.log.writeln(actionName)
var collection = api.actions.actions[actionName]
for(var version in collection){
var action = collection[version];
grunt.log.writeln(' ' + 'version: ' + version)
grunt.log.writeln(' ' + action.description)
grunt.log.writeln(' ' + 'required inputs: ' + action.inputs.required.join(', '))
grunt.log.writeln(' ' + 'optional inputs: ' + action.inputs.optional.join(', '))
}
}
done()
})
})
grunt.registerTask('enqueueAllPeriodicTasks','This will enqueue all periodic tasks (could lead to duplicates)',function(){
var done = this.async()
init(function(api){
api.resque.startQueue(function(){
api.tasks.enqueueAllRecurrentJobs(function(loadedTasks){
grunt.log.writeln('loaded tasks: ' + loadedTasks.join(', '))
done()
})
})
})
})
grunt.registerTask('enqueuePeriodicTask','Enqueue a periodic task (:taskName)',function(taskName){
var done = this.async()
init(function(api){
if(!api.tasks.tasks[taskName]) throw new Error('Task not found')
api.resque.startQueue(function(){
// enqueue to run ASAP
api.tasks.enqueue(taskName, function(err, toRun){
if(err) throw err
if(toRun === true){
grunt.log.writeln('loaded task: ' + taskName)
}else{
grunt.log.writeln(taskName + ' not enqueued')
}
done()
})
})
})
})
grunt.registerTask('stopPeriodicTask','Remove an enqueued periodic task (:taskName)',function(taskName){
var done = this.async()
init(function(api){
if(!api.tasks.tasks[taskName]) throw new Error('Task not found')
api.resque.startQueue(function(){
api.tasks.stopRecurrentJob(taskName, function(error, count){
grunt.log.writeln('removed ' + count + ' instances of ' + taskName)
done()
})
})
})
})
grunt.registerTask('flushRedis','Clear the entire actionhero redis database',function(){
var done = this.async()
init(function(api){
api.redis.client.flushdb(function(err){
if(err) throw err
grunt.log.writeln('flushed')
done()
})
})
})
grunt.registerTask('clearCache','Clear the actionhero cache',function(){
var done = this.async()
init(function(api){
api.cache.clear(function(error, count){
if(error) throw error
grunt.log.writeln('cleared ' + count + ' items from the cache');
done()
})
})
})
grunt.registerTask('dumpCache','Save the current cache as a JSON object (:file)',function(file){
var done = this.async()
init(function(api){
if(undefined === file){ file = 'cache.dump' }
api.cache.dumpWrite(file, function(error, count){
if(error) throw error
grunt.log.writeln('dumped ' + count + ' items from the cache to ' + file);
done()
})
})
})
grunt.registerTask('loadCache','Set the cache from a file (overwrites existing cache) (:file)',function(file){
var done = this.async()
init(function(api){
if(file == null){ file = 'cache.dump' }
api.cache.dumpRead(file, function(error, count){
if(error) throw error
grunt.log.writeln('cleared the cache and then loaded ' + count + ' items from ' + file);
done()
})
})
})