Skip to content

Commit

Permalink
scheduler time logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordnibbler committed Aug 5, 2015
1 parent 661c0fb commit 897011d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
30 changes: 18 additions & 12 deletions bin/scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

request = require 'request'
config = require 'config'
moment = require 'moment'
logger = require '../src/logger'

# ugly munging to build fully qualified prod/dev API URL
Expand All @@ -13,19 +14,24 @@ else

off_url = "http://#{domain}/api/v1/scheduler/off"
on_url = "http://#{domain}/api/v1/scheduler/on"
logger.info 'off_url: ', off_url
logger.info 'on_url: ', on_url

# request to turn off LEDs
# request off_url, (error, response, body) ->
# logger.info 'response: ', response.body
# if response.statusCode == 200
# logger.info 'turned LEDs off'
# process.exit
turn_off = ->
request off_url, (error, response, body) ->
logger.info 'response: ', response.body
if response.statusCode == 200
logger.info 'turned LEDs off'
process.exit

# request to turn on LEDs
request on_url, (error, response, body) ->
logger.info 'response: ', response.body
if response.statusCode == 200
logger.info 'turned LEDs on'
process.exit
turn_on = ->
request on_url, (error, response, body) ->
logger.info 'response: ', response.body
if response.statusCode == 200
logger.info 'turned LEDs on'
process.exit

now = moment()
logger.info "now.hour(): #{now.hour()}"
turn_off() if now.hour() == 1 # 1am
turn_on() if now.hour() == 18 # 6pm
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"grunt-contrib-watch": "~0.5.2",
"grunt-contrib-imagemin": "~0.9.0",
"suncalc": "~1.6.0",
"request": "*"
"request": "*",
"moment": "~2.10",
"moment-timezone": "~0.4"
},
"devDependencies": {
"mocha": "*",
Expand Down
13 changes: 0 additions & 13 deletions src/scheduler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ Redis = require './redis'
# @note this might be better named Manager, as scheduler pertains to the Heroku worker
# scheduled task
class Scheduler
# scheduler job entrypoint, which checks if sunset or sunrise
# and accordingly turns the lights on or off
# @run: ->
# @off()
# return if @_check_sunrise()
# return if @_check_sunset()

# @_check_sunset: ->

# emits solid black over all connected beagle sockets
@off: (sockets) ->
# console.log 'scheduler off'
Expand Down Expand Up @@ -59,8 +50,4 @@ class Scheduler
b = bigint & 255
return { r: r , g: g, b: b }


module.exports = Scheduler

# if process.ENV['scheduler'] == 'true'
# Scheduler.run()

0 comments on commit 897011d

Please sign in to comment.