Ejemplo n.º 1
0
def schedule_sync(workspace_id, schedule, user):
    """
    Schedule sync
    :param workspace_id: workspace_id
    :param schedule: schedule object
    :param user: user email
    """
    fyle_sdk_connection = connect_to_fyle(workspace_id)

    jobs = FyleJobsSDK(settings.FYLE_JOBS_URL, fyle_sdk_connection)

    created_job = jobs.trigger_interval(
        callback_url='{0}{1}'.format(
            settings.API_BASE_URL,
            '/workspace_jobs/{0}/settings/schedule/trigger/'.format(
                workspace_id
            )
        ),
        callback_method='POST',
        object_id=schedule.id,
        job_description='Fetch expenses: Workspace id - {0}, user - {1}'.format(
            workspace_id, user
        ),
        start_datetime=schedule.start_datetime.strftime('%Y-%m-%d %H:%M:00.00'),
        hours=int(schedule.interval_hours)
    )
    schedule.fyle_job_id = created_job['id']
    schedule.save()
Ejemplo n.º 2
0
def create_schedule_job(workspace_id: int, schedule: WorkspaceSchedule,
                        user: str, start_datetime: datetime, hours: int):
    fyle_credentials = FyleCredential.objects.get(workspace_id=workspace_id)
    fyle_connector = FyleConnector(fyle_credentials.refresh_token)
    fyle_sdk_connection = fyle_connector.connection

    jobs = FyleJobsSDK(settings.FYLE_JOBS_URL, fyle_sdk_connection)

    created_job = jobs.trigger_interval(
        callback_url='{0}{1}'.format(
            settings.API_URL,
            '/workspaces/{0}/schedule/trigger/'.format(workspace_id)),
        callback_method='POST',
        object_id=schedule.id,
        job_description='Fetch expenses: Workspace id - {0}, user - {1}'.
        format(workspace_id, user),
        start_datetime=start_datetime.strftime('%Y-%m-%d %H:%M:00.00'),
        hours=hours)
    return created_job