Giter Site home page Giter Site logo

django-crontab-to-run-flushexpiredtokens's Introduction

django-crontab to run flushexpiredtokens

Implementation of django-crontab to run flushexpiredtokens


Header

THIS PROJECT WAS MADE TO LEARN TO USE THE CRONTAB TO RUN FLUSHEXPIREDTOKENS

Learn REST API with Django Rest Framework and Mysql

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

In this project we will see the Implementation of django-crontab to execute flushexpiredtokens and eliminate the tokens from the Outstanding tokens and Blacklisted tokens generated with Simple JWT list.

Built With

Frameworks and libraries. Framewrok:

Libraries:

Getting Started

To check your rest api

Insomnia

With their streamlined API client, you can quickly and easily send REST, SOAP, GraphQL, and GRPC requests directly within Insomnia. Link to visit insomnia website: - Link

Header

Postman

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIsβ€”faster. Link to visit postman website: - Link

Header

Prerequisites

In this example we use simple jwt with django rest framework, you must have a jwt implementation to generate the tokens that will be sent to the Blacklisted token and Outstanding tokens

Installation πŸ–₯

  1. To obtain my repository you must create a folder in a desired directory and within this folder open a terminal or use cmd in the case of windows.

  2. Clone the repo

    git clone [email protected]:aldomatus/django-crontab-to-run-flushexpiredtokens.git
    
    
  3. Make the pull request from a branch called main

    git fetch
    git checkout origin master
    git pull origin master
    
    http://localhost:8000/admin/
    

Description of the files πŸ’Ό 🐳

requirements.txt

In our requirements file we write the flask libraries, the connection libraries for msql and with which we are going to manage the SQL data

asgiref==3.4.1
Django==3.2.7
django-common-helpers==0.9.2
django-cors-headers==3.8.0
django-cron==0.5.1
django-crontab==0.7.1
django-environ==0.7.0
django-rest-auth==0.9.5
djangorestframework==3.12.4
djangorestframework-simplejwt==4.8.0
mysqlclient==2.0.3
Pillow==8.3.2
PyJWT==2.1.0
pytz==2021.1
six==1.16.0
sqlparse==0.4.2

.env file 🌍

This file contains our environment variables that will be read by the dockerfile.

FLASK_DEBUG=True
FLASK_APP=src/main.py
FLASK_RUN_HOST=0.0.0.0
ALLOWED_HOSTS=127.0.0.1,localhost

django-crontab implementaction

install via pip:

pip install django-crontab

add it to installed apps in django settings.py:

INSTALLED_APPS = (
    'django_crontab',
    ...
)

now create a new method that should be executed by cron every 5 minutes, f.e. in myapp/cron.py:

def my_scheduled_job():
  pass
# Example
import os
import sys

def flushexpiredtokens():
    os.system('GREPDB="cd /home/aldo/Documents/independent_projects/wpo-back/ && source .venv/bin/activate && python3 manage.py flushexpiredtokens > /dev/null 2>&1"; /bin/bash -c "$GREPDB"')

now add this to your settings.py:

CRONJOBS = [
    ('*/5 * * * *', 'myapp.cron.my_scheduled_job')
]
# Example
CRONJOBS = [
    ('*/1 * * * *', 'Apps.users.cron.flushexpiredtokens')
    ]

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Aldo Matus - Linkedin Facebook

Project Link: Repository

django-crontab-to-run-flushexpiredtokens's People

Contributors

aldomatus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.