Dive into Code

Discover code snippets, tutorials, and programming insights

Linux

celery worker supervisor example conf

<p>celery worker supervisor example conf</p>

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; ==================================
;  celery worker supervisor example
; ==================================

; the name of your supervisord program
[program:myproject_celery]

; Set full path to celery program if using virtualenv
command=/path/to/env/bin/celery worker -A myproject --loglevel=INFO

; The directory to your Django project
directory=/path/to/myproject/myproject

; If supervisord is run as the root user, switch users to this UNIX user account
; before doing any processing.
user=user

; Supervisor will start as many instances of this program as named by numprocs
numprocs=1

; Put process stdout output in this file
stdout_logfile=/var/log/celery/myproject_worker.log

; Put process stderr output in this file
stderr_logfile=/var/log/celery/myproject_worker.log

; If true, this program will start automatically when supervisord is started
autostart=true

; May be one of false, unexpected, or true. If false, the process will never
; be autorestarted. If unexpected, the process will be restart when the program
; exits with an exit code that is not one of the exit codes associated with this
; process configuration (see exitcodes). If true, the process will be
; unconditionally restarted when it exits, without regard to its exit code.
autorestart=true

; The total number of seconds which the program needs to stay running after
; a startup to consider the start successful.
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if your broker is supervised, set its priority higher
; so it starts first
priority=998
Linux

example ngnix conf file

example nginx conf file

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
server {
    listen 80;
    server_name myproject.com;
    access_log /path/to/nginx-access.log;
    error_log /path/to/nginx-error.log debug;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /path/to/public/static;
    }
    location /media/ {
        root /patgh/to/public/media;
    }

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://unix:/path/to/project.sock;
    }

    location /ws/ {
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_pass http://unix:/path/to/project_asgi.sock;
    }
}
Linux

celery beat supervisor example conf

celery beat supervisor example conf

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
; ================================
;  celery beat supervisor example
; ================================

; the name of your supervisord program
[program:myproject]

; Set full path to celery program if using virtualenv
command=/path/to/env/bin/celery beat -A myproject --loglevel=INFO


; The directory to your Django project
directory=/path/to/myproject/myproject

; If supervisord is run as the root user, switch users to this UNIX user account
; before doing any processing.
user=user

; Supervisor will start as many instances of this program as named by numprocs
numprocs=1

; Put process stdout output in this file
stdout_logfile=/var/log/celery/myproject_beat.log

; Put process stderr output in this file
stderr_logfile=/var/log/celery/myproject_beat.log

; If true, this program will start automatically when supervisord is started
autostart=true

; May be one of false, unexpected, or true. If false, the process will never
; be autorestarted. If unexpected, the process will be restart when the program
; exits with an exit code that is not one of the exit codes associated with this
; process configuration (see exitcodes). If true, the process will be
; unconditionally restarted when it exits, without regard to its exit code.
autorestart=true

; The total number of seconds which the program needs to stay running after
; a startup to consider the start successful.
startsecs=10

; if your broker is supervised, set its priority higher
; so it starts first
priority=999
Python

Random dates in python

Random dates in python

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import datetime
import random

def random_date(start, end):
    """
    This function will return a random datetime between two datetime
    objects.
    """
    delta = end - start
    int_delta = (delta.days * 24 * 60 * 60) + delta.seconds
    random_second = random.randrange(int_delta)
    return start + datetime.timedelta(seconds=random_second)


end_date = datetime.datetime.now()
start_date = end_date - datetime.timedelta(days=60)
random_date(start_date, end_date)
Python

Python date generator

python date generator

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import datetime
date = datetime.datetime.now()
time = date.time()
def date_generator(date, delta):
  counter =0
  date = date - datetime.timedelta(days=delta)
  while counter <= delta:
    yield date
    date = date + datetime.timedelta(days=1)
    counter +=1

for date in date_generator(date, 30):
   if date.date() != datetime.datetime.now().date():
     start_date = datetime.datetime.combine(date, datetime.time())
     end_date = datetime.datetime.combine(date, datetime.time.max)
   else:
     start_date = datetime.datetime.combine(date, datetime.time())
     end_date = datetime.datetime.combine(date, time)
   print('start_date---->',start_date,'end_date---->',end_date)