Explore all Redis open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Redis

No Popular Releases are available at this moment for Redis

Popular Libraries in Redis

AnimalRecognitionDemo

by RedisGears doticonpythondoticon

star image 30 doticonApache-2.0

An example of using Redis Streams, RedisGears and RedisAI for Realtime Video Analytics (i.e. filtering cats)

redis-pipeline

by online-demo doticonjavadoticon

star image 2 doticon

redis-pipeline

redis-recommend

by wlattner doticoncdoticon

star image 2 doticon

A Recommendation Module for Redis

Trending New libraries in Redis

redis-pipeline

by online-demo doticonjavadoticon

star image 2 doticon

redis-pipeline

Top Authors in Redis

1

RedisGears

1 Libraries

star icon30

2

online-demo

1 Libraries

star icon2

3

wlattner

1 Libraries

star icon2

1

1 Libraries

star icon30

2

1 Libraries

star icon2

3

1 Libraries

star icon2

Trending Kits in Redis

No Trending Kits are available at this moment for Redis

Trending Discussions on Redis

How to invalidate a view cache using django-cacheops

Redis NodeJs server error,client is closed

angular 13: Module not found: Error: Can't resolve 'rxjs/operators'

Celery unable to use redis

Unable to build and deploy Rails 6.0.4.1 app on heroku - Throws gyp verb cli error

Why the swagger doesn't open in .NET 6?

log4shell exploit for Redis server

Docker image does not run with specified Python version

Bitnami Redis on Kubernetes Authentication Failure with Existing Secret

Removed Node.js v15 from list of versions, but Github Actions still shows it in list of checks

QUESTION

How to invalidate a view cache using django-cacheops

Asked 2022-Mar-19 at 15:05

