Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
220 changes: 119 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,121 @@
# In name of Allah
# Django Schedular

## Introduction
We want a simple app to schedule & validate tasks for users. It should be possible to use django admin as interface for this application.

There are two kind of users:
- normal users
- admin users

**note** that each user must have below fields:
- email
- username
- password
- first name
- last name
- permissions (admin & normal)

You should extend AbstractUser for implementing user model.

normal users can only see, filter & add to their own tasks. These tasks will have a title, description, owner, time to send and precondition tasks field. the task should be scheduled to send an email to its owner at the specified time (use celery for this purpose) **Note** that every task has a set of precondition tasks (which are tasks as well) meaning for a task to be done, first, the set of tasks defined for it should have been done by the time it needs to be sent, otherwise the task will not be considered done. Also definition of done for a task is if it was sent at the specified time.

admin users have the permission to manage users, add to them and delete them. Also they can manage all tasks of users, add task for them and edit their tasks. When created or edited, scheduled tasks should be added or edited.

### Note
Write an API for validating a set of tasks (validation means if the set of tasks is possible to be done or not). If there is a precondition task which is not in the specified set of tasks, you do not need to consider it.

### Example

#### example 1
- Task
- id: 1
- title: task 1
- description: desc 1
- owner: nilva.man
- time to send: 2020-05-10 10:30
- pre-tasks:
- Task
- id: 2
- title: task 2
- description: desc 2
- owner: nilva.man
- time to send: 2020-05-06 10:30
- pre-tasks:
- 1
- 3
- Task
- id: 3
- title: task 3
- description: desc 3
- owner: nilva.man
- time to send: 2020-02-10 9:30
- pre-tasks:

result: **No**, task 1 happens after task 2, but is a precondition of task 2, which makes it impossible to happen

#### example 2
- Task
- id: 1
- title: task 1
- description: desc 1
- owner: nilva.man
- time to send: 2020-05-10 10:30
- pre-tasks:
- Task
- id: 2
- title: task 2
- description: desc 2
- owner: nilva.man
- time to send: 2020-06-10 12:30
- pre-tasks:
- 1
- 3
- Task
- id: 3
- title: task 3
- description: desc 3
- owner: nilva.man
- time to send: 2020-06-01 12:30
- pre-tasks:
- 1

result: **Yes**, First task 1 will happen, then task 3, then task 2


## Expectations

So What does matter to us?
- a clean structure of codebase & components
- clean code practices
- well written unit tests
- finally, ability to learn

## Tasks

1. Fork this repository
2. Break and specify your tasks in project management tool (append the image of your tasks to readme file of your project)
3. Learn & Develop
4. Push your code to your repository
5. Explain the roadmap of your development in readme of repository (also append the image of your specified tasks on part 2 to file)
6. Send us a pull request, we will review and get back to you
7. Enjoy

**Finally** don't be afraid to ask anything from us.

Django Schedular is a web-based task scheduling and validation application built using the Django framework. It is designed to streamline task management for users, allowing them to schedule tasks, set dependencies, and receive timely notifications. The application is tailored to meet the needs of both individual users and administrators overseeing multiple users and tasks.


## Key Features

- Task Scheduling: Users can easily schedule tasks with specific details such as title description, owner, and time to send.

- Dependency Management: Tasks can have preconditions, ensuring that specific tasks are completed before others can be scheduled.

- Email Notifications: The application leverages Celery for task scheduling, including sending email notifications to task owners at the specified time.
## Table of Contents
1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Usage](#usage)
4. [API Reference](#api-reference)

---
## project managment Board
i used trello for managing tasks

[board](https://trello.com/invite/b/2qjTiUPw/ATTI1ef0b3968c6c6932a821f871a4112a4514888892/nilva)

## Installation


#### Clone the repository

clone the repository with git clone


#### Install dependencies
```sh
pip install -r requirements.txt
```

## Configuration

Explain any configuration settings that users may need to modify, including environment variables, configuration files, etc.

#### Set environment variables
```sh
...
SECRET_KEY=
DEBUG=
EMAIL_HOST=
EMAIL_PORT=
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
CELERY_BROKER_URL=
SENDER_EMAIL=
...
```

## Usage

#### Perform migrations

```sh
python manage.py makemigrations
python manage.py migrate
```

#### Create SuperUser
```sh
python manage.py createsuperuser
```


#### Run the development server
```sh
python manage.py runserver
```

#### Run the celery
```sh
celery -A TaskScheduler worker --loglevel=info
```

----

visit the app in [127.0.0.1:8000/admin](http://127.0.0.1:8000/admin)


## API Reference

This project has only one endpoint that shows the list of tasks

Endpoint 1

URL: /tasks/validate
Method: GET
Parameters:
-
Response:

json

[
{
"id": 1,
"title": "task title",
"description": "task description",
"owner": 1, <user_id>
"time_to_send": "2024-02-02T20:46:42Z",
"precondition_tasks": [], <task_id>
"is_valid": "yes" / "no"
},
{
"id": 2,
"title": "task title",
"description": "task description",
"owner": 1, <user_id>
"time_to_send": "2024-02-02T20:46:42Z",
"precondition_tasks": [], <task_id>
"is_valid": "yes" / "no"
},
]
Empty file added TaskScheduler/__init__.py
Empty file.
Binary file added TaskScheduler/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added TaskScheduler/__pycache__/celery.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added TaskScheduler/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added TaskScheduler/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions TaskScheduler/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for TaskScheduler project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TaskScheduler.settings')

application = get_asgi_application()
14 changes: 14 additions & 0 deletions TaskScheduler/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TaskScheduler.settings')

# Create a Celery instance and configure it using the settings from `TaskScheduler/settings.py`
from django.conf import settings
app = Celery('TaskScheduler')
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
Loading