Guest User

Untitled

a guest
Dec 18th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. @task
  2. def send(text):
  3. try:
  4. bot = telebot.TeleBot('token******')
  5.  
  6. for user in BotUser.objects.all():
  7.  
  8. try:
  9. bot.send_message(user.chat_id, text)
  10. except:
  11. pass
  12.  
  13. except Exception as e:
  14. print(e)
  15. bot.send_message(359144124, str(e))
  16.  
  17.  
  18. class Dispatch(models.Model):
  19. text = models.TextField(null=True, blank=True)
  20.  
  21. def __str__(self):
  22. return self.text
  23.  
  24. class Meta:
  25. verbose_name = 'Рассылка'
  26. verbose_name_plural = 'Рассылка'
  27.  
  28. def save(self, *args, **kwargs):
  29. if self.pk is None:
  30. send.apply_async((self.text,))
  31.  
  32. super(Dispatch, self).save(*args, **kwargs)
  33.  
  34. from __future__ import absolute_import, unicode_literals
  35. import os
  36. from celery import Celery
  37. from celery.schedules import crontab
  38. from django.conf import settings
  39.  
  40.  
  41. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'franch2.settings')
  42.  
  43. app = Celery('franch2')
  44.  
  45.  
  46. app.config_from_object('django.conf:settings')
  47. app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
  48.  
  49. -------------- celery@cs158429 v4.1.0 (latentcall)
  50. ---- **** -----
  51. --- * *** * -- Linux-4.4.0-103-generic-x86_64-with-Ubuntu-16.04-xenial 2017-12-19 01:14:44
  52. -- * - **** ---
  53. - ** ---------- [config]
  54. - ** ---------- .> app: franch2:0x7f06e71b4f28
  55. - ** ---------- .> transport: redis://localhost:6379//
  56. - ** ---------- .> results: redis://localhost:6379/
  57. - *** --- * --- .> concurrency: 1 (prefork)
  58. -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
  59. --- ***** -----
  60. -------------- [queues]
  61. .> celery exchange=celery(direct) key=celery
  62.  
  63.  
  64. [tasks]
  65. . bot.models.send
  66.  
  67. [2017-12-19 01:14:44,648: INFO/MainProcess] Connected to redis://localhost:6379//
  68. [2017-12-19 01:14:44,660: INFO/MainProcess] mingle: searching for neighbors
  69. [2017-12-19 01:14:45,706: INFO/MainProcess] mingle: all alone
  70. [2017-12-19 01:14:45,731: INFO/MainProcess] celery@cs158429 ready.
  71. [2017-12-19 01:15:25,830: ERROR/MainProcess] Process 'ForkPoolWorker-1' pid:16260 exited with 'signal 9 (SIGKILL)'
Add Comment
Please, Sign In to add comment