Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from configobj import ConfigObj
- from cmdlineutil import CronJob
- from sqlalchemyutil import engine_from_properties
- from jsfraudlabelercronjobs.dao.frauddetectiondb_dao import FrauddetectiondbDAO
- from jsfraudlabelercronjobs.dao.labeler_dao import LabelerDAO
- from jsfraudlabelercronjobs.sql_query_builder import SQLQueryBuilder
- from jsfraudlabelercronjobs.domainlab_outbound.doc_builder import DocBuilder
- from jsfraudlabelercronjobs.domainlab_outbound.domainlab_outbound import DomainlabOutbound
- TOOL_NAME = 'domainlab_outbound_cronjob'
- LOG = logging.getLogger(TOOL_NAME)
- def begin_execution(config, mysql_engine):
- TASK_NAME = 'asbo_domain_labeler'
- API_KEY = config['labeler.domainlab_cronjobs.api_key']
- POST_DOC_URL = config['labeler.post_doc_url']
- GET_DOC_URL = config['labeler.get_doc_url']
- frauddb_dao = FrauddetectiondbDAO(mysql_engine)
- labeler_dao = LabelerDAO(TASK_NAME, API_KEY, POST_DOC_URL, GET_DOC_URL)
- doc_builder = DocBuilder(TASK_NAME, API_KEY)
- query = SQLQueryBuilder()._domain_labeler_query()
- domainlab_outbound = DomainlabOutbound(frauddb_dao, labeler_dao, doc_builder, query)
- domainlab_outbound.run()
- class DomainlabLabelerCronjob(CronJob):
- """An implementation of the cmdlineutil CronJob
- Implement CronJob class so that this script
- handles the ops specific requirements for a command line cron job
- """
- name = TOOL_NAME
- display_name = 'JSFraudDomainlabOutboundCronjob'
- options = [
- (('config_filename',), dict(action='store', help='The config file.')),
- ]
- def __init__(self):
- super(DomainlabLabelerCronjob, self).__init__()
- def _run_impl(self):
- """
- This method loads MySQL credentials from
- A) Your team's `product_group_auto.properties` if running in Mesos
- B) Props argument you send during local dev with: --props creds.txt
- It then creates a sqlalchemy Engine.
- """
- mysql_frauddetection_engine = engine_from_properties("mysql.frauddetection", self.props)
- LOG.info("STARTING %s .", self.display_name)
- begin_execution(self.props, mysql_frauddetection_engine)
- def _main():
- """Setup and start the cmdlineutil CronJob integration.
- """
- app = DomainlabLabelerCronjob()
- app.run()
- if __name__ == '__main__':
- _main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement