Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Cloud Tasks and Python 3 App Engine environment ? #9

Open
patb2 opened this issue Aug 5, 2020 · 1 comment
Open

Support for Cloud Tasks and Python 3 App Engine environment ? #9

patb2 opened this issue Aug 5, 2020 · 1 comment

Comments

@patb2
Copy link

patb2 commented Aug 5, 2020

Would this implementation work with Cloud Tasks within Python 3 App Engine ?

@AlexisH
Copy link
Contributor

AlexisH commented Aug 5, 2020

One would have to adapt it, also checking if it's compatible with the new ndb lib for Python3, and replacing the usage of webapp2 by another lib like Flask.

But the core would remain the same : the DeferredHandler could be left unchanged (except for webapp2) and for the enqueue part integrating with Cloud Tasks would look like :

parent = client.queue_path(projectId, regionId, queue)
if countdown:
    scheduleDate = datetime.utcnow() + timedelta(seconds=countdown)
elif eta:
    scheduleDate = datetime.utcfromtimestamp(eta)
else:
    scheduleDate = datetime.utcnow()
task = {
        # "2014-10-02T15:01:23.045123456Z"
        'scheduleTime': scheduleDate.strftime('%Y-%m-%dT%H:%M:%S.0Z'),
        'appEngineHttpRequest': {
            'httpMethod': 'POST',
            'relativeUri': url,
            'body': base64.b64encode(payload).decode()
        }
  }
  if taskName:
      task['name'] = f'projects/{projectId}/locations/{regionId}/queues/{queue}/tasks/{taskName}'
  if target:
      version, service = target.rsplit('.', 1)
      task['appEngineHttpRequest']['appEngineRouting'] = {
          'service': service,
          'version': version
      }
client.create_task(parent, task)

Also note that linking the enqueue task operation with a datastore transaction would no longer be possible (_transactional keyword).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants