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

scheduling frontend #700

Merged
merged 44 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cfe2164
remove usage of `any`
koonpeng Mar 7, 2023
074a920
add recurring ui to create task form
koonpeng Mar 8, 2023
5725273
disable scheduling for batch upload; pass schedule to submitTasks cb
koonpeng Mar 8, 2023
50584fa
wip adding calender ui
koonpeng Mar 8, 2023
a396394
add start_from; remove next_run
koonpeng Mar 8, 2023
82aa49f
convert recurring days to api schedule
koonpeng Mar 8, 2023
8ac0c78
add once param
koonpeng Mar 8, 2023
772f38b
use once schedule when it is not recurring
koonpeng Mar 8, 2023
7072567
use scheduled task endpoint
koonpeng Mar 17, 2023
f350824
allow schedule if at least 1 job can be run
koonpeng Mar 23, 2023
bfc7168
Merge remote-tracking branch 'origin/main' into kp/scheduling-frontend
koonpeng Mar 23, 2023
6fb8962
add start_from and until query
koonpeng Mar 23, 2023
b75b68d
add start_from and until docs
koonpeng Mar 23, 2023
e319844
change start_from and until to start_before and until_after
koonpeng Mar 23, 2023
8a2a35c
fix merge conflicts
koonpeng Mar 23, 2023
26d7fbf
remove once option
koonpeng Mar 24, 2023
3ec5a1e
use old task dispatch for immediate tasks
koonpeng Mar 24, 2023
1695f97
first successful sending schedule from frontend
koonpeng Mar 27, 2023
f36d64b
fix wrong time being returned
koonpeng Mar 28, 2023
b72b66a
calendar working but not refreshing when tasks are created/deleted
koonpeng Mar 29, 2023
73a25ae
workaround lack of refresh by remounting new instance
koonpeng Mar 30, 2023
91631e0
options for scheduling is now on 2nd view
koonpeng Apr 20, 2023
3bf6076
Merge remote-tracking branch 'origin/main' into kp/scheduling-frontend
koonpeng Apr 21, 2023
85c37b7
Merge branch 'main' into kp/scheduling-frontend
aaronchongth Jun 6, 2023
8d02736
Separate queue and calendar to be sub tabs under Task microapp
aaronchongth Jun 6, 2023
7db4f32
Fix unsubscribe access vs call
aaronchongth Jun 6, 2023
40bb50e
Resolved conflicted use of Dialog vs ConfirmationDialog
aaronchongth Jun 14, 2023
62ae8c6
Use Chip instead of Button, refactored submission
aaronchongth Jun 16, 2023
a513037
Refreshing task queue table after tasks have been submitted
aaronchongth Jun 19, 2023
5730a9f
Minimal scheduling dialog created
aaronchongth Jun 19, 2023
b51df94
Debugging scheduling range errors
aaronchongth Jun 20, 2023
49bb405
Fixed Date assignment as copy
aaronchongth Jun 20, 2023
b6a7bdb
Using startOfMinute and endOfMinute for schedule start and end time t…
aaronchongth Jun 20, 2023
f6cfd7e
Time of scheduled tasks seem to be fixed
aaronchongth Jun 20, 2023
5678cc3
api-server lint
aaronchongth Jun 20, 2023
9190e7d
react-components, lint
aaronchongth Jun 20, 2023
a841b8e
Unified task app refresh counter to be used for queue table and sched…
aaronchongth Jun 20, 2023
d156b20
Add job tag and fix delete job bug
Angatupyry Jun 27, 2023
c165fc5
Add return data type in get function
Angatupyry Jun 27, 2023
d452d7a
Changing delete order
Angatupyry Jun 27, 2023
17d1201
Adding getter for protected id member
aaronchongth Jun 30, 2023
31c250f
Revert use of single global client for tests, as concurrency with cli…
aaronchongth Jun 30, 2023
3189fca
Lint and fix e2e test
aaronchongth Jun 30, 2023
dc3cd88
Adding aria-label to submit button for e2e test
aaronchongth Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
562 changes: 546 additions & 16 deletions packages/api-client/lib/openapi/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: '796aa7a6b92f0df4ec0872dc71df915c3a58a0d3',
rmfServer: '8a2a35c3b36709e67dc704d0e2f890e2b0d6865b',
openapiGenerator: '6.2.1',
};
266 changes: 258 additions & 8 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,25 +380,26 @@ export default {
in: 'query',
},
{
description: 'defaults to 100',
required: false,
schema: {
title: 'Limit',
maximum: 1000000.0,
maximum: 1000.0,
exclusiveMinimum: 0.0,
type: 'integer',
default: 1000000,
description: 'defaults to 100',
},
name: 'limit',
in: 'query',
},
{
description: 'defaults to 0',
required: false,
schema: {
title: 'Offset',
maximum: 1000000.0,
minimum: 0.0,
type: 'integer',
default: 0,
description: 'defaults to 0',
},
name: 'offset',
in: 'query',
Expand Down Expand Up @@ -834,6 +835,186 @@ export default {
},
},
},
'/scheduled_tasks': {
get: {
tags: ['Tasks'],
summary: 'Get Scheduled Tasks',
operationId: 'get_scheduled_tasks_scheduled_tasks_get',
parameters: [
{
description: 'Only return scheduled tasks that start before given timestamp',
required: true,
schema: {
title: 'Start Before',
type: 'string',
description: 'Only return scheduled tasks that start before given timestamp',
format: 'date-time',
},
name: 'start_before',
in: 'query',
},
{
description: 'Only return scheduled tasks that stop after given timestamp',
required: true,
schema: {
title: 'Until After',
type: 'string',
description: 'Only return scheduled tasks that stop after given timestamp',
format: 'date-time',
},
name: 'until_after',
in: 'query',
},
{
description: 'defaults to 100',
required: false,
schema: {
title: 'Limit',
maximum: 1000.0,
exclusiveMinimum: 0.0,
type: 'integer',
description: 'defaults to 100',
},
name: 'limit',
in: 'query',
},
{
description: 'defaults to 0',
required: false,
schema: {
title: 'Offset',
minimum: 0.0,
type: 'integer',
description: 'defaults to 0',
},
name: 'offset',
in: 'query',
},
{
description:
"common separated list of fields to order by, prefix with '-' to sort descendingly.",
required: false,
schema: {
title: 'Order By',
type: 'string',
description:
"common separated list of fields to order by, prefix with '-' to sort descendingly.",
},
name: 'order_by',
in: 'query',
},
],
responses: {
'200': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask_list',
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
post: {
tags: ['Tasks'],
summary: 'Post Scheduled Task',
description:
'Create a scheduled task. Below are some examples of how the schedules are represented.\nFor more examples, check the docs of the underlying library used [here](https://github.com/dbader/schedule/blob/6eb0b5346b1ce35ece5050e65789fa6e44368175/docs/examples.rst).\n\n| every | to | period | at | description |\n| - | - | - | - | - |\n| 10 | - | minutes | - | Every 10 minutes |\n| - | - | hour | - | Every hour |\n| - | - | day | 10:30 | Every day at 10:30am |\n| - | - | monday | - | Every monday |\n| - | - | wednesday | 13:15 | Every wednesday at 01:15pm |\n| - | - | minute | :17 | Every 17th sec of a mintue |\n| 5 | 10 | seconds | - | Every 5-10 seconds (randomly) |',
operationId: 'post_scheduled_task_scheduled_tasks_post',
requestBody: {
content: {
'application/json': {
schema: { $ref: '#/components/schemas/PostScheduledTaskRequest' },
},
},
required: true,
},
responses: {
'201': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask',
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/scheduled_tasks/{task_id}': {
get: {
tags: ['Tasks'],
summary: 'Get Scheduled Task',
operationId: 'get_scheduled_task_scheduled_tasks__task_id__get',
parameters: [
{
required: true,
schema: { title: 'Task Id', type: 'integer' },
name: 'task_id',
in: 'path',
},
],
responses: {
'200': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask',
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
delete: {
tags: ['Tasks'],
summary: 'Del Scheduled Tasks',
operationId: 'del_scheduled_tasks_scheduled_tasks__task_id__delete',
parameters: [
{
required: true,
schema: { title: 'Task Id', type: 'integer' },
name: 'task_id',
in: 'path',
},
],
responses: {
'200': {
description: 'Successful Response',
content: { 'application/json': { schema: {} } },
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/favorite_tasks': {
get: {
tags: ['Tasks'],
Expand Down Expand Up @@ -1173,25 +1354,26 @@ export default {
in: 'query',
},
{
description: 'defaults to 100',
required: false,
schema: {
title: 'Limit',
maximum: 1000000.0,
maximum: 1000.0,
exclusiveMinimum: 0.0,
type: 'integer',
default: 1000000,
description: 'defaults to 100',
},
name: 'limit',
in: 'query',
},
{
description: 'defaults to 0',
required: false,
schema: {
title: 'Offset',
maximum: 1000000.0,
minimum: 0.0,
type: 'integer',
default: 0,
description: 'defaults to 0',
},
name: 'offset',
in: 'query',
Expand Down Expand Up @@ -2480,6 +2662,21 @@ export default {
type: 'object',
properties: { name: { title: 'Name', type: 'string' } },
},
PostScheduledTaskRequest: {
title: 'PostScheduledTaskRequest',
required: ['task_request', 'schedules'],
type: 'object',
properties: {
task_request: { $ref: '#/components/schemas/TaskRequest' },
schedules: {
title: 'Schedules',
type: 'array',
items: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTaskSchedule.leaf',
},
},
},
},
PostUsers: {
title: 'PostUsers',
required: ['username'],
Expand Down Expand Up @@ -3163,6 +3360,59 @@ export default {
type: { title: 'Error Type', type: 'string' },
},
},
'api_server.models.tortoise_models.scheduled_task.ScheduledTask': {
title: 'ScheduledTask',
required: ['id', 'created_by', 'schedules'],
type: 'object',
properties: {
id: { title: 'Id', maximum: 2147483647.0, minimum: 1.0, type: 'integer' },
task_request: { title: 'Task Request' },
created_by: { title: 'Created By', maxLength: 255, type: 'string' },
last_ran: { title: 'Last Ran', type: 'string', format: 'date-time', nullable: true },
schedules: {
title: 'Schedules',
type: 'array',
items: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTaskSchedule.leaf',
},
},
},
additionalProperties: false,
},
'api_server.models.tortoise_models.scheduled_task.ScheduledTaskSchedule.leaf': {
title: 'ScheduledTaskSchedule',
required: ['period'],
type: 'object',
properties: {
every: {
title: 'Every',
maximum: 32767.0,
minimum: -32768.0,
type: 'integer',
nullable: true,
},
start_from: { title: 'Start From', type: 'string', format: 'date-time', nullable: true },
until: { title: 'Until', type: 'string', format: 'date-time', nullable: true },
period: {
title: 'Period',
maxLength: 9,
type: 'string',
description:
'Monday: monday<br/>Tuesday: tuesday<br/>Wednesday: wednesday<br/>Thursday: thursday<br/>Friday: friday<br/>Saturday: saturday<br/>Sunday: sunday<br/>Day: day<br/>Hour: hour<br/>Minute: minute',
},
at: { title: 'At', maxLength: 255, type: 'string', nullable: true },
},
additionalProperties: false,
description:
'The schedules for a scheduled task request.<br/>A scheduled task may have multiple schedules.',
},
'api_server.models.tortoise_models.scheduled_task.ScheduledTask_list': {
title: 'ScheduledTask_list',
type: 'array',
items: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask',
},
},
'api_server.models.tortoise_models.tasks.TaskFavorite.leaf': {
title: 'TaskFavorite',
required: ['id', 'name', 'category', 'user'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import schedule
from schedule import Job
from tortoise.contrib.pydantic.creator import pydantic_model_creator
from tortoise.contrib.pydantic.creator import (
pydantic_model_creator,
pydantic_queryset_creator,
)
from tortoise.fields import (
CharEnumField,
CharField,
Expand All @@ -24,7 +27,6 @@ class ScheduledTask(Model):
created_by = CharField(255)
schedules: ReverseRelation["ScheduledTaskSchedule"]
last_ran: Optional[datetime] = DatetimeField(null=True)
next_run: Optional[datetime] = DatetimeField(null=True)


class ScheduledTaskSchedule(Model):
Expand All @@ -50,7 +52,8 @@ class Period(str, Enum):
"models.ScheduledTask", related_name="schedules"
)
every = SmallIntField(null=True)
to = SmallIntField(null=True)
start_from = DatetimeField(null=True)
until = DatetimeField(null=True)
period = CharEnumField(Period)
at = CharField(255, null=True)

Expand All @@ -59,8 +62,9 @@ def to_job(self) -> Job:
job = schedule.every(self.every)
else:
job = schedule.every()
if self.to is not None:
job = job.to(self.to)
if self.until is not None:
# schedule uses `datetime.now()`, which is tz naive
job = job.until(datetime.fromtimestamp(self.until.timestamp()))

if self.period in (
ScheduledTaskSchedule.Period.Monday,
Expand Down Expand Up @@ -88,5 +92,11 @@ def to_job(self) -> Job:
return job


from tortoise import Tortoise

Tortoise.init_models(["api_server.models.tortoise_models.scheduled_task"], "models")
ScheduledTaskPydantic = pydantic_model_creator(ScheduledTask)
ScheduledTaskSchedulePydantic = pydantic_model_creator(ScheduledTaskSchedule)
ScheduledTaskPydanticList = pydantic_queryset_creator(ScheduledTask)
ScheduledTaskSchedulePydantic = pydantic_model_creator(
ScheduledTaskSchedule, exclude=("scheduled_task",)
)
Loading