Skip to content

Instantly share code, notes, and snippets.

@LeCoupa
Last active November 10, 2017 01:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeCoupa/056d9c930346294d844d to your computer and use it in GitHub Desktop.
Save LeCoupa/056d9c930346294d844d to your computer and use it in GitHub Desktop.
Meteor & Spooky Bootstrap --> https://github.com/LeCoupa/awesome-cheatsheets
# Meteor & Spooky Bootstrap. (Growth Hacking)
# You may also be interested by the PhantomJS, CasperJS & Spooky CheatSheet
# https://gist.github.com/LeCoupa/10008302
# Choose XPath over CSS3 selectors it's much more powerful and less buggy
# https://gist.github.com/LeCoupa/8c305ec8c713aad07b14
# Use Meteor-NPM to install these npm packages
# https://github.com/arunoda/meteor-npm/
Spooky = Meteor.npmRequire('spooky')
cronJob = Meteor.npmRequire('cron').CronJob
# Server >> Spooky > Data
@processNameData = { username: 'LeCoupa', password: 'gentlenode' }
# Server >> Spooky > Actions
@runFirstAction = ->
processName.then ->
# CasperJS environment
@runSecondAction = ->
processName.then ->
# CasperJS environment
processName.then ->
# CasperJS environment
@emit 'specificEventListener', @evaluate ->
# PhantomJS environment
# Server >> Spooky > Event Listeners > Specifics
@processNameSpecificEventListener = (val) ->
# do your thing (NodeJS environment)
# Server >> Spooky > Event Listeners > Debugging
@processNameRemoteMessage = (line) ->
console.log 'ProcessName: [PhantomJS] ' + line
@processNameConsole = (line) ->
console.log 'ProcessName: ' + line
@processNameError = (e, stack) ->
console.error 'ProcessName: ' + e
@processNameDie = (e, stack) ->
console.error 'ProcessName: ' + e
console.log 'ProcessName: The process just die'
processNameDestroyProcess()
@processNameStarted = ->
console.log 'ProcessName: The process is starting'
@processNameCompleted = ->
console.log 'ProcessName: The process is now over'
processNameDestroyProcess()
# Server >> Spooky > Helpers
@processNameDestroyProcess = ->
processName.destroy()
processName.removeAllListeners()
console.log 'ProcessName: Spooky has been destroyed'
# Server >> Spooky > Build Processes
@buildProcessName = (err) ->
if err
e = new Error 'Failed to initialize SpookyJS'
e.details = err
throw e
# 1. Debugging & Specific Event Listeners
processName.on 'remote.message', processNameRemoteMessage
processName.on 'console', processNameConsole
processName.on 'error', processNameError
processName.on 'die', processNameDie
processName.on 'run.start', processNameStarted
processName.on 'run.complete', processNameCompleted
# you can skip Meteor.bindEnvironment if you do not need to access the database
# or to run things that require to be inside the Meteor environment.
processName.on 'specificEventListener', Meteor.bindEnvironment processNameSpecificEventListener
# 2. Initialization
processName.start()
# 3. Actions
runFirstAction()
runSecondAction()
# 4. Time to run the process
processName.run()
# Server >> Spooky > Run Processes
@runProcessName = ->
@processName = new Spooky
child:
'ssl-protocol': 'any'
'proxy': '192.128.101.42:9001',
'proxy-auth': 'username:password'
casper:
logLevel: 'debug' # can also be set 'info', 'warning' and 'error'
verbose: true
exitOnError: false
pageSettings:
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)
AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/34.0.1847.137 Safari/537.36'
, Meteor.bindEnvironment buildProcessName
# Server >> Spooky > Cron Jobs
if process.env.METEOR_ENV is 'production'
Meteor.startup ->
new cronJob '00 */1 * * * *',
( Meteor.bindEnvironment runProcessName ),
null , true, 'Europe/Paris'
# For one time running (debugging and testing purpose)
# Comment the lines above and uncomment the ones below:
# Meteor.startup ->
# runProcessName()
@frozeman
Copy link

If i execute your script i get

W20141119-11:19:38.506(1)? (STDERR)
W20141119-11:19:38.509(1)? (STDERR) events.js:72
W20141119-11:19:38.509(1)? (STDERR)         throw er; // Unhandled 'error' event
W20141119-11:19:38.510(1)? (STDERR)               ^
W20141119-11:19:38.510(1)? (STDERR) Error: spawn ENOENT
W20141119-11:19:38.510(1)? (STDERR)     at errnoException (child_process.js:1000:11)
W20141119-11:19:38.510(1)? (STDERR)     at Process.ChildProcess._handle.onexit (child_process.js:791:34)

with meteor 1.0

@LeCoupa
Copy link
Author

LeCoupa commented Dec 6, 2014

I just used it with Meteor 1.0. Send me an email (gentlenode.com) if you still need help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment