Ejemplo n.º 1
0
func sendOneReminder(ctx context.Context, t *taskqueue.Task) {
	// decode todo item
	todoItem_ := jsonToTodoItem(t.Payload)
	switch (*todoItem_).(type) {
	case TodoItem:
		{
			todoItem := (*todoItem_).(TodoItem)
			if reminderDue(todoItem) {
				// send email reminder
				// note: this doesn't handle the case where a task gets complete in between
				// when it's enqueued and when the reminder is due to be sent
				if sendReminderEmail(ctx,
					todoItem.OwnerEmail,
					todoItem.Description,
					todoItem.DueDate) {
					err := taskqueue.Delete(ctx, t, "reminders")
					if err != nil {
						// ???
					}
				}
				// if sending the reminder failed, we just leave it in the queue
			} else {
				err := taskqueue.ModifyLease(ctx, t, "reminders", 0)
				if err != nil {
					// ??
				}
			}
		}
	default:
		// ignore errors, for now
		break
	}
}
Ejemplo n.º 2
0
func example() {
	var ctx context.Context

	// [START deleting_tasks]
	// Purge entire queue...
	err := taskqueue.Purge(ctx, "queue1")

	// Delete an individual task...
	t := &taskqueue.Task{Name: "foo"}
	err = taskqueue.Delete(ctx, t, "queue1")
	// [END deleting_tasks]
	_ = err
}