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

Add time window #64

Open
stanim opened this issue Nov 24, 2019 · 10 comments
Open

Add time window #64

stanim opened this issue Nov 24, 2019 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@stanim
Copy link

stanim commented Nov 24, 2019

The business want to be able to specify a time window (start time and end time) in which the website turns automatically the website on and off. What would be the best method? Maybe a new setting which defines a function which is called in need_maintenance_response?
Would you accept a pull request for this?

Fund with Polar
@fabiocaccamo
Copy link
Owner

@stanim I have this feature in mind since long time, but actually I have not time to implement it, so I share with you my idea in case you want to send a PR:

MAINTENANCE_MODE_SCHEDULE={
    'mon': {
        'on': '03:00', 
        'off': '03:30',
    },
    'tue': {
        'on': '14:30', 
        'off': '14:45',
    },
    # for each day, or use * for all days
}

I would add support to a new setting like this one, what do you think about it?

@stanim
Copy link
Author

stanim commented Nov 24, 2019

The problem is that the business needs to be able to configure this from a webview. So Django settings are no solution, as settings are supposed to be immutable. Would it be possible to store the settings in the maintenance lock file?

@fabiocaccamo
Copy link
Owner

I understand your needs, but it seems a specific case. The maintenance state file is not for this, you should write a custom state backend that return values based on the configuration done in the webview.
Check MAINTENANCE_MODE_STATE_BACKEND setting in the README.

@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Jan 7, 2021

@stanim check #66 if you are interested to implement a quick schedule system by @scwall using the backend/database, or check #48 if you need to control maintenance mode state using the admin.

@miklevtsov
Copy link

I use https://django-constance.readthedocs.io/en/latest/ for configuring stuff like this. For example:

CONSTANCE_CONFIG = {
    "MAINTENANCE_ENABLED": (False, "Maintenance mode is enabled", bool),
    "MAINTENANCE_END": (datetime(2023, 11, 7, 11), "Maintenance mode end", datetime),
}

So you just need to implement MAINTENANCE_MODE_STATE_BACKEND as mentioned before to use this setting.

@fabiocaccamo Maybe you want to add this backend to your package, so people can choose the bundled backend if they use Constance?

@fabiocaccamo
Copy link
Owner

@miklevtsov of which backend are you talking about?

I think that this should be managed at settings level as described here #66 (comment) and also that any backend implementation would be too specific.

@Pavankumardontha
Copy link

@fabiocaccamo can i contribute to this ??

@fabiocaccamo
Copy link
Owner

@Pavankumardontha sure, but please read my prev comment.

@Pavankumardontha
Copy link

@fabiocaccamo i have read the discussions. I feel webview is not possible for now since we need db and you want to keep it db free. What can i do more to contribute to this ? Any suggestion from your end ?

@fabiocaccamo
Copy link
Owner

@Pavankumardontha my idea is to add a new MAINTENANCE_MODE_SCHEDULE setting:

# or this to schedule maintenance every day:
MAINTENANCE_MODE_SCHEDULE = {
    '*': {'start':'01:00', 'end':'02:00'},
}

# or this to specify days
MAINTENANCE_MODE_SCHEDULE = {
    'sun': {'start':'01:00', 'end':'02:00'},
    'mon': None,
    'tue': None,
    'wed': {'start':'01:00', 'end':'02:00'},
    'thu': None,
    'fri': None,
    'sat': None,
}

Then you only need to update this function:
https://github.com/fabiocaccamo/django-maintenance-mode/blob/main/maintenance_mode/http.py#L184


An alternative solution that is already supported, is to use cronjobs for calling the managements commands at specific days/hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

4 participants