示例#1
0
    def make_new_jobs(cls):
        """
        Send new requests to lantern, and record the jobs that are created.

        This method looks for accounts who have Lantern credentials, looks for PublicAPC records belonging to those
        accounts which could benefit from lookup in Lantern,

        :return:
        """
        dao = PublicAPC()

        gen = MonitorUKAccount.list_lantern_enabled(keepalive="1h")
        for acc in gen:
            gen2 = dao.list_by_owner(acc.id)
            identifiers = []
            for apc in gen2:
                if LanternApi._needs_lantern_data(apc):
                    idents = LanternApi._get_identifiers(apc)
                    if idents is not None:
                        identifiers.append(idents)
                    apc.lantern_lookup = dates.now()
                    apc.save()

            # if there are no identifiers, no need to do any more
            if len(identifiers) == 0:
                continue

            # now check the user's quota
            lc = client.Lantern(api_key=acc.lantern_api_key)
            quota = lc.get_quota(acc.lantern_email)
            available = quota.get("data", {}).get("available", 0)
            if available == 0:
                continue

            if len(identifiers) > available:
                identifiers = identifiers[:available]

            batches = LanternApi._batch(identifiers)
            for batch in batches:
                resp = lc.create_job(acc.lantern_email, "monitor-uk", batch)
                if resp.get("status") == "success":
                    job_id = resp.get("data", {}).get("job")
                    lj = LanternJob()
                    lj.job_id = job_id
                    lj.account = acc.id
                    lj.status = "active"
                    lj.save()
示例#2
0
    def test_06_public_dao(self):
        # Check all the DAO methods on the PublicAPC object

        dao = PublicAPC()

        source = PublicAPCFixtureFactory.example()
        pub = PublicAPC(source)
        pub.set_apc_ref("test1", "1111111111")
        pub.save(blocking=True)

        # first try the straight-forward pull
        pub2 = dao.pull(pub.id)
        assert pub2 is not None

        # now do the successful queries
        res = dao.find_by_doi("10.1234/me")
        assert len(res) == 1

        res = dao.find_by_pmid("87654321")
        assert len(res) == 1

        res = dao.find_by_pmcid("PMC1234")
        assert len(res) == 1

        res = dao.find_by_url("http://example.com/whatever")
        assert len(res) == 1

        # now to check those queries don't always return, make sure we can get 0 results
        res = dao.find_by_doi("10.1234/whatever")
        assert len(res) == 0

        res = dao.find_by_pmid("88888888")
        assert len(res) == 0

        res = dao.find_by_pmcid("PMC1111")
        assert len(res) == 0

        res = dao.find_by_url("http://example.com/another")
        assert len(res) == 0

        gen = dao.list_by_owner("abcdefg")
        count = 0
        for apc in gen:
            count += 1
        assert count == 1