示例#1
0
def startpeerfacilitysync(server, user_id):
    """
    Initiate a SYNC (PULL + PUSH) of a specific facility from another device.
    """

    user = FacilityUser.objects.get(pk=user_id)
    facility_id = user.facility.id

    device_info = get_device_info()

    extra_metadata = prepare_sync_task(
        facility_id,
        user_id,
        user.username,
        user.facility.name,
        device_info["device_name"],
        device_info["instance_id"],
        server,
        type="SYNCPEER/FULL",
    )

    job_data = prepare_peer_sync_job(server,
                                     facility_id,
                                     user.username,
                                     user.password,
                                     extra_metadata=extra_metadata)

    job_id = queue.enqueue(call_command, "sync", **job_data)

    return job_id
示例#2
0
    def test_prepare_sync_task(self):
        user = Mock(spec=FacilityUser, pk=456)
        req = Mock(spec=Request, data=dict(facility=123), user=user)

        expected = dict(
            facility=123,
            started_by=456,
            sync_state="PENDING",
            bytes_sent=0,
            bytes_received=0,
            other_kwarg="is test",
        )
        actual = prepare_sync_task(req, other_kwarg="is test")
        self.assertEqual(expected, actual)