Beispiel #1
0
def add_version(flask_app):
    """
    ADD ROUTING TO HANDLE REQUEST FOR /__version__
    :param flask_app: THE (Flask) APP
    :return:
    """
    try:
        rev = coalesce(git.get_revision(), "")
        branch = "https://github.com/mozilla/ActiveData/tree/" + coalesce(
            git.get_branch())

        version_info = value2json(
            {
                "source": "https://github.com/mozilla/ActiveData/tree/" + rev,
                "branch": branch,
                "commit": rev,
            },
            pretty=True,
        ).encode('utf8') + b"\n"

        Log.note("Using github version\n{{version}}", version=version_info)

        @register_thread
        @cors_wrapper
        def version():
            return Response(version_info,
                            status=200,
                            headers={"Content-Type": mimetype.JSON})

        flask_app.add_url_rule(
            str("/__version__"),
            None,
            version,
            defaults={},
            methods=[str("GET"), str("POST")],
        )
    except Exception as e:
        Log.error("Problem setting up listeners for dockerflow", cause=e)
Beispiel #2
0
 def test_get_revision(self):
     rev = git.get_revision()
     self.assertTrue(is_hex(rev))
     self.assertEqual(len(rev), 40)
Beispiel #3
0
    def process_one(self, start, end, branch, please_stop):
        # ASSUME PREVIOUS WORK IS DONE
        # UPDATE THE DATABASE STATE
        self.done.min = mo_math.min(end, self.done.min)
        self.done.max = mo_math.max(start, self.done.max)
        self.set_state()

        try:
            pushes = make_push_objects(from_date=start.format(),
                                       to_date=end.format(),
                                       branch=branch)
        except MissingDataError:
            return
        except Exception as e:
            raise Log.error("not expected", cause=e)

        Log.note(
            "Found {{num}} pushes on {{branch}} in ({{start}}, {{end}})",
            num=len(pushes),
            start=start,
            end=end,
            branch=branch,
        )

        data = []
        try:
            for push in pushes:
                if please_stop:
                    break

                with Timer("get tasks for push {{push}}", {"push": push.id}):
                    try:
                        schedulers = [
                            label.split("shadow-scheduler-")[1]
                            for label in push.scheduled_task_labels
                            if "shadow-scheduler" in label
                        ]
                    except Exception as e:
                        Log.warning("could not get schedulers", cause=e)
                        schedulers = []

                    scheduler = []
                    for s in schedulers:
                        try:
                            scheduler.append({
                                "name":
                                s,
                                "tasks":
                                jx.sort(push.get_shadow_scheduler_tasks(s)),
                            })
                        except Exception:
                            pass
                try:
                    regressions = push.get_regressions("label").keys()
                except Exception as e:
                    regressions = []
                    Log.warning("could not get regressions for {{push}}",
                                push=push.id,
                                cause=e)

                # RECORD THE PUSH
                data.append({
                    "push": {
                        "id": push.id,
                        "date": push.date,
                        "changesets": push.revs,
                        "backedoutby": push.backedoutby,
                    },
                    "schedulers":
                    scheduler,
                    "regressions": [{
                        "label": name
                    } for name in jx.sort(regressions)],
                    "branch":
                    branch,
                    "etl": {
                        "revision": git.get_revision(),
                        "timestamp": Date.now(),
                    },
                })
        finally:
            # ADD WHATEVER WE HAVE
            with Timer("adding {{num}} records to bigquery",
                       {"num": len(data)}):
                self.destination.extend(data)
Beispiel #4
0
import os

from mo_files import File
from mo_future import text_type
from mo_json import value2json
from pyLibrary.env import git

print("Uses *.dockerfile environment variables to write a verion.json file")

File("version.json").write(value2json(
    {
        "source": os.environ.get('REPO_URL'),
        "version": os.environ.get('REPO_CHECKOUT').replace("tags/", '"'),
        "commit": git.get_revision(),
        "build": os.environ.get('BUILD_URL')
    },
    pretty=True
) + text_type("\n"))