# Path: newsApp/feedManager.py
# class FeedManager(DbItemManagerV2):
#     """
#     Manage feeds stored on AWS dynamo db database.
# 
#     Contains functions for CRUD operations on the feeds stored
# 
#     Following environment variables need to be set -
#     'FEEDTAGSTABLE_CONNECTIONSTRING' : connection string of feed tags table.
#     """
# 
#     def __init__(self):
#         """
#         Instantiates the feedManager.
#         """
# 
#         DbItemManagerV2.__init__(self,
#             os.environ['FEEDTAGSTABLE_CONNECTIONSTRING'])
# 
#     def put(self, feed):
#         """
#         Put a new feed.
#         """
# 
#         # add polling info tags and put into database
#         feed.tags[FEEDTAG_NEXTPOLLTIME] = int(time.time())
#         if FEEDTAG_POLLFREQUENCY not in feed.tags:
#             feed.tags[FEEDTAG_POLLFREQUENCY] = DEFAULT_FEED_POLLING_FREQUENCY
#         DbItemManagerV2.put(self, feed)
# 
#     def getStaleFeeds(self):
#         """
#         Returns a list of feedIds of stale feeds (i.e whose next poll time
#         is less than current time.
#         """
# 
#         currentTime = int(time.time())
#         scanResults = DbItemManagerV2.scan(self, nextPollTime__lte = currentTime)
#         return (result.id for result in scanResults)
# 
#     def updateFeedOnSuccessfullPoll(self, feed):
#         """
#         Updates the polling related tags of specified feed and puts in db.
#         """
# 
#         feed.tags[FEEDTAG_LASTPOLLTIME] = int(time.time())
#         feed.tags[FEEDTAG_NEXTPOLLTIME] = (feed.tags[FEEDTAG_LASTPOLLTIME] +
#             feed.tags[FEEDTAG_POLLFREQUENCY]*60)
#         DbItemManagerV2.put(self, feed)
# 
# Path: newsApp/workerJob.py
# class WorkerJob:
#     """
#     Represents a job which can be processed by one of the worker roles.
#     """
# 
#     def __init__(self, jobName, jobParams, jobId = None):
#         """
#         Instantiates a new worker job object.
#         Requires 'jobName': a string representing name of the job
#         Requires 'jobParams': a dictionary where keys represnt job parameter
#             names, and corresponding values the job parameter values.
#         Optional 'jobId': a identier for this job. If not provided a
#             randomly generated alphanumeric string is used.
#         """
# 
#         if (jobId is None):
#             self.jobId = _generateRandomJobId()
#         else :
#             self.jobId = jobId
# 
#         self.jobName = jobName
#         self.jobParams = jobParams
# 
#     def deserializeFromString(self, serializedJob):
#         """
#         Sets this worker job object to the specified serialized string
#         representation.
#         """
# 
#         tempDict = json.loads(serializedJob)
#         jobName = tempDict.pop('jobName', None)
#         jobId = tempDict.pop('jobId', None)
#         self.__init__(jobName, tempDict, jobId)
# 
#     def serializeToString(self):
#         """
#         Serialize to a human-readable string representation of this object
#         """
# 
#         tempDict = dict(self.jobParams)
#         tempDict['jobName'] = self.jobName
#         tempDict['jobId'] = self.jobId
#         return json.dumps(tempDict)
# 
# Path: newsApp/minerJobManager.py
# class MinerJobManager(JobManager):
#     """
#     Helper class to enqueue and dequeue jobs to the miner job queue.
#     """
# 
#     def __init__(self):
#         JobManager.__init__(self, 'MINER_JOBSQUEUE_CONNECTIONSTRING')


from .constants import *
from .loggingHelper import *
from .feedManager import FeedManager
from .workerJob import WorkerJob
from .minerJobManager import MinerJobManager

InitLogging()

def pushFeedJobs():
    """
    Push feed processing jobs to job queue.
    """

    jobManager = MinerJobManager()

