import json
import threading
import time
import logging

from frigg.worker import config
from frigg.worker.jobs import Build

logger = logging.getLogger(__name__)


def fetcher():
    redis = config.redis_client()
    while redis:
        task = redis.rpop('frigg:queue')
        if task:
            __start_task(task)

        time.sleep(2)


def __start_task(json_string):
    task = json.loads(json_string)
    thread = threading.Thread(name='build-%s' % task['id'], target=__start_build, args=[task])
    thread.daemon = True
    thread.start()
    logger.info('Started %s' % task)
    return thread


def __start_build(task):
    build = Build(task['id'], task)
    build.run_tests()
    for result in build.results:
        del result
    del build

import sys
import json
import threading
import time
import logging

from frigg.worker import config
from frigg.worker.jobs import Build

logger = logging.getLogger(__name__)


def fetcher():
    redis = config.redis_client()
    while redis:
        task = redis.rpop('frigg:queue')
        if task:
            __start_task(task)

        time.sleep(2)


def __start_task(json_string):
    task = json.loads(json_string)
    thread = threading.Thread(name='build-%s' % task['id'], target=__start_build, args=[task])
    thread.daemon = True
    thread.start()
    logger.info('Started %s' % task)
    return thread


def __start_build(task):
    build = Build(task['id'], task)
    build.run_tests()
    sys.exit(0)

Make worker exit after a build
Make worker exit after a build

+ import sys
  import json
  import threading
  import time
  import logging
  
  from frigg.worker import config
  from frigg.worker.jobs import Build
  
  logger = logging.getLogger(__name__)
  
  
  def fetcher():
      redis = config.redis_client()
      while redis:
          task = redis.rpop('frigg:queue')
          if task:
              __start_task(task)
  
          time.sleep(2)
  
  
  def __start_task(json_string):
      task = json.loads(json_string)
      thread = threading.Thread(name='build-%s' % task['id'], target=__start_build, args=[task])
      thread.daemon = True
      thread.start()
      logger.info('Started %s' % task)
      return thread
  
  
  def __start_build(task):
      build = Build(task['id'], task)
      build.run_tests()
+     sys.exit(0)
-     for result in build.results:
-         del result
-     del build
  
Make worker exit after a build
## Code Before:
import json
import threading
import time
import logging

from frigg.worker import config
from frigg.worker.jobs import Build

logger = logging.getLogger(__name__)


def fetcher():
    redis = config.redis_client()
    while redis:
        task = redis.rpop('frigg:queue')
        if task:
            __start_task(task)

        time.sleep(2)


def __start_task(json_string):
    task = json.loads(json_string)
    thread = threading.Thread(name='build-%s' % task['id'], target=__start_build, args=[task])
    thread.daemon = True
    thread.start()
    logger.info('Started %s' % task)
    return thread


def __start_build(task):
    build = Build(task['id'], task)
    build.run_tests()
    for result in build.results:
        del result
    del build

## Instruction:
Make worker exit after a build
## Code After:
import sys
import json
import threading
import time
import logging

from frigg.worker import config
from frigg.worker.jobs import Build

logger = logging.getLogger(__name__)


def fetcher():
    redis = config.redis_client()
    while redis:
        task = redis.rpop('frigg:queue')
        if task:
            __start_task(task)

        time.sleep(2)


def __start_task(json_string):
    task = json.loads(json_string)
    thread = threading.Thread(name='build-%s' % task['id'], target=__start_build, args=[task])
    thread.daemon = True
    thread.start()
    logger.info('Started %s' % task)
    return thread


def __start_build(task):
    build = Build(task['id'], task)
    build.run_tests()
    sys.exit(0)
