Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @task
- def send(text):
- try:
- bot = telebot.TeleBot('token******')
- for user in BotUser.objects.all():
- try:
- bot.send_message(user.chat_id, text)
- except:
- pass
- except Exception as e:
- print(e)
- bot.send_message(359144124, str(e))
- class Dispatch(models.Model):
- text = models.TextField(null=True, blank=True)
- def __str__(self):
- return self.text
- class Meta:
- verbose_name = 'Рассылка'
- verbose_name_plural = 'Рассылка'
- def save(self, *args, **kwargs):
- if self.pk is None:
- send.apply_async((self.text,))
- super(Dispatch, self).save(*args, **kwargs)
- from __future__ import absolute_import, unicode_literals
- import os
- from celery import Celery
- from celery.schedules import crontab
- from django.conf import settings
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'franch2.settings')
- app = Celery('franch2')
- app.config_from_object('django.conf:settings')
- app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
- -------------- celery@cs158429 v4.1.0 (latentcall)
- ---- **** -----
- --- * *** * -- Linux-4.4.0-103-generic-x86_64-with-Ubuntu-16.04-xenial 2017-12-19 01:14:44
- -- * - **** ---
- - ** ---------- [config]
- - ** ---------- .> app: franch2:0x7f06e71b4f28
- - ** ---------- .> transport: redis://localhost:6379//
- - ** ---------- .> results: redis://localhost:6379/
- - *** --- * --- .> concurrency: 1 (prefork)
- -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
- --- ***** -----
- -------------- [queues]
- .> celery exchange=celery(direct) key=celery
- [tasks]
- . bot.models.send
- [2017-12-19 01:14:44,648: INFO/MainProcess] Connected to redis://localhost:6379//
- [2017-12-19 01:14:44,660: INFO/MainProcess] mingle: searching for neighbors
- [2017-12-19 01:14:45,706: INFO/MainProcess] mingle: all alone
- [2017-12-19 01:14:45,731: INFO/MainProcess] celery@cs158429 ready.
- [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