# Path: newsApp/feedManager.py
# class FeedManager(DbItemManagerV2):
#     """
#     Manage feeds stored on AWS dynamo db database.
# 
#     Contains functions for CRUD operations on the feeds stored
# 
#     Following environment variables need to be set -
#     'FEEDTAGSTABLE_CONNECTIONSTRING' : connection string of feed tags table.
#     """
# 
#     def __init__(self):
#         """
#         Instantiates the feedManager.
#         """
# 
#         DbItemManagerV2.__init__(self,
#             os.environ['FEEDTAGSTABLE_CONNECTIONSTRING'])
# 
#     def put(self, feed):
#         """
#         Put a new feed.
#         """
# 
#         # add polling info tags and put into database
#         feed.tags[FEEDTAG_NEXTPOLLTIME] = int(time.time())
#         if FEEDTAG_POLLFREQUENCY not in feed.tags:
#             feed.tags[FEEDTAG_POLLFREQUENCY] = DEFAULT_FEED_POLLING_FREQUENCY
#         DbItemManagerV2.put(self, feed)
# 
#     def getStaleFeeds(self):
#         """
#         Returns a list of feedIds of stale feeds (i.e whose next poll time
#         is less than current time.
#         """
# 
#         currentTime = int(time.time())
#         scanResults = DbItemManagerV2.scan(self, nextPollTime__lte = currentTime)
#         return (result.id for result in scanResults)
# 
#     def updateFeedOnSuccessfullPoll(self, feed):
#         """
#         Updates the polling related tags of specified feed and puts in db.
#         """
# 
#         feed.tags[FEEDTAG_LASTPOLLTIME] = int(time.time())
#         feed.tags[FEEDTAG_NEXTPOLLTIME] = (feed.tags[FEEDTAG_LASTPOLLTIME] +
#             feed.tags[FEEDTAG_POLLFREQUENCY]*60)
#         DbItemManagerV2.put(self, feed)
# 
# Path: newsApp/workerJob.py
# class WorkerJob:
#     """
#     Represents a job which can be processed by one of the worker roles.
#     """
# 
#     def __init__(self, jobName, jobParams, jobId = None):
#         """
#         Instantiates a new worker job object.
#         Requires 'jobName': a string representing name of the job
#         Requires 'jobParams': a dictionary where keys represnt job parameter
#             names, and corresponding values the job parameter values.
#         Optional 'jobId': a identier for this job. If not provided a
#             randomly generated alphanumeric string is used.
#         """
# 
#         if (jobId is None):
#             self.jobId = _generateRandomJobId()
#         else :
#             self.jobId = jobId
# 
#         self.jobName = jobName
#         self.jobParams = jobParams
# 
#     def deserializeFromString(self, serializedJob):
#         """
#         Sets this worker job object to the specified serialized string
#         representation.
#         """
# 
#         tempDict = json.loads(serializedJob)
#         jobName = tempDict.pop('jobName', None)
#         jobId = tempDict.pop('jobId', None)
#         self.__init__(jobName, tempDict, jobId)
# 
#     def serializeToString(self):
#         """
#         Serialize to a human-readable string representation of this object
#         """
# 
#         tempDict = dict(self.jobParams)
#         tempDict['jobName'] = self.jobName
#         tempDict['jobId'] = self.jobId
#         return json.dumps(tempDict)
# 
# Path: newsApp/minerJobManager.py
# class MinerJobManager(JobManager):
#     """
#     Helper class to enqueue and dequeue jobs to the miner job queue.
#     """
# 
#     def __init__(self):
#         JobManager.__init__(self, 'MINER_JOBSQUEUE_CONNECTIONSTRING')


# Path: newsApp/pushFeedJobs.py
from .constants import *
from .loggingHelper import *
from .feedManager import FeedManager
from .workerJob import WorkerJob
from .minerJobManager import MinerJobManager


InitLogging()

def pushFeedJobs():
    """
    Push feed processing jobs to job queue.
    """

    jobManager = MinerJobManager()

    feedManager = FeedManager()