Background
We introduced how to improve your work efficiency by Notion daily tasks in last artical,Meanwhile,we find two issues as below:
- Notion is unable to support recurring tasks,For example,daily review,daily meeting .
- you need manually update CompletedDate for Notion tasks, If not, You will still see the tasks that already completed yesterday.
Requirements
- Recurring tasks
Requirement |
---|
Create template page for recurring tasks and create recurring tasks in this template page |
Query recurring tasks in template page, Create different recurring tasks by different recurring task types,For example, Homework review is workday task , Nucleic acid testing is weekly taskk, and some tasks only occurs on specific days(Monday,Thursday etc) |
- Automatically update task status
Requirement |
---|
Task is already expired ,We need to complete this task ASAP,So mark this task as Doing Status to complete this task today |
If task will be expired in X days(X shouldn’t be empty or 0),We’d better to mark task status as Todo to avoid forgetting to complete this task |
If task will be expired today,Mark task as Doing status |
If task expiration date is within date range,Mark task as Doing status |
If you forgot to input expiration date for your task yesterday , Update task expirationDate to the date of yesterday,Mark task status as Todo |
If task is completed(Task status is Done),Update CompletedDate to the date of yesterday,This task will not show in your daily task board |
Solution and Design
Diagram
Design
Create a Notion database page as template to save recurring tasks
1.1See Cloumn name and values as below:
Column | Value | Comment |
---|---|---|
Title | task name | task name |
Status | TBD,Todo,Doing,Done,Blocker,Invalid,Withdrawn,Unfinishted,OnHold | Task status |
Type | WorkDay,SpecificDay,SpecificDateRange | Task type for recurring task |
Tag | Work,Life,Python,Docker etc, | custom field |
Cycle Date | 9/18/2022-9/25/2022 | Date range |
Cycle Days | From Monday to Sunday,Choose one or more options | From Monday to Sunday |
EndDate | Recurring task’s expiration date | Expiration date |
- 2Daily task status
Task Status | Comment |
---|---|
TBD(To be determined) | The tasks need to be completed in the future,But we don’t need to complete it today |
Todo | The tasks that need to complete today |
Doing | The task that we are doing |
Done | The task that already completed |
Blocker | The task that we can’t continue working since there are some dependencies |
Invalid | Invalid tasks,It’s only used in recurring tasks template page |
Withdrawn | The task is not needed |
Unfinished | The task that you can’t complete today and this task will be invalid on tomorrow |
OnHold | The task that you have already started ,But you can’t complete this task today,You need to continue working on this task on tomorrow |
Create Python Code to call Notion API to retrieve the records in Recurring task template page ,Add new records to Daily task page
Create Python code to call NotionAPI to update Notion tasks status
Create azure function -Timer trigger project, Call Python package that we mentioned in previous steps(You also could use jenkins instead of Azure function, see XXX)
Steps
Create recurring task page as template page for daily tasks,Please refer template page in https://stone-fighter-9fa.notion.site/530ba8c6780d4f668235e9b62f697d92?v=c802b9ed6928482c88da55051b41bb32
Develop python code to call Notion API to query recurring tasks in template page, Insert eligible recurring tasks to Daily task page https://stone-fighter-9fa.notion.site/DailyTask-Demo-59a57f31d29b4dfcab5db9d20aeca6ab
Develop python code call Notion API to update task status accordingly
Create Azure funtion timer trigger project to call Notion Python package in the morning. After Azure function triggered, You will see the new recurring task is created and some tasks status are updated accordingly.
Function.json1
2
3
4
5
6
7
8
9
10
11{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 10 16 * * *"
}
]
}init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18import datetime
import logging
import os
import azure.functions as func
from NotionRecurringTask.RecurringTask import RecurringTask
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
auth=os.environ["Auth"]
taskConfiguration_dabaseid=os.environ["TaskConfiguration_dabaseid"]
timeDeltaWithUTC=(int)(os.environ["TimeDeltaWithUTC"])
databaseid=os.environ["DatabaseID"]
knotion=RecurringTask()
knotion.process(auth,taskConfiguration_dabaseid,databaseid,timeDeltaWithUTC)
logging.info('Python timer trigger function ran at %s', utc_timestamp)
requirement.txt
1
2
3
4
5
6
7
8
9
10--index-url=https://test.pypi.org/simple/
azure-functions
requests
NotionRecurringTask-KevinZhou>0.0.7
# git+https://github.com/nightwish2016/NotionRecurringTask.git
# ./DailyNotionTaskTrigger/dist/NotionRecurringTask_KevinZhou-0.0.1-py3-none-any.whlConfig environment variables in Azure function
Environment Variable | Value |
---|---|
Auth | Access your Notion page,Please referGetting started (notion.com) |
DatabaseID | DatabaseId of daily task page |
TimeDeltaWithUTC | Time difference between your time zone and UTC time zone, if your time zone is UTC+8(Beijing time zone), Please set value to 8 |
TaskConfiguration_dabaseid | Databaseid for recurring tasks template page |
Testing
Testing for task status update
Current date:2022/9/24(utc+8)
Test Case | Test Data | Test Result |
---|---|---|
Task is already expired ,We need to complete this task ASAP,So mark this task as Doing Status to complete this task today | Name:M117 Regression,ExpirationDate:9/19/2022 | Pass,Status:Doing |
If task will be expired in X days(X =1),We’d better to mark task status as Todo to avoid forgetting to complete this task | Name:Legacy regression,ExpirationDate:9/25/2022 | Pass,Status:ToDo |
If task expiration date is within date range,Mark task as Doing status | Name:Production testing Preparation,ExpirationDate:9/19/2022-9/31/2022 | Pass,Status:Doing |
If you forgot to input expiration date for your task yesterday , Update task expirationDate to the date of yesterday,Mark task status as Todo | Name: Task1,ExpirationDate:empty | Pass,Status:ToDo |
If task is completed(Task status is Done),Update CompletedDate to the date of yesterday,This task will not show in your daily task board | Name: Task2,Status:Done | Pass,Status:Done,CompletedDate:Today |
Testing for Recurring tasks
Test Case | Test Data | Test Result |
---|---|---|
If task ype is Workday, Task will be created from Monday to Sunday | Name:M117 Regression,ExpirationDate:9/19/2022 | Pass,Task could be able tocreated in workday |
if task type is Daily, Task will be created everyday | Name:Sport | Pass,Task could be able to created everyday |
If task type is SpecificDay,Task will be created in specific days(Monday,Sunday) | Name:Nucleic acid testing,Cycle Days:Wednesday,SunDay | Pass,Task will be created on Wednesday and Sunday |
If task type is SpecificDateRange,task will be created envery day in Specific date range | Name:check for CBS automation test results,Cycle Date:9/1/2022-9/30/2022 | Pass,Task will created each day from 9/1/2022 to 9/30/2022 |
If task is expired in template page, Recurring task will not be created in daily task page | Name:Docker practice,EndDate:8/31/2022 | Pass,Task will not be created since task is expired |
Daily task status before daily azure function run,see sample in page https://stone-fighter-9fa.notion.site/DailyTask-Demo-59a57f31d29b4dfcab5db9d20aeca6ab:
Daily task status after Azure function run
Auzure function logs
The time zone above is UTC time zone
Source code and Python package
Python Package
https://test.pypi.org/project/NotionRecurringTask-KevinZhou/
Install package : pip install -i https://test.pypi.org/project/NotionRecurringTask-KevinZhou/
Github source Code
https://github.com/nightwish2016/NotionRecurringTask