# Path: farmsList/imports.py
# def every_night_at_1am():
# 	print 'Starting the 1am job.'
# 	# Important to note that the order of the updates in the database matters
# 	# For example, the soil of the imported parcels is based on soil data already being present
# 	remoteDatasets = connection.execute("SELECT * FROM remote_datasets ORDER BY id")
# 	for dataset in remoteDatasets:
# 		name = dataset.name
# 		print 'Checking for update to dataset: ' + name
# 		responseHtml = urllib2.urlopen(dataset.url).read()
# 		parser, updater = getToolsForDataset(name)
# 		parser.feed(responseHtml)
# 		updateInstant = parser.updateInstant.strftime('%Y-%m-%d %H:%M:%S')
# 		print 'Last Updated Locally: ' + dataset.lastUpdatedLocally.strftime('%Y-%m-%d %H:%M:%S')
# 		print 'Last Updated Remotely: ' + updateInstant
# 		if parser.updateInstant > dataset.lastUpdatedLocally:
# 			print 'Updating dataset: ' + name
# 			updater.update()
# 			print 'Finished updating dataset: ' + name
# 			connection.execute("UPDATE remote_datasets SET \"lastUpdatedLocally\"='{}' WHERE id={}".format(updateInstant, dataset.id))
# 		else:
# 			print 'No update required for dataset: ' + name
# 	print 'Finished the 1am job.'


from apscheduler.schedulers.blocking import BlockingScheduler
from farmsList.imports import every_night_at_1am
from rq import Queue
from worker import conn
import logging

logging.basicConfig()
q = Queue(connection=conn)
sched = BlockingScheduler()

@sched.scheduled_job('cron', hour=8, minute=15)  # This is UTC and translates to 1:15 AM PDT (12:15 AM PST)

# Path: farmsList/imports.py
# def every_night_at_1am():
# 	print 'Starting the 1am job.'
# 	# Important to note that the order of the updates in the database matters
# 	# For example, the soil of the imported parcels is based on soil data already being present
# 	remoteDatasets = connection.execute("SELECT * FROM remote_datasets ORDER BY id")
# 	for dataset in remoteDatasets:
# 		name = dataset.name
# 		print 'Checking for update to dataset: ' + name
# 		responseHtml = urllib2.urlopen(dataset.url).read()
# 		parser, updater = getToolsForDataset(name)
# 		parser.feed(responseHtml)
# 		updateInstant = parser.updateInstant.strftime('%Y-%m-%d %H:%M:%S')
# 		print 'Last Updated Locally: ' + dataset.lastUpdatedLocally.strftime('%Y-%m-%d %H:%M:%S')
# 		print 'Last Updated Remotely: ' + updateInstant
# 		if parser.updateInstant > dataset.lastUpdatedLocally:
# 			print 'Updating dataset: ' + name
# 			updater.update()
# 			print 'Finished updating dataset: ' + name
# 			connection.execute("UPDATE remote_datasets SET \"lastUpdatedLocally\"='{}' WHERE id={}".format(updateInstant, dataset.id))
# 		else:
# 			print 'No update required for dataset: ' + name
# 	print 'Finished the 1am job.'


# Path: clock.py
from apscheduler.schedulers.blocking import BlockingScheduler
from farmsList.imports import every_night_at_1am
from rq import Queue
from worker import conn
import logging


logging.basicConfig()
q = Queue(connection=conn)
sched = BlockingScheduler()

@sched.scheduled_job('cron', hour=8, minute=15)  # This is UTC and translates to 1:15 AM PDT (12:15 AM PST)

def scheduled_job():