I have a view and I cached it in views.py using django-cacheops (https://github.com/Suor/django-cacheops):

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5

The regex for order view in urls.py:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7

And I want to invalidate the cached view order inside the below view:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16

According to the docs, we can achieve this by doing:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16@login_required 
17def available(request, pk, avail):
18    pk = int(pk)
19    avail = strtobool(avail)
20    if avail:
21        Product.objects.filter(id = pk).update(available = True)
22        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
23        #it's a dummy url I've handled it dynamically in my code
24    else:
25        Product.objects.filter(id = pk).update(available = False)
26        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
27        #it's a dummy url I've handled it dynamically in my code
28    return HttpResponseRedirect(reverse_lazy('yc')) 
29

But it's not working. Here are my logs using redis-cli monitor:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16@login_required 
17def available(request, pk, avail):
18    pk = int(pk)
19    avail = strtobool(avail)
20    if avail:
21        Product.objects.filter(id = pk).update(available = True)
22        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
23        #it's a dummy url I've handled it dynamically in my code
24    else:
25        Product.objects.filter(id = pk).update(available = False)
26        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
27        #it's a dummy url I've handled it dynamically in my code
28    return HttpResponseRedirect(reverse_lazy('yc')) 
291647434341.849096 [1 [::1]:59650] "GET" "c:af687d461ec8bb3c48f6392010e54778"
301647434341.866966 [1 [::1]:59650] "SETEX" "c:af687d461ec8bb3c48f6392010e54778" "900" "\x80\x04\x95\xfa\b\x00\x00\x00\x00\x00\x00\x8c\x14django.http.response\x94\x8c\x0cHttpResponse\x94\x93\x94)\x81\x94}\x94(\x8c\b_headers\x94}\x94\x8c\x0ccontent-type\x94\x8c\x0cContent-Type\x94\x8c\x18text/html; charset=utf-8\x94\x86\x94s\x8c\x11_closable_objects\x94]\x94\x8c\x0e_handler_class\x94N\x8c\acookies\x94\x8c\x0chttp.cookies\x94\x8c\x0cSimpleCookie\x94\x93\x94)\x81\x94\x8c\x06closed\x94\x89\x8c\x0e_reason_phrase\x94N\x8c\b_charset\x94N\x8c\n_container\x94]\x94B\xed\a\x00\x00<!DOCTYPE html>\n\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Buy Products</title>\n    <link href=\"https://fonts.googleapis.com/css?family=Peralta\" rel=\"stylesheet\">\n    <link rel=\"stylesheet\" href=\"/static/css/bootstrap.min.css\">\n    <link rel=\"stylesheet\" href=\"/static/css/app.css\">\n  </head>\n  <body>\n      <div class=\"wrapper\">\n        <div class=\"container\">\n          <ol class=\"breadcrumb my-4\">\n            <li class=\"breadcrumb-item active\" style=\"color: #000;\">Buy Products</li>\n          </ol>\n          <form method=\"post\">\n            <!-- <input type=\"hidden\" name=\"csrfmiddlewaretoken\" value=\"SnsBnyPIwIDejqctR7TMNkITcSafgwiydwsyIiAKQkiSvr3nFA0cm1Tf3Mk6JTPj\"> -->\n            <p><label for=\"id_name\">Name:</label> <select name=\"name\" id=\"id_name\">\n  <option value=\"Redmi note 5\">Product Name: Redmi note 5 \n MRP: 100000 \n  Discounted Price: 45678 \n Description: It's good phone too</option>\n\n  <option value=\"xiomi 2\">Product Name: xiomi 2 \n MRP: 10000 \n  Discounted Price: 200 \n Description: xyz</option>\n\n  <option value=\"mouse\">Product Name: mouse \n MRP: 1400 \n  Discounted Price: 200 \n Description: xyzat</option>\n\n</select></p>\n<p><label for=\"id_user_name\">User name:</label> <textarea name=\"user_name\" cols=\"40\" rows=\"1\" maxlength=\"30\" required id=\"id_user_name\">\n</textarea></p>\n<p><label for=\"id_adress\">Adress:</label> <textarea name=\"adress\" cols=\"40\" rows=\"2\" maxlength=\"4000\" required id=\"id_adress\">\n</textarea></p>\n<p><label for=\"id_mobile\">Mobile:</label> <textarea name=\"mobile\" cols=\"40\" rows=\"1\" maxlength=\"10\" required id=\"id_mobile\">\n</textarea></p>\n<p><label for=\"id_qty\">Qty:</label> <input type=\"number\" name=\"qty\" required id=\"id_qty\"></p>\n            <button type=\"submit\" class=\"btn btn-success\">Buy</button>\n          </form>\n        </div>\n        <div class=\"push\"></div>\n      </div>\n    <script src=\"/static/js/jquery-3.2.1.min.js\"></script>\n    <script src=\"/static/js/popper.min.js\"></script>\n    <script src=\"/static/js/bootstrap.min.js\"></script>\n  </body>\n</html>\n\x94aub."
311647434354.133804 [1 [::1]:59650] "DEL" "c:94c7a9e7f6c7a45ee645caa02f53d000"
32

It looks like it's deleting some other cache.

I've also raised the issue in the repo of django-cache, you can check it for more information: https://github.com/Suor/django-cacheops/issues/425

ANSWER

Answered 2022-Mar-19 at 14:37

Since you used a named group usr in your regex, Django passes it as a keyword argument:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16@login_required 
17def available(request, pk, avail):
18    pk = int(pk)
19    avail = strtobool(avail)
20    if avail:
21        Product.objects.filter(id = pk).update(available = True)
22        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
23        #it's a dummy url I've handled it dynamically in my code
24    else:
25        Product.objects.filter(id = pk).update(available = False)
26        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
27        #it's a dummy url I've handled it dynamically in my code
28    return HttpResponseRedirect(reverse_lazy('yc')) 
291647434341.849096 [1 [::1]:59650] "GET" "c:af687d461ec8bb3c48f6392010e54778"
301647434341.866966 [1 [::1]:59650] "SETEX" "c:af687d461ec8bb3c48f6392010e54778" "900" "\x80\x04\x95\xfa\b\x00\x00\x00\x00\x00\x00\x8c\x14django.http.response\x94\x8c\x0cHttpResponse\x94\x93\x94)\x81\x94}\x94(\x8c\b_headers\x94}\x94\x8c\x0ccontent-type\x94\x8c\x0cContent-Type\x94\x8c\x18text/html; charset=utf-8\x94\x86\x94s\x8c\x11_closable_objects\x94]\x94\x8c\x0e_handler_class\x94N\x8c\acookies\x94\x8c\x0chttp.cookies\x94\x8c\x0cSimpleCookie\x94\x93\x94)\x81\x94\x8c\x06closed\x94\x89\x8c\x0e_reason_phrase\x94N\x8c\b_charset\x94N\x8c\n_container\x94]\x94B\xed\a\x00\x00<!DOCTYPE html>\n\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Buy Products</title>\n    <link href=\"https://fonts.googleapis.com/css?family=Peralta\" rel=\"stylesheet\">\n    <link rel=\"stylesheet\" href=\"/static/css/bootstrap.min.css\">\n    <link rel=\"stylesheet\" href=\"/static/css/app.css\">\n  </head>\n  <body>\n      <div class=\"wrapper\">\n        <div class=\"container\">\n          <ol class=\"breadcrumb my-4\">\n            <li class=\"breadcrumb-item active\" style=\"color: #000;\">Buy Products</li>\n          </ol>\n          <form method=\"post\">\n            <!-- <input type=\"hidden\" name=\"csrfmiddlewaretoken\" value=\"SnsBnyPIwIDejqctR7TMNkITcSafgwiydwsyIiAKQkiSvr3nFA0cm1Tf3Mk6JTPj\"> -->\n            <p><label for=\"id_name\">Name:</label> <select name=\"name\" id=\"id_name\">\n  <option value=\"Redmi note 5\">Product Name: Redmi note 5 \n MRP: 100000 \n  Discounted Price: 45678 \n Description: It's good phone too</option>\n\n  <option value=\"xiomi 2\">Product Name: xiomi 2 \n MRP: 10000 \n  Discounted Price: 200 \n Description: xyz</option>\n\n  <option value=\"mouse\">Product Name: mouse \n MRP: 1400 \n  Discounted Price: 200 \n Description: xyzat</option>\n\n</select></p>\n<p><label for=\"id_user_name\">User name:</label> <textarea name=\"user_name\" cols=\"40\" rows=\"1\" maxlength=\"30\" required id=\"id_user_name\">\n</textarea></p>\n<p><label for=\"id_adress\">Adress:</label> <textarea name=\"adress\" cols=\"40\" rows=\"2\" maxlength=\"4000\" required id=\"id_adress\">\n</textarea></p>\n<p><label for=\"id_mobile\">Mobile:</label> <textarea name=\"mobile\" cols=\"40\" rows=\"1\" maxlength=\"10\" required id=\"id_mobile\">\n</textarea></p>\n<p><label for=\"id_qty\">Qty:</label> <input type=\"number\" name=\"qty\" required id=\"id_qty\"></p>\n            <button type=\"submit\" class=\"btn btn-success\">Buy</button>\n          </form>\n        </div>\n        <div class=\"push\"></div>\n      </div>\n    <script src=\"/static/js/jquery-3.2.1.min.js\"></script>\n    <script src=\"/static/js/popper.min.js\"></script>\n    <script src=\"/static/js/bootstrap.min.js\"></script>\n  </body>\n</html>\n\x94aub."
311647434354.133804 [1 [::1]:59650] "DEL" "c:94c7a9e7f6c7a45ee645caa02f53d000"
32url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
33

But you are trying to invalidate the cache with a positional argument:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16@login_required 
17def available(request, pk, avail):
18    pk = int(pk)
19    avail = strtobool(avail)
20    if avail:
21        Product.objects.filter(id = pk).update(available = True)
22        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
23        #it's a dummy url I've handled it dynamically in my code
24    else:
25        Product.objects.filter(id = pk).update(available = False)
26        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
27        #it's a dummy url I've handled it dynamically in my code
28    return HttpResponseRedirect(reverse_lazy('yc')) 
291647434341.849096 [1 [::1]:59650] "GET" "c:af687d461ec8bb3c48f6392010e54778"
301647434341.866966 [1 [::1]:59650] "SETEX" "c:af687d461ec8bb3c48f6392010e54778" "900" "\x80\x04\x95\xfa\b\x00\x00\x00\x00\x00\x00\x8c\x14django.http.response\x94\x8c\x0cHttpResponse\x94\x93\x94)\x81\x94}\x94(\x8c\b_headers\x94}\x94\x8c\x0ccontent-type\x94\x8c\x0cContent-Type\x94\x8c\x18text/html; charset=utf-8\x94\x86\x94s\x8c\x11_closable_objects\x94]\x94\x8c\x0e_handler_class\x94N\x8c\acookies\x94\x8c\x0chttp.cookies\x94\x8c\x0cSimpleCookie\x94\x93\x94)\x81\x94\x8c\x06closed\x94\x89\x8c\x0e_reason_phrase\x94N\x8c\b_charset\x94N\x8c\n_container\x94]\x94B\xed\a\x00\x00<!DOCTYPE html>\n\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Buy Products</title>\n    <link href=\"https://fonts.googleapis.com/css?family=Peralta\" rel=\"stylesheet\">\n    <link rel=\"stylesheet\" href=\"/static/css/bootstrap.min.css\">\n    <link rel=\"stylesheet\" href=\"/static/css/app.css\">\n  </head>\n  <body>\n      <div class=\"wrapper\">\n        <div class=\"container\">\n          <ol class=\"breadcrumb my-4\">\n            <li class=\"breadcrumb-item active\" style=\"color: #000;\">Buy Products</li>\n          </ol>\n          <form method=\"post\">\n            <!-- <input type=\"hidden\" name=\"csrfmiddlewaretoken\" value=\"SnsBnyPIwIDejqctR7TMNkITcSafgwiydwsyIiAKQkiSvr3nFA0cm1Tf3Mk6JTPj\"> -->\n            <p><label for=\"id_name\">Name:</label> <select name=\"name\" id=\"id_name\">\n  <option value=\"Redmi note 5\">Product Name: Redmi note 5 \n MRP: 100000 \n  Discounted Price: 45678 \n Description: It's good phone too</option>\n\n  <option value=\"xiomi 2\">Product Name: xiomi 2 \n MRP: 10000 \n  Discounted Price: 200 \n Description: xyz</option>\n\n  <option value=\"mouse\">Product Name: mouse \n MRP: 1400 \n  Discounted Price: 200 \n Description: xyzat</option>\n\n</select></p>\n<p><label for=\"id_user_name\">User name:</label> <textarea name=\"user_name\" cols=\"40\" rows=\"1\" maxlength=\"30\" required id=\"id_user_name\">\n</textarea></p>\n<p><label for=\"id_adress\">Adress:</label> <textarea name=\"adress\" cols=\"40\" rows=\"2\" maxlength=\"4000\" required id=\"id_adress\">\n</textarea></p>\n<p><label for=\"id_mobile\">Mobile:</label> <textarea name=\"mobile\" cols=\"40\" rows=\"1\" maxlength=\"10\" required id=\"id_mobile\">\n</textarea></p>\n<p><label for=\"id_qty\">Qty:</label> <input type=\"number\" name=\"qty\" required id=\"id_qty\"></p>\n            <button type=\"submit\" class=\"btn btn-success\">Buy</button>\n          </form>\n        </div>\n        <div class=\"push\"></div>\n      </div>\n    <script src=\"/static/js/jquery-3.2.1.min.js\"></script>\n    <script src=\"/static/js/popper.min.js\"></script>\n    <script src=\"/static/js/bootstrap.min.js\"></script>\n  </body>\n</html>\n\x94aub."
311647434354.133804 [1 [::1]:59650] "DEL" "c:94c7a9e7f6c7a45ee645caa02f53d000"
32url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
33order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
34

Instead, invalidate it with the corresponding keyword argument:

1@cached_view(timeout=60*15)
2@csrf_exempt
3def order(request, usr):
4    ...
5url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
6# Example Url: http://127.0.0.1:8000/order/demo (demo is the user name)
7@login_required 
8def available(request, pk, avail):
9    pk = int(pk)
10    avail = strtobool(avail)
11    if avail:
12        Product.objects.filter(id = pk).update(available = True)
13    else:
14        Product.objects.filter(id = pk).update(available = False)
15    return HttpResponseRedirect(reverse_lazy('yc')) 
16@login_required 
17def available(request, pk, avail):
18    pk = int(pk)
19    avail = strtobool(avail)
20    if avail:
21        Product.objects.filter(id = pk).update(available = True)
22        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
23        #it's a dummy url I've handled it dynamically in my code
24    else:
25        Product.objects.filter(id = pk).update(available = False)
26        order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
27        #it's a dummy url I've handled it dynamically in my code
28    return HttpResponseRedirect(reverse_lazy('yc')) 
291647434341.849096 [1 [::1]:59650] "GET" "c:af687d461ec8bb3c48f6392010e54778"
301647434341.866966 [1 [::1]:59650] "SETEX" "c:af687d461ec8bb3c48f6392010e54778" "900" "\x80\x04\x95\xfa\b\x00\x00\x00\x00\x00\x00\x8c\x14django.http.response\x94\x8c\x0cHttpResponse\x94\x93\x94)\x81\x94}\x94(\x8c\b_headers\x94}\x94\x8c\x0ccontent-type\x94\x8c\x0cContent-Type\x94\x8c\x18text/html; charset=utf-8\x94\x86\x94s\x8c\x11_closable_objects\x94]\x94\x8c\x0e_handler_class\x94N\x8c\acookies\x94\x8c\x0chttp.cookies\x94\x8c\x0cSimpleCookie\x94\x93\x94)\x81\x94\x8c\x06closed\x94\x89\x8c\x0e_reason_phrase\x94N\x8c\b_charset\x94N\x8c\n_container\x94]\x94B\xed\a\x00\x00<!DOCTYPE html>\n\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Buy Products</title>\n    <link href=\"https://fonts.googleapis.com/css?family=Peralta\" rel=\"stylesheet\">\n    <link rel=\"stylesheet\" href=\"/static/css/bootstrap.min.css\">\n    <link rel=\"stylesheet\" href=\"/static/css/app.css\">\n  </head>\n  <body>\n      <div class=\"wrapper\">\n        <div class=\"container\">\n          <ol class=\"breadcrumb my-4\">\n            <li class=\"breadcrumb-item active\" style=\"color: #000;\">Buy Products</li>\n          </ol>\n          <form method=\"post\">\n            <!-- <input type=\"hidden\" name=\"csrfmiddlewaretoken\" value=\"SnsBnyPIwIDejqctR7TMNkITcSafgwiydwsyIiAKQkiSvr3nFA0cm1Tf3Mk6JTPj\"> -->\n            <p><label for=\"id_name\">Name:</label> <select name=\"name\" id=\"id_name\">\n  <option value=\"Redmi note 5\">Product Name: Redmi note 5 \n MRP: 100000 \n  Discounted Price: 45678 \n Description: It's good phone too</option>\n\n  <option value=\"xiomi 2\">Product Name: xiomi 2 \n MRP: 10000 \n  Discounted Price: 200 \n Description: xyz</option>\n\n  <option value=\"mouse\">Product Name: mouse \n MRP: 1400 \n  Discounted Price: 200 \n Description: xyzat</option>\n\n</select></p>\n<p><label for=\"id_user_name\">User name:</label> <textarea name=\"user_name\" cols=\"40\" rows=\"1\" maxlength=\"30\" required id=\"id_user_name\">\n</textarea></p>\n<p><label for=\"id_adress\">Adress:</label> <textarea name=\"adress\" cols=\"40\" rows=\"2\" maxlength=\"4000\" required id=\"id_adress\">\n</textarea></p>\n<p><label for=\"id_mobile\">Mobile:</label> <textarea name=\"mobile\" cols=\"40\" rows=\"1\" maxlength=\"10\" required id=\"id_mobile\">\n</textarea></p>\n<p><label for=\"id_qty\">Qty:</label> <input type=\"number\" name=\"qty\" required id=\"id_qty\"></p>\n            <button type=\"submit\" class=\"btn btn-success\">Buy</button>\n          </form>\n        </div>\n        <div class=\"push\"></div>\n      </div>\n    <script src=\"/static/js/jquery-3.2.1.min.js\"></script>\n    <script src=\"/static/js/popper.min.js\"></script>\n    <script src=\"/static/js/bootstrap.min.js\"></script>\n  </body>\n</html>\n\x94aub."
311647434354.133804 [1 [::1]:59650] "DEL" "c:94c7a9e7f6c7a45ee645caa02f53d000"
32url(r'^order/(?P<usr>\D+)$', views.order, name='ord')
33order.invalidate("http://127.0.0.1:8000/order/demo", "demo")
34order.invalidate("http://127.0.0.1:8000/order/demo", usr="demo")
35

Source https://stackoverflow.com/questions/71510217

QUESTION

Redis NodeJs server error,client is closed

Asked 2022-Feb-11 at 05:16

I am developing an application where chats has to cached and monitored, currently it is an local application where i have installed redis and redis-cli. The problem i'm facing is (node:5368) UnhandledPromiseRejectionWarning: Error: The client is closed Attaching code snippet below

1//redis setup
2const redis = require('redis');
3const client = redis.createClient()//kept blank so that default options are available
4  
5
6//runs when client connects
7io.on("connect", function (socket) {
8
9  //this is client side socket
10  //console.log("a new user connected...");
11
12  socket.on("join", function ({ name, room }, callback) {
13    //console.log(name, room);
14    const { msg, user } = addUser({ id: socket.id, name, room });
15   // console.log(user);
16    if (msg) return callback(msg); //accessible in frontend
17
18    //emit to all users
19    socket.emit("message", {
20      user: "Admin",
21      text: `Welcome to the room ${user.name}`,
22    });
23    //emit to all users except current one
24  
25    socket.broadcast
26      .to(user.room)
27      .emit("message", { user: "Admin", text: `${user.name} has joined` });
28
29    socket.join(user.room); //pass the room that user wants to join
30
31    //get all users in the room
32    io.to(user.room).emit("roomData", {
33      room: user.room,
34      users: getUsersInRoom(user.room),
35    });
36
37    callback();
38  }); //end of join
39
40  //user generated messages
41  socket.on("sendMessage",  async(message, callback)=>{
42    const user = getUser(socket.id);
43
44    //this is where we can store the messages in redis
45    await client.set("messages",message);
46
47    io.to(user.room).emit("message", { user: user.name, text: message });
48    console.log(client.get('messages'));
49    callback();
50  }); //end of sendMessage
51
52  //when user disconnects
53  socket.on("disconnect", function () {
54    const user = removeUser(socket.id);
55    if (user) {
56     
57      console.log(client)
58
59      io.to(user.room).emit("message", {
60        user: "Admin",
61        text: `${user.name} has left `,
62      });
63    }
64  }); //end of disconnect
65
66

I am getting above error when user sends a message to the room or when socket.on("sendMessage") is called.

Where am I going wrong?

Thank you in advance.

ANSWER

Answered 2021-Dec-01 at 20:16

You should await client.connect() before using the client

Source https://stackoverflow.com/questions/70185436

QUESTION

angular 13: Module not found: Error: Can't resolve 'rxjs/operators'

Asked 2022-Jan-22 at 05:29

I have upgraded my angular to angular 13. when I run to build SSR it gives me following error.

1ERROR in ./node_modules/@angular/common/fesm2015/http.mjs 12:0-56
2Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/common/fesm2015'
3Did you mean 'index.js'?
4BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
5(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
6The extension in the request is mandatory for it to be fully specified.
7Add the extension to the request.
8 @ ./src/app/app.server.module.ts 6:0-57 16:25-42
9 @ ./src/main.server.ts 3:0-58 3:0-58
10 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
11
12ERROR in ./node_modules/@angular/core/fesm2015/core.mjs 8:0-39
13Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/core/fesm2015'
14Did you mean 'index.js'?
15BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
16(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
17The extension in the request is mandatory for it to be fully specified.
18Add the extension to the request.
19 @ ./server.ts 30:0-47 35:0-14
20
21ERROR in ./node_modules/@angular/forms/fesm2015/forms.mjs 11:0-37
22Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/forms/fesm2015'
23Did you mean 'index.js'?
24BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
25(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
26The extension in the request is mandatory for it to be fully specified.
27Add the extension to the request.
28 @ ./src/app/app.module.ts 12:0-45 78:12-23
29 @ ./src/app/app.server.module.ts 3:0-41 12:18-27
30 @ ./src/main.server.ts 3:0-58 3:0-58
31 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
32
33ERROR in ./node_modules/@angular/platform-server/fesm2015/platform-server.mjs 21:0-39
34Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/platform-server/fesm2015'
35Did you mean 'index.js'?
36BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
37(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
38The extension in the request is mandatory for it to be fully specified.
39Add the extension to the request.
40 @ ./src/main.server.ts 4:0-77 4:0-77 4:0-77
41 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
42
43ERROR in ./node_modules/@angular/router/fesm2015/router.mjs 10:0-180
44Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/router/fesm2015'
45Did you mean 'index.js'?
46BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
47(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
48The extension in the request is mandatory for it to be fully specified.
49Add the extension to the request.
50 @ ./src/app/app.component.ts 2:0-48 35:31-44
51 @ ./src/app/app.server.module.ts 2:0-47 13:20-32
52 @ ./src/main.server.ts 3:0-58 3:0-58
53 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
54

my package.json file:

1ERROR in ./node_modules/@angular/common/fesm2015/http.mjs 12:0-56
2Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/common/fesm2015'
3Did you mean 'index.js'?
4BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
5(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
6The extension in the request is mandatory for it to be fully specified.
7Add the extension to the request.
8 @ ./src/app/app.server.module.ts 6:0-57 16:25-42
9 @ ./src/main.server.ts 3:0-58 3:0-58
10 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
11
12ERROR in ./node_modules/@angular/core/fesm2015/core.mjs 8:0-39
13Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/core/fesm2015'
14Did you mean 'index.js'?
15BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
16(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
17The extension in the request is mandatory for it to be fully specified.
18Add the extension to the request.
19 @ ./server.ts 30:0-47 35:0-14
20
21ERROR in ./node_modules/@angular/forms/fesm2015/forms.mjs 11:0-37
22Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/forms/fesm2015'
23Did you mean 'index.js'?
24BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
25(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
26The extension in the request is mandatory for it to be fully specified.
27Add the extension to the request.
28 @ ./src/app/app.module.ts 12:0-45 78:12-23
29 @ ./src/app/app.server.module.ts 3:0-41 12:18-27
30 @ ./src/main.server.ts 3:0-58 3:0-58
31 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
32
33ERROR in ./node_modules/@angular/platform-server/fesm2015/platform-server.mjs 21:0-39
34Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/platform-server/fesm2015'
35Did you mean 'index.js'?
36BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
37(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
38The extension in the request is mandatory for it to be fully specified.
39Add the extension to the request.
40 @ ./src/main.server.ts 4:0-77 4:0-77 4:0-77
41 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
42
43ERROR in ./node_modules/@angular/router/fesm2015/router.mjs 10:0-180
44Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/router/fesm2015'
45Did you mean 'index.js'?
46BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
47(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
48The extension in the request is mandatory for it to be fully specified.
49Add the extension to the request.
50 @ ./src/app/app.component.ts 2:0-48 35:31-44
51 @ ./src/app/app.server.module.ts 2:0-47 13:20-32
52 @ ./src/main.server.ts 3:0-58 3:0-58
53 @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
54{
55  "name": "admin-panel",
56  "version": "0.0.0",
57  "license": "MIT",
58  "angular-cli": {},
59  "scripts": {
60    "start": "DEBUG=jobsaf-website:* nodemon --inspect --trace-warnings --legacy-watch  --trace-warnings ./bin/www",
61    "seed": "node ./seeds/static-tables.js",
62    "test-jobsaf": "mocha --timeout 10000",
63    "rm-web": "rm -rf ./public/web/*",
64    "ng": "node ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0",
65    "ng:build": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng  build --configuration production --aot",
66    "build:server:prod": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng run jobsaf-website:server:prod && webpack --config webpack.server.config.js",
67    "build:browser:prod": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng build --configuration production --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer  --progress=true",
68    "build:server:staging": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng run jobsaf-website:server:staging && webpack --config webpack.server.config.js",
69    "build:browser:staging": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng build --configuration production --configuration=staging --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer",
70    "build:stats": "node --max_old_space_size=3192 node_modules/@angular/cli/bin/ng build --configuration production --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer  --progress=true --configuration production --stats-json",
71    "build:prod": "npm run rm-web && npm run build:server:prod && npm run build:browser:prod",
72    "build:staging": "npm run rm-web && npm run build:server:staging && npm run build:browser:staging",
73    "server": "node local.js",
74    "file:migration": "APP_FILE_MIGRATION=true node ./migration/file-migration.js",
75    "test_env": "set NODE_ENV=test",
76    "jest": "jest --detectOpenHandles --watchAll --config ./jest.config.js",
77    "coverage": "jest -i --coverage",
78    "jest:ci": "jest --detectOpenHandles --forceExit --config ./jest.config.js",
79    "test": "npm run test_env && npm run jest",
80    "test:ci": "npm run test_env && npm run seed && npm run jest:ci",
81    "dev:ssr": "ng run jobsaf-website:serve-ssr",
82    "serve:ssr": "node public/web/server/main.js",
83    "build:ssr": "ng build --configuration production && ng run jobsaf-website:server:prod",
84    "prerender": "ng run jobsaf-website:prerender",
85    "postinstall": "ngcc"
86  },
87  "private": true,
88  "napa": {
89    "jquery.flot.spline": "miloszfalinski/jquery.flot.spline",
90    "ika.jvectormap": "kakirigi/ika.jvectormap"
91  },
92  "dependencies": {
93    "@angular/animations": "^13.0.2",
94    "@angular/common": "^13.0.2",
95    "@angular/compiler": "^13.0.2",
96    "@angular/compiler-cli": "^13.0.2",
97    "@angular/core": "^13.0.2",
98    "@angular/forms": "^13.0.2",
99    "@angular/material": "^13.0.2",
100    "@angular/platform-browser": "^13.0.2",
101    "@angular/platform-browser-dynamic": "^13.0.2",
102    "@angular/platform-server": "^13.0.2",
103    "@angular/pwa": "^13.0.3",
104    "@angular/router": "^13.0.2",
105    "@angular/service-worker": "^13.0.2",
106    "@fortawesome/angular-fontawesome": "^0.10.1",
107    "@fortawesome/fontawesome-svg-core": "^1.2.36",
108    "@fortawesome/free-brands-svg-icons": "^5.15.4",
109    "@fortawesome/free-solid-svg-icons": "^5.15.4",
110    "@fullcalendar/core": "^5.10.1",
111    "@hapi/joi": "^15.1.0",
112    "@ng-select/ng-select": "^8.1.1",
113    "@nguniversal/common": "^13.0.1",
114    "@nguniversal/express-engine": "^13.0.1",
115    "@ngx-loading-bar/core": "^5.1.2",
116    "@ngxs/store": "^3.7.3-dev.master-1e7127b",
117    "@schematics/angular": "^13.0.3",
118    "@sindresorhus/slugify": "^1.1.0",
119    "@trademe/ng-defer-load": "^8.2.1",
120    "@types/jquery": "^3.5.8",
121    "angular-archwizard": "^7.0.0",
122    "angular2-uuid": "^1.1.1",
123    "apicache": "^1.6.3",
124    "archiver": "^5.3.0",
125    "aws-sdk": "^2.1031.0",
126    "bluebird": "^3.7.2",
127    "bootstrap": "5.1.3",
128    "compression": "^1.7.4",
129    "compromise": "^13.11.4",
130    "cookie-parser": "^1.4.6",
131    "core-js": "3.19.1",
132    "cors": "~2.8.5",
133    "debug": "^4.3.2",
134    "dotenv": "^10.0.0",
135    "easyimage": "^3.1.1",
136    "ejs": "^3.1.6",
137    "exceljs": "^4.3.0",
138    "express": "^4.17.1",
139    "express-jwt": "^6.1.0",
140    "express-mongo-sanitize": "^2.1.0",
141    "express-rate-limit": "^5.5.1",
142    "express-useragent": "^1.0.15",
143    "express-validator": "^6.13.0",
144    "feed": "^4.2.2",
145    "file-saver": "^2.0.5",
146    "firebase-admin": "^10.0.0",
147    "font-awesome": "^4.7.0",
148    "generate-password": "^1.7.0",
149    "google-auth-library": "^7.10.2",
150    "hammerjs": "^2.0.8",
151    "helmet": "^4.6.0",
152    "html-pdf": "^3.0.1",
153    "http-status": "^1.5.0",
154    "intl-tel-input": "^17.0.13",
155    "izitoast": "1.4.0",
156    "joi-objectid": "^4.0.2",
157    "jquery": "^3.6.0",
158    "jsonwebtoken": "^8.5.1",
159    "jwt-decode": "^3.1.2",
160    "keyword-extractor": "0.0.20",
161    "kickbox": "^2.0.4",
162    "libphonenumber-js": "^1.9.43",
163    "localstorage-polyfill": "^1.0.1",
164    "lodash": "^4.17.21",
165    "lodash.uniq": "^4.5.0",
166    "md5": "^2.3.0",
167    "moment": "^2.29.1",
168    "mongoose": "5.8.11",
169    "mongoose-history": "^0.8.0",
170    "mongoose-unique-validator": "^2.0.3",
171    "mongoose-url-slugs": "^1.0.2",
172    "multer": "^1.4.3",
173    "multer-s3": "^2.10.0",
174    "multer-s3-transform": "^2.10.3",
175    "mysql": "^2.18.1",
176    "ng-recaptcha": "^9.0.0",
177    "ng2-file-upload": "^1.4.0",
178    "ngx-auth": "^5.4.0",
179    "ngx-bootstrap": "^6.1.0",
180    "ngx-facebook": "^3.0.0-0",
181    "ngx-img-cropper": "^11.0.0",
182    "ngx-infinite-scroll": "^10.0.1",
183    "ngx-moment": "^5.0.0",
184    "ngx-pagination": "^5.1.1",
185    "ngx-quill-editor": "^2.2.2",
186    "ngx-toastr": "^14.2.0",
187    "node-schedule": "^2.0.0",
188    "nodemailer": "^6.7.1",
189    "passport": "^0.5.0",
190    "passport-facebook-token": "^4.0.0",
191    "passport-google-id-token": "^0.4.7",
192    "passport-google-token": "^0.1.2",
193    "passport-linkedin-token": "^0.1.1",
194    "passport-local": "^1.0.0",
195    "pdf-to-text": "0.0.7",
196    "phantomjs-prebuilt": "^2.1.16",
197    "phone": "^3.1.10",
198    "phpass": "^0.1.1",
199    "rand-token": "^1.0.1",
200    "request": "^2.88.2",
201    "request-ip": "^2.1.3",
202    "rxjs": "^6.5.5",
203    "sharp": "^0.29.3",
204    "showdown": "^1.9.1",
205    "simple-line-icons": "^2.5.5",
206    "socket.io": "^4.3.2",
207    "socket.io-client": "^4.3.2",
208    "socket.io-redis": "^5.4.0",
209    "socketio-auth": "^0.1.1",
210    "textract": "^2.5.0",
211    "ts-loader": "9.2.6",
212    "underscore": "^1.13.1",
213    "unique-random-array": "^2.0.0",
214    "url": "^0.11.0",
215    "util": "^0.12.4",
216    "uuid": "^8.3.2",
217    "winston": "^3.3.3",
218    "xlsx": "^0.17.4",
219    "xss-clean": "^0.1.1",
220    "zone.js": "~0.11.4",
221    "zxcvbn": "^4.4.2"
222  },
223  "devDependencies": {
224    "@angular-devkit/build-angular": "~13.0.3",
225    "@angular/cli": "^13.0.3",
226    "@types/express": "^4.17.13",
227    "@types/hammerjs": "^2.0.40",
228    "@types/mocha": "^9.0.0",
229    "@types/node": "^16.11.7",
230    "@types/underscore": "^1.11.3",
231    "husky": "^7.0.0",
232    "jasmine-core": "~3.10.1",
233    "jasmine-spec-reporter": "~7.0.0",
234    "jest": "^27.3.1",
235    "karma": "^6.3.9",
236    "karma-chrome-launcher": "~3.1.0",
237    "karma-coverage-istanbul-reporter": "^3.0.3",
238    "karma-jasmine": "~4.0.1",
239    "karma-jasmine-html-reporter": "^1.7.0",
240    "lint-staged": "^12.0.2",
241    "mocha": "^9.1.3",
242    "ng-diff-match-patch": "^3.0.1",
243    "nodemon": "^2.0.15",
244    "protractor": "^7.0.0",
245    "supertest": "^6.1.6",
246    "tslib": "^2.3.1",
247    "tslint": "^6.1.3",
248    "typescript": "4.4.3",
249    "webpack": "^5.64.1",
250    "webpack-cli": "^4.9.1"
251  }
252}
253
254

Any Idea

ANSWER

Answered 2022-Jan-22 at 05:29

I just solve this issue by correcting the RxJS version to 7.4.0. I hope this can solve others issue as well.

Source https://stackoverflow.com/questions/70589846

QUESTION

Celery unable to use redis

Asked 2022-Jan-18 at 05:44

Trying to start Celery first time but issues error as below, i have installed redis and its starting fine , but still somehow django seems to have issues with it ,

1File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3  File "/home/atif/Documents/celery_test/celery-env/lib/python3.8/site-packages/kombu/transport/redis.py", line 263, in <module>
4    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
5AttributeError: 'NoneType' object has no attribute 'Redis'
6

Celery.py

1File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3  File "/home/atif/Documents/celery_test/celery-env/lib/python3.8/site-packages/kombu/transport/redis.py", line 263, in <module>
4    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
5AttributeError: 'NoneType' object has no attribute 'Redis'
6from django.conf import settings
7os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celery_test.settings')
8
9
10
11    app = Celery('celery_test',)
12    
13    app.config_from_object('django.conf:settings')
14    
15    # Load task modules from all registered Django apps.
16    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
17    
18    
19    @app.task(bind=True)
20    def debug_task(self):
21        print(f'Request: {self.request!r}')
22

Settings

1File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3  File "/home/atif/Documents/celery_test/celery-env/lib/python3.8/site-packages/kombu/transport/redis.py", line 263, in <module>
4    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
5AttributeError: 'NoneType' object has no attribute 'Redis'
6from django.conf import settings
7os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celery_test.settings')
8
9
10
11    app = Celery('celery_test',)
12    
13    app.config_from_object('django.conf:settings')
14    
15    # Load task modules from all registered Django apps.
16    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
17    
18    
19    @app.task(bind=True)
20    def debug_task(self):
21        print(f'Request: {self.request!r}')
22#celery stuff ---------------
23BROKER_URL = 'redis://localhost:6379'
24CELERY_RESULT_BACKEND = 'redis://localhost:6379'
25CELERY_ACCEPT_CONTENT = ['application/json']
26CELERY_TASK_SERIALIZER = 'json'
27CELERY_RESULT_SERIALIZER = 'json'
28CELERY_TIMEZONE = 'Asia/Kolkata'
29

celery_module/tasks.py

1File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3  File "/home/atif/Documents/celery_test/celery-env/lib/python3.8/site-packages/kombu/transport/redis.py", line 263, in <module>
4    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
5AttributeError: 'NoneType' object has no attribute 'Redis'
6from django.conf import settings
7os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celery_test.settings')
8
9
10
11    app = Celery('celery_test',)
12    
13    app.config_from_object('django.conf:settings')
14    
15    # Load task modules from all registered Django apps.
16    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
17    
18    
19    @app.task(bind=True)
20    def debug_task(self):
21        print(f'Request: {self.request!r}')
22#celery stuff ---------------
23BROKER_URL = 'redis://localhost:6379'
24CELERY_RESULT_BACKEND = 'redis://localhost:6379'
25CELERY_ACCEPT_CONTENT = ['application/json']
26CELERY_TASK_SERIALIZER = 'json'
27CELERY_RESULT_SERIALIZER = 'json'
28CELERY_TIMEZONE = 'Asia/Kolkata'
29from celery import Celery
30
31app = Celery('tasks',)
32
33@app.task
34def add(x, y):
35    return x + y
36

ANSWER

Answered 2022-Jan-18 at 05:44

Try to install Redis as in your virtual environment as well:

1File "<frozen importlib._bootstrap_external>", line 848, in exec_module
2  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3  File "/home/atif/Documents/celery_test/celery-env/lib/python3.8/site-packages/kombu/transport/redis.py", line 263, in <module>
4    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
5AttributeError: 'NoneType' object has no attribute 'Redis'
6from django.conf import settings
7os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celery_test.settings')
8
9
10
11    app = Celery('celery_test',)
12    
13    app.config_from_object('django.conf:settings')
14    
15    # Load task modules from all registered Django apps.
16    app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
17    
18    
19    @app.task(bind=True)
20    def debug_task(self):
21        print(f'Request: {self.request!r}')
22#celery stuff ---------------
23BROKER_URL = 'redis://localhost:6379'
24CELERY_RESULT_BACKEND = 'redis://localhost:6379'
25CELERY_ACCEPT_CONTENT = ['application/json']
26CELERY_TASK_SERIALIZER = 'json'
27CELERY_RESULT_SERIALIZER = 'json'
28CELERY_TIMEZONE = 'Asia/Kolkata'
29from celery import Celery
30
31app = Celery('tasks',)
32
33@app.task
34def add(x, y):
35    return x + y
36pip install Redis
37

Source https://stackoverflow.com/questions/70164076

QUESTION

Unable to build and deploy Rails 6.0.4.1 app on heroku - Throws gyp verb cli error

Asked 2022-Jan-02 at 10:07

Hi i was deploying a branch on heroku and threw up this error. I also tried deploying a branch which worked perfectly, but that is also showing the same error.

local yarn verion : 1.22.17 local node version : v12.22.7 Please help !!!

Tried building without yarn.lock and package-lock same thing.

This is how it starts Heroku deployment build log through CLI

1yarn install v1.22.17
2remote:        warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
3remote:        [1/5] Validating package.json...
4remote:        [2/5] Resolving packages...
5remote:        [3/5] Fetching packages...
6remote:        [4/5] Linking dependencies...
7remote:        warning " > webpack-dev-server@4.6.0" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0".
8remote:        warning "webpack-dev-server > webpack-dev-middleware@5.2.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
9remote:        [5/5] Building fresh packages...
10remote:        error /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass: Command failed.
11remote:        Exit code: 1
12remote:        Command: node scripts/build.js
13remote:        Arguments: 
14remote:        Directory: /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
15remote:        Output:
16remote:        Building: /tmp/build_df192222/bin/node /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
17remote:        gyp info it worked if it ends with ok
18remote:        gyp verb cli [
19remote:        gyp verb cli   '/tmp/build_df192222/bin/node',
20remote:        gyp verb cli   '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js',
21remote:        gyp verb cli   'rebuild',
22

. . . . . `

1yarn install v1.22.17
2remote:        warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
3remote:        [1/5] Validating package.json...
4remote:        [2/5] Resolving packages...
5remote:        [3/5] Fetching packages...
6remote:        [4/5] Linking dependencies...
7remote:        warning " > webpack-dev-server@4.6.0" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0".
8remote:        warning "webpack-dev-server > webpack-dev-middleware@5.2.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
9remote:        [5/5] Building fresh packages...
10remote:        error /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass: Command failed.
11remote:        Exit code: 1
12remote:        Command: node scripts/build.js
13remote:        Arguments: 
14remote:        Directory: /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
15remote:        Output:
16remote:        Building: /tmp/build_df192222/bin/node /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
17remote:        gyp info it worked if it ends with ok
18remote:        gyp verb cli [
19remote:        gyp verb cli   '/tmp/build_df192222/bin/node',
20remote:        gyp verb cli   '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js',
21remote:        gyp verb cli   'rebuild',
22remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
23remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
24remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
25remote:              |                                      ^~~~~~~~~~~
26remote:              |                                      remove_cv
27remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
28remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
29remote:              |                                      ^~~~~~~~~~~
30remote:              |                                      remove_cv
31remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:50: error: template argument 2 is invalid
32remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
33remote:              |                                                  ^
34remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:63: error: ‘::Perform’ has not been declared
35remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
36remote:              |                                                               ^~~~~~~
37remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render(Nan::NAN_METHOD_ARGS_TYPE)’:
38remote:        ../src/binding.cpp:284:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
39remote:          284 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
40remote:              |                                                                                                  ^~~~~~~~~~~~
41remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render_file(Nan::NAN_METHOD_ARGS_TYPE)’:
42remote:        ../src/binding.cpp:320:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
43remote:          320 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
44remote:              |                                                                                                  ^~~~~~~~~~~~
45remote:        In file included from ../../../../../nan/nan.h:58,
46remote:                         from ../src/binding.cpp:1:
47remote:        ../src/binding.cpp: At global scope:
48remote:        /app/.node-gyp/16.13.1/include/node/node.h:821:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
49remote:          821 |       (node::addon_register_func) (regfunc),                          \
50remote:              |                                           ^
51remote:        /app/.node-gyp/16.13.1/include/node/node.h:855:3: note: in expansion of macro ‘NODE_MODULE_X’
52remote:          855 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
53remote:              |   ^~~~~~~~~~~~~
54remote:        ../src/binding.cpp:358:1: note: in expansion of macro ‘NODE_MODULE’
55remote:          358 | NODE_MODULE(binding, RegisterModule);
56remote:              | ^~~~~~~~~~~
57remote:        make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
58remote:        make: Leaving directory '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass/build'
59remote:        gyp ERR! build error 
60remote:        gyp ERR! stack Error: `make` failed with exit code: 2
61remote:        gyp ERR! stack     at ChildProcess.onExit (/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/lib/build.js:262:23)
62remote:        gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
63remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
64remote:        gyp ERR! System Linux 4.4.0-1097-aws
65remote:        gyp ERR! command "/tmp/build_df192222/bin/node" "/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
66remote:        gyp ERR! cwd /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
67remote:        gyp ERR! node -v v16.13.1
68remote:        gyp ERR! node-gyp -v v3.8.0
69remote:        gyp ERR! not ok 
70remote:        Build failed with error code: 1
71remote: 
72remote:  !
73remote:  !     Precompiling assets failed.
74remote:  !
75remote:  !     Push rejected, failed to compile Ruby app.
76remote: 
77remote:  !     Push failed
78

Though it is a Rails app I added node in engines to package.json.

1yarn install v1.22.17
2remote:        warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
3remote:        [1/5] Validating package.json...
4remote:        [2/5] Resolving packages...
5remote:        [3/5] Fetching packages...
6remote:        [4/5] Linking dependencies...
7remote:        warning " > webpack-dev-server@4.6.0" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0".
8remote:        warning "webpack-dev-server > webpack-dev-middleware@5.2.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
9remote:        [5/5] Building fresh packages...
10remote:        error /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass: Command failed.
11remote:        Exit code: 1
12remote:        Command: node scripts/build.js
13remote:        Arguments: 
14remote:        Directory: /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
15remote:        Output:
16remote:        Building: /tmp/build_df192222/bin/node /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
17remote:        gyp info it worked if it ends with ok
18remote:        gyp verb cli [
19remote:        gyp verb cli   '/tmp/build_df192222/bin/node',
20remote:        gyp verb cli   '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js',
21remote:        gyp verb cli   'rebuild',
22remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
23remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
24remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
25remote:              |                                      ^~~~~~~~~~~
26remote:              |                                      remove_cv
27remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
28remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
29remote:              |                                      ^~~~~~~~~~~
30remote:              |                                      remove_cv
31remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:50: error: template argument 2 is invalid
32remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
33remote:              |                                                  ^
34remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:63: error: ‘::Perform’ has not been declared
35remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
36remote:              |                                                               ^~~~~~~
37remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render(Nan::NAN_METHOD_ARGS_TYPE)’:
38remote:        ../src/binding.cpp:284:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
39remote:          284 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
40remote:              |                                                                                                  ^~~~~~~~~~~~
41remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render_file(Nan::NAN_METHOD_ARGS_TYPE)’:
42remote:        ../src/binding.cpp:320:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
43remote:          320 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
44remote:              |                                                                                                  ^~~~~~~~~~~~
45remote:        In file included from ../../../../../nan/nan.h:58,
46remote:                         from ../src/binding.cpp:1:
47remote:        ../src/binding.cpp: At global scope:
48remote:        /app/.node-gyp/16.13.1/include/node/node.h:821:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
49remote:          821 |       (node::addon_register_func) (regfunc),                          \
50remote:              |                                           ^
51remote:        /app/.node-gyp/16.13.1/include/node/node.h:855:3: note: in expansion of macro ‘NODE_MODULE_X’
52remote:          855 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
53remote:              |   ^~~~~~~~~~~~~
54remote:        ../src/binding.cpp:358:1: note: in expansion of macro ‘NODE_MODULE’
55remote:          358 | NODE_MODULE(binding, RegisterModule);
56remote:              | ^~~~~~~~~~~
57remote:        make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
58remote:        make: Leaving directory '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass/build'
59remote:        gyp ERR! build error 
60remote:        gyp ERR! stack Error: `make` failed with exit code: 2
61remote:        gyp ERR! stack     at ChildProcess.onExit (/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/lib/build.js:262:23)
62remote:        gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
63remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
64remote:        gyp ERR! System Linux 4.4.0-1097-aws
65remote:        gyp ERR! command "/tmp/build_df192222/bin/node" "/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
66remote:        gyp ERR! cwd /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
67remote:        gyp ERR! node -v v16.13.1
68remote:        gyp ERR! node-gyp -v v3.8.0
69remote:        gyp ERR! not ok 
70remote:        Build failed with error code: 1
71remote: 
72remote:  !
73remote:  !     Precompiling assets failed.
74remote:  !
75remote:  !     Push rejected, failed to compile Ruby app.
76remote: 
77remote:  !     Push failed
78{
79  "name": "travel_empire",
80  "private": true,
81  "dependencies": {
82    "@fortawesome/fontawesome-free": "^5.15.4",
83    "@popperjs/core": "^2.10.2",
84    "@rails/actioncable": "^6.0.0",
85    "@rails/activestorage": "^6.0.0",
86    "@rails/ujs": "^6.0.0",
87    "@rails/webpacker": "4.3.0",
88    "bootstrap": "4.3.1",
89    "bootstrap-icons": "^1.5.0",
90    "easy-autocomplete": "^1.3.5",
91    "jquery": "^3.6.0",
92    "jquery-ui-dist": "^1.12.1",
93    "js-autocomplete": "^1.0.4",
94    "node-sass": "^7.0.0",
95    "popper.js": "^1.16.1",
96    "turbolinks": "^5.2.0"
97  },
98  "version": "0.1.0",
99  "devDependencies": {
100    "webpack-dev-server": "^4.6.0"
101  },
102  "engines": {
103    "node": "16.x"
104  }
105}
106

Gemfile

1yarn install v1.22.17
2remote:        warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
3remote:        [1/5] Validating package.json...
4remote:        [2/5] Resolving packages...
5remote:        [3/5] Fetching packages...
6remote:        [4/5] Linking dependencies...
7remote:        warning " > webpack-dev-server@4.6.0" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0".
8remote:        warning "webpack-dev-server > webpack-dev-middleware@5.2.1" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
9remote:        [5/5] Building fresh packages...
10remote:        error /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass: Command failed.
11remote:        Exit code: 1
12remote:        Command: node scripts/build.js
13remote:        Arguments: 
14remote:        Directory: /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
15remote:        Output:
16remote:        Building: /tmp/build_df192222/bin/node /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
17remote:        gyp info it worked if it ends with ok
18remote:        gyp verb cli [
19remote:        gyp verb cli   '/tmp/build_df192222/bin/node',
20remote:        gyp verb cli   '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js',
21remote:        gyp verb cli   'rebuild',
22remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
23remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
24remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
25remote:              |                                      ^~~~~~~~~~~
26remote:              |                                      remove_cv
27remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’; did you mean ‘remove_cv’?
28remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
29remote:              |                                      ^~~~~~~~~~~
30remote:              |                                      remove_cv
31remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:50: error: template argument 2 is invalid
32remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
33remote:              |                                                  ^
34remote:        /app/.node-gyp/16.13.1/include/node/v8-internal.h:492:63: error: ‘::Perform’ has not been declared
35remote:          492 |             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
36remote:              |                                                               ^~~~~~~
37remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render(Nan::NAN_METHOD_ARGS_TYPE)’:
38remote:        ../src/binding.cpp:284:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
39remote:          284 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
40remote:              |                                                                                                  ^~~~~~~~~~~~
41remote:        ../src/binding.cpp: In function ‘Nan::NAN_METHOD_RETURN_TYPE render_file(Nan::NAN_METHOD_ARGS_TYPE)’:
42remote:        ../src/binding.cpp:320:98: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
43remote:          320 |     int status = uv_queue_work(uv_default_loop(), &ctx_w->request, compile_it, (uv_after_work_cb)MakeCallback);
44remote:              |                                                                                                  ^~~~~~~~~~~~
45remote:        In file included from ../../../../../nan/nan.h:58,
46remote:                         from ../src/binding.cpp:1:
47remote:        ../src/binding.cpp: At global scope:
48remote:        /app/.node-gyp/16.13.1/include/node/node.h:821:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
49remote:          821 |       (node::addon_register_func) (regfunc),                          \
50remote:              |                                           ^
51remote:        /app/.node-gyp/16.13.1/include/node/node.h:855:3: note: in expansion of macro ‘NODE_MODULE_X’
52remote:          855 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
53remote:              |   ^~~~~~~~~~~~~
54remote:        ../src/binding.cpp:358:1: note: in expansion of macro ‘NODE_MODULE’
55remote:          358 | NODE_MODULE(binding, RegisterModule);
56remote:              | ^~~~~~~~~~~
57remote:        make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
58remote:        make: Leaving directory '/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass/build'
59remote:        gyp ERR! build error 
60remote:        gyp ERR! stack Error: `make` failed with exit code: 2
61remote:        gyp ERR! stack     at ChildProcess.onExit (/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/lib/build.js:262:23)
62remote:        gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
63remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
64remote:        gyp ERR! System Linux 4.4.0-1097-aws
65remote:        gyp ERR! command "/tmp/build_df192222/bin/node" "/tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
66remote:        gyp ERR! cwd /tmp/build_df192222/node_modules/@rails/webpacker/node_modules/node-sass
67remote:        gyp ERR! node -v v16.13.1
68remote:        gyp ERR! node-gyp -v v3.8.0
69remote:        gyp ERR! not ok 
70remote:        Build failed with error code: 1
71remote: 
72remote:  !
73remote:  !     Precompiling assets failed.
74remote:  !
75remote:  !     Push rejected, failed to compile Ruby app.
76remote: 
77remote:  !     Push failed
78{
79  "name": "travel_empire",
80  "private": true,
81  "dependencies": {
82    "@fortawesome/fontawesome-free": "^5.15.4",
83    "@popperjs/core": "^2.10.2",
84    "@rails/actioncable": "^6.0.0",
85    "@rails/activestorage": "^6.0.0",
86    "@rails/ujs": "^6.0.0",
87    "@rails/webpacker": "4.3.0",
88    "bootstrap": "4.3.1",
89    "bootstrap-icons": "^1.5.0",
90    "easy-autocomplete": "^1.3.5",
91    "jquery": "^3.6.0",
92    "jquery-ui-dist": "^1.12.1",
93    "js-autocomplete": "^1.0.4",
94    "node-sass": "^7.0.0",
95    "popper.js": "^1.16.1",
96    "turbolinks": "^5.2.0"
97  },
98  "version": "0.1.0",
99  "devDependencies": {
100    "webpack-dev-server": "^4.6.0"
101  },
102  "engines": {
103    "node": "16.x"
104  }
105}
106source 'https://rubygems.org'
107git_source(:github) { |repo| "https://github.com/#{repo}.git" }
108
109ruby '2.7.3'
110
111# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
112gem 'rails', '~> 6.0.3', '>= 6.0.3.7'
113
114gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git'
115
116
117# Use Puma as the app server
118gem 'puma', '~> 4.1'
119# Use SCSS for stylesheets
120gem 'sass-rails', '>= 6'
121# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
122gem 'webpacker', '~> 4.0'
123# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
124gem 'turbolinks', '~> 5'
125# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
126gem 'jbuilder', '~> 2.7'
127# Use Redis adapter to run Action Cable in production
128# gem 'redis', '~> 4.0'
129# Use Active Model has_secure_password
130
131
132# Use Active Storage variant
133# gem 'image_processing', '~> 1.2'
134
135
136gem 'axlsx'
137gem 'caxlsx_rails'
138
139
140#Bootstrap for UI
141gem 'bootstrap', '~> 5.1.0'
142gem 'bootstrap-timepicker-rails', '~> 0.1.3'
143gem 'bootstrap-select-rails', '~> 1.6', '>= 1.6.3'
144#JQuery Rails
145gem 'jquery-rails'
146
147 gem 'rails_12factor', group: :production
148# Reduces boot times through caching; required in config/boot.rb
149gem 'bootsnap', '>= 1.4.2', require: false
150
151group :development, :test do
152  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
153  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
154end
155
156group :development do
157  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
158  gem 'web-console', '>= 3.3.0'
159  gem 'listen', '~> 3.2'
160  gem 'pry'
161  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
162  gem 'spring'
163  gem 'spring-watcher-listen', '~> 2.0.0'
164end
165
166group :test do
167  # Adds support for Capybara system testing and selenium driver
168  gem 'capybara', '>= 2.15'
169  gem 'selenium-webdriver'
170  # Easy installation and use of web drivers to run system tests with browsers
171  gem 'webdrivers'
172  gem 'cucumber-rails', require: false
173  gem 'database_cleaner'
174end
175
176# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
177gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
178
179#HTTParty for RESTful API calls
180gem 'httparty'
181
182
183#Paperclip for storing files
184gem 'paperclip'
185gem "mongoid-paperclip", :require => "mongoid_paperclip"
186
187gem "letter_opener", :group => :development
188

ANSWER

Answered 2021-Dec-18 at 14:32

I had a similar problem but resolved by following steps.

  1. Run the following command. heroku buildpacks:add heroku/nodejs --index 1
  2. Update node version from 16.x to 12.16.2 in package.json.

Source https://stackoverflow.com/questions/70401055

QUESTION

Why the swagger doesn't open in .NET 6?

Asked 2021-Dec-15 at 15:11

Well, I was doing a DDD project, specifically using redis, but I don't think that has anything to do with it.

The problem is, the swagger doesn't appear to me, it fails, but when I make requests in postman it works normally.

Thats the error:

1 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
2  An unhandled exception has occurred while executing the request.
3  System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Metadata.ITagsMetadata' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
4     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultTagsSelector(ApiDescription apiDescription)
5     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultSortKeySelector(ApiDescription apiDescription) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x600012d+0x0
6     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) in System.Linq.dll:token 0x600040b+0x10
7     at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000401+0x0
8     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000402+0x0
9     at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext() in System.Linq.dll:token 0x6000391+0x3d
10     at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) in System.Linq.dll:token 0x6000366+0x2b
11     at System.Linq.GroupedEnumerable`2.GetEnumerator() in System.Linq.dll:token 0x600035f+0x0
12     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f8+0x3a
13     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f6+0xe6
14     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) in Swashbuckle.AspNetCore.Swagger.dll:token 0x6000009+0xe2
15     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) in Microsoft.AspNetCore.Diagnostics.dll:token 0x60000aa+0x82
16

Startup file (ConfigureServices):

1 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
2  An unhandled exception has occurred while executing the request.
3  System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Metadata.ITagsMetadata' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
4     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultTagsSelector(ApiDescription apiDescription)
5     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultSortKeySelector(ApiDescription apiDescription) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x600012d+0x0
6     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) in System.Linq.dll:token 0x600040b+0x10
7     at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000401+0x0
8     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000402+0x0
9     at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext() in System.Linq.dll:token 0x6000391+0x3d
10     at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) in System.Linq.dll:token 0x6000366+0x2b
11     at System.Linq.GroupedEnumerable`2.GetEnumerator() in System.Linq.dll:token 0x600035f+0x0
12     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f8+0x3a
13     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f6+0xe6
14     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) in Swashbuckle.AspNetCore.Swagger.dll:token 0x6000009+0xe2
15     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) in Microsoft.AspNetCore.Diagnostics.dll:token 0x60000aa+0x82
16public void ConfigureServices(IServiceCollection services)
17{
18        services.AddRedisContext(Configuration);
19        services.AddControllers();
20        services.AddSwaggerGen(c =>
21        {
22            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Basket.Api", Version = "v1" 
23        });
24});
25

My method in extension method class:

1 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
2  An unhandled exception has occurred while executing the request.
3  System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Metadata.ITagsMetadata' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
4     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultTagsSelector(ApiDescription apiDescription)
5     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultSortKeySelector(ApiDescription apiDescription) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x600012d+0x0
6     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) in System.Linq.dll:token 0x600040b+0x10
7     at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000401+0x0
8     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000402+0x0
9     at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext() in System.Linq.dll:token 0x6000391+0x3d
10     at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) in System.Linq.dll:token 0x6000366+0x2b
11     at System.Linq.GroupedEnumerable`2.GetEnumerator() in System.Linq.dll:token 0x600035f+0x0
12     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f8+0x3a
13     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f6+0xe6
14     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) in Swashbuckle.AspNetCore.Swagger.dll:token 0x6000009+0xe2
15     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) in Microsoft.AspNetCore.Diagnostics.dll:token 0x60000aa+0x82
16public void ConfigureServices(IServiceCollection services)
17{
18        services.AddRedisContext(Configuration);
19        services.AddControllers();
20        services.AddSwaggerGen(c =>
21        {
22            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Basket.Api", Version = "v1" 
23        });
24});
25public static IServiceCollection AddRedisContext(this IServiceCollection services, IConfiguration config)
26{
27        services.AddStackExchangeRedisCache(options =>
28        {                
29            options.Configuration = config["CacheSettings:ConnectionString"];
30        });
31
32        services.AddScoped<IBasketRepository, BasketRepository>();
33        services.AddScoped<IBasketService, BasketService>();
34
35        return services;
36 }
37

The Package reference:

1 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
2  An unhandled exception has occurred while executing the request.
3  System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Metadata.ITagsMetadata' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
4     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultTagsSelector(ApiDescription apiDescription)
5     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.DefaultSortKeySelector(ApiDescription apiDescription) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x600012d+0x0
6     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) in System.Linq.dll:token 0x600040b+0x10
7     at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000401+0x0
8     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) in System.Linq.dll:token 0x6000402+0x0
9     at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext() in System.Linq.dll:token 0x6000391+0x3d
10     at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) in System.Linq.dll:token 0x6000366+0x2b
11     at System.Linq.GroupedEnumerable`2.GetEnumerator() in System.Linq.dll:token 0x600035f+0x0
12     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f8+0x3a
13     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) in Swashbuckle.AspNetCore.SwaggerGen.dll:token 0x60000f6+0xe6
14     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) in Swashbuckle.AspNetCore.Swagger.dll:token 0x6000009+0xe2
15     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) in Microsoft.AspNetCore.Diagnostics.dll:token 0x60000aa+0x82
16public void ConfigureServices(IServiceCollection services)
17{
18        services.AddRedisContext(Configuration);
19        services.AddControllers();
20        services.AddSwaggerGen(c =>
21        {
22            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Basket.Api", Version = "v1" 
23        });
24});
25public static IServiceCollection AddRedisContext(this IServiceCollection services, IConfiguration config)
26{
27        services.AddStackExchangeRedisCache(options =>
28        {                
29            options.Configuration = config["CacheSettings:ConnectionString"];
30        });
31
32        services.AddScoped<IBasketRepository, BasketRepository>();
33        services.AddScoped<IBasketService, BasketService>();
34
35        return services;
36 }
37<Project Sdk="Microsoft.NET.Sdk.Web">
38
39  <PropertyGroup>
40    <TargetFramework>net6.0</TargetFramework>
41  </PropertyGroup>
42
43  <ItemGroup>    
44    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
45  </ItemGroup>
46
47  <ItemGroup>
48    <ProjectReference Include="..\Basket.Infra.Data\Basket.Infra.Data.csproj" />
49  </ItemGroup>
50
51</Project>
52

I also commented the lines referring to redis and it still gave the same error. So it's almost certainly something involving the swagger.

ANSWER

Answered 2021-Dec-15 at 15:11

In my case, it was the SDK not running the proper net6.0 version.

While the whole project was using new net6.0 NuGet packages, the local SDK on that one machine I was working on was still net5.0. After installing .net6.0, Swashbuckle 6.2.3 was working again, and all was as expected.

Source https://stackoverflow.com/questions/69861755

QUESTION

log4shell exploit for Redis server

Asked 2021-Dec-12 at 21:27

We are running redis server on EC2 instance.

i can see in many publications that Redis Server is vulnerable to the log4shell exploit, but can't see any documentation or any official about that.

What should I do in order to protect my redis server instance to be in-vulnerable for this exploit?

ANSWER

Answered 2021-Dec-12 at 21:27

Redis Server does not use Java and is therefore not impacted by this vulnerability.

See more here: https://redis.com/security/notice-apache-log4j2-cve-2021-44228/

Source https://stackoverflow.com/questions/70322115

QUESTION

Docker image does not run with specified Python version

Asked 2021-Oct-08 at 00:53

I have a Dockerfile

1FROM python:3.7.12-slim-buster
2FROM aaftio/face_recognition
3RUN pip install redis
4RUN pip3 install glob2
5
6RUN pip install face_recognition
7COPY ./worker.py /worker.py
8COPY ./rediswq.py /rediswq.py
9
10CMD  python3 worker.py
11

I build the image and run my image with docker run -it {image_id}, but I see errors from python app - It complains about f-strings syntax as it is supported since python 3.6 I address that it uses some older python.

I debugged and get python version it printed 1.19.0

The error:

1FROM python:3.7.12-slim-buster
2FROM aaftio/face_recognition
3RUN pip install redis
4RUN pip3 install glob2
5
6RUN pip install face_recognition
7COPY ./worker.py /worker.py
8COPY ./rediswq.py /rediswq.py
9
10CMD  python3 worker.py
11      File "worker.py", line 14
12    for filename in glob.iglob(f"/root/divisions/{division_number}/" + '**/*.*', recursive=True):
13                                                                   ^
14SyntaxError: invalid syntax
15

I debugged and executed whereis python3 and the output is

1FROM python:3.7.12-slim-buster
2FROM aaftio/face_recognition
3RUN pip install redis
4RUN pip3 install glob2
5
6RUN pip install face_recognition
7COPY ./worker.py /worker.py
8COPY ./rediswq.py /rediswq.py
9
10CMD  python3 worker.py
11      File "worker.py", line 14
12    for filename in glob.iglob(f"/root/divisions/{division_number}/" + '**/*.*', recursive=True):
13                                                                   ^
14SyntaxError: invalid syntax
15python3: /usr/bin/python3.5m-config /usr/bin/python3.5 /usr/bin/python3 /usr/bin/python3.5-config /usr/bin/python3.5m /usr/lib/python3 /usr/lib/python3.5 /etc/python3.5 /etc/python3 /usr/local/bin/python3.4m-config /usr/local/bin/python3.4m /usr/local/bin/python3.4 /usr/local/bin/python3 /usr/local/bin/python3.4-config /usr/local/lib/python3.4 /usr/local/lib/python3.5 /usr/include/python3.5 /usr/include/python3.5m /usr/share/python3
16

ANSWER

Answered 2021-Oct-08 at 00:53

The error is in the way you have defined the Dockerfile

While creating a docker multi stage build, your final container will always be based off the last docker container you have referenced

So in your case it will be aaftio/face_recognition which uses Python 3.4.9 and not python:3.7.12-slim-buster which uses Python 3.7.12

Reference for docker multi stage build - here

You can try something like this

1FROM python:3.7.12-slim-buster
2FROM aaftio/face_recognition
3RUN pip install redis
4RUN pip3 install glob2
5
6RUN pip install face_recognition
7COPY ./worker.py /worker.py
8COPY ./rediswq.py /rediswq.py
9
10CMD  python3 worker.py
11      File "worker.py", line 14
12    for filename in glob.iglob(f"/root/divisions/{division_number}/" + '**/*.*', recursive=True):
13                                                                   ^
14SyntaxError: invalid syntax
15python3: /usr/bin/python3.5m-config /usr/bin/python3.5 /usr/bin/python3 /usr/bin/python3.5-config /usr/bin/python3.5m /usr/lib/python3 /usr/lib/python3.5 /etc/python3.5 /etc/python3 /usr/local/bin/python3.4m-config /usr/local/bin/python3.4m /usr/local/bin/python3.4 /usr/local/bin/python3 /usr/local/bin/python3.4-config /usr/local/lib/python3.4 /usr/local/lib/python3.5 /usr/include/python3.5 /usr/include/python3.5m /usr/share/python3
16FROM aaftio/face_recognition as intermediate
17RUN pip install face_recognition
18
19
20FROM python:3.7.12-slim-buster
21
22#Copy the python installed libraries from intermediate container
23#COPY --from=intermediate face_recognition
24
25RUN pip install redis
26RUN pip3 install glob2
27COPY ./worker.py /worker.py
28COPY ./rediswq.py /rediswq.py
29
30CMD  python3 worker.py
31

Source https://stackoverflow.com/questions/69486935

QUESTION

Bitnami Redis on Kubernetes Authentication Failure with Existing Secret

Asked 2021-Sep-02 at 12:07

I'm trying to install Redis on Kubernetes environment with Bitnami Redis HELM Chart. I want to use a defined password rather than randomly generated one. But i'm getting error below when i want to connect to redis master or replicas with redis-cli.

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4

I created a Kubernetes secret like this.

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13

And in values.yaml file i updated auth spec like below.

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19

If i don't define existingSecret field and use randomly generated password then i can connect without an issue. I also tried AUTH admin1234 after Warning: AUTH failed error but it didn't work either.

ANSWER

Answered 2021-Aug-30 at 14:59

You can achieve it in much simpler way i.e. by running:

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19$ helm install my-release \
20  --set auth.password="admin1234" \
21    bitnami/redis
22

This will update your "my-release-redis" secret, so when you run:

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19$ helm install my-release \
20  --set auth.password="admin1234" \
21    bitnami/redis
22$ kubectl get secrets my-release-redis -o yaml
23

you'll see it contains your password, already base64-encoded:

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19$ helm install my-release \
20  --set auth.password="admin1234" \
21    bitnami/redis
22$ kubectl get secrets my-release-redis -o yaml
23apiVersion: v1
24data:
25  redis-password: YWRtaW4xMjM0Cg==
26kind: Secret
27...
28

In order to get your password, you need to run:

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19$ helm install my-release \
20  --set auth.password="admin1234" \
21    bitnami/redis
22$ kubectl get secrets my-release-redis -o yaml
23apiVersion: v1
24data:
25  redis-password: YWRtaW4xMjM0Cg==
26kind: Secret
27...
28export REDIS_PASSWORD=$(kubectl get secret --namespace default my-release-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
29

This will set and export REDIS_PASSWORD environment variable containing your redis password.

And then you may run your redis-client pod:

1I have no name!@redis-client:/$ redis-cli -h redis-master -a $REDIS_PASSWORD 
2Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
3Warning: AUTH failed
4---
5apiVersion: v1
6kind: Secret
7metadata:
8  name: redis-secret
9  namespace: redis
10type: Opaque
11data:
12  redis-password: YWRtaW4xMjM0Cg==
13auth:
14  enabled: true
15  sentinel: false
16  existingSecret: "redis-secret"
17  existingSecretPasswordKey: "redis-password"
18  usePasswordFiles: false
19$ helm install my-release \
20  --set auth.password="admin1234" \
21    bitnami/redis
22$ kubectl get secrets my-release-redis -o yaml
23apiVersion: v1
24data:
25  redis-password: YWRtaW4xMjM0Cg==
26kind: Secret
27...
28export REDIS_PASSWORD=$(kubectl get secret --namespace default my-release-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
29kubectl run --namespace default redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:6.2.4-debian-10-r13 --command -- sleep infinity
30

which will set REDIS_PASSWORD environment variable within your redis-client pod by assigning to it the value of REDIS_PASSWORD set locally in the previous step.

Source https://stackoverflow.com/questions/68960083

QUESTION

Removed Node.js v15 from list of versions, but Github Actions still shows it in list of checks

Asked 2021-Aug-30 at 17:46

I initially had Github Actions set up to run unit tests using node versions 14, 15, 16.

However I've since removed 15.x from the list. This is what it looks like now:

1name: Compliance
2
3on: pull_request
4
5jobs:
6  build:
7
8    runs-on: ubuntu-latest
9
10    services:
11      redis:
12        image: redis
13        # Set health checks to wait until redis has started
14        options: >-
15          --health-cmd "redis-cli ping"
16          --health-interval 10s
17          --health-timeout 5s
18          --health-retries 5
19
20    strategy:
21      matrix:
22        node-version: [14.x, 16.x]
23
24    steps:
25      ....
26

The checks list shows the proper title for versions 14 and 16, however there's a build 15 afterward that obviously never runs (and therefore never completes) and my PRs never get a green checkmark.

1name: Compliance
2
3on: pull_request
4
5jobs:
6  build:
7
8    runs-on: ubuntu-latest
9
10    services:
11      redis:
12        image: redis
13        # Set health checks to wait until redis has started
14        options: >-
15          --health-cmd "redis-cli ping"
16          --health-interval 10s
17          --health-timeout 5s
18          --health-retries 5
19
20    strategy:
21      matrix:
22        node-version: [14.x, 16.x]
23
24    steps:
25      ....
26CodeQL / Analyze (javascript) (pull_request) Successful in 1m
27Compliance / build (14.x) (pull_request) Successful in 2m
28Compliance / build (16.x) (pull_request) Successful in 1m
29build (15.x) Expected — Waiting for status to be reported
30Code scanning results / CodeQL Successful in 3s — No new or fixed alerts
31

I've searched through my .github/* files with no mention of 15 anywhere. I'm at a loss as to where I can find and remove this ghost entry for a no longer relevant version in the matrix.

ANSWER

Answered 2021-Aug-30 at 17:46

The problem here was that the master branch has a set of required checks, which you must name specifically by their job (and node version) name. eg. build 15.x.

It took some digging as this is not directly obvious, however in the repository settings -> branches -> master [edit] page, you can add/remove the status checks which must pass.

Source https://stackoverflow.com/questions/68973531

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Redis

Tutorials and Learning Resources are not available at this moment for Redis

Share this Page

share link

Get latest updates on Redis