# Path: django_eventstream/eventstream.py
# def send_event(channel, event_type, data, skip_user_ids=None, async_publish=True, json_encode=True):
# 	from .event import Event
# 
# 	if skip_user_ids is None:
# 		skip_user_ids = []
# 
# 	storage = get_storage()
# 	channelmanager = get_channelmanager()
# 
# 	if channelmanager.is_channel_reliable(channel) and storage:
# 		e = storage.append_event(channel, event_type, data)
# 		pub_id = str(e.id)
# 		pub_prev_id = str(e.id - 1)
# 	else:
# 		e = Event(channel, event_type, data)
# 		pub_id = None
# 		pub_prev_id = None
# 
# 	if have_channels():
# 		from .consumers import get_listener_manager
# 		# send to local listeners
# 		get_listener_manager().add_to_queues(channel, e)
# 
# 	# publish through grip proxy
# 	publish_event(
# 		channel,
# 		event_type,
# 		data,
# 		pub_id,
# 		pub_prev_id,
# 		skip_user_ids=skip_user_ids,
# 		blocking=(not async_publish),
# 		json_encode=json_encode)


import time
import datetime
import threading
from django.apps import AppConfig
from django_eventstream import send_event
    from django.db import DatabaseError
    from django_eventstream.models import Event

class TimeappConfig(AppConfig):
    name = 'timeapp'

    def ready(self):
        ensure_worker_started()


worker_started = False


def ensure_worker_started():
    global worker_started

    if worker_started:
        return

    if not is_db_ready():
        return

    worker_started = True

    thread = threading.Thread(target=send_worker)
    thread.daemon = True
    thread.start()


def send_worker():
    while True:
        data = datetime.datetime.utcnow().isoformat()

# Path: django_eventstream/eventstream.py
# def send_event(channel, event_type, data, skip_user_ids=None, async_publish=True, json_encode=True):
# 	from .event import Event
# 
# 	if skip_user_ids is None:
# 		skip_user_ids = []
# 
# 	storage = get_storage()
# 	channelmanager = get_channelmanager()
# 
# 	if channelmanager.is_channel_reliable(channel) and storage:
# 		e = storage.append_event(channel, event_type, data)
# 		pub_id = str(e.id)
# 		pub_prev_id = str(e.id - 1)
# 	else:
# 		e = Event(channel, event_type, data)
# 		pub_id = None
# 		pub_prev_id = None
# 
# 	if have_channels():
# 		from .consumers import get_listener_manager
# 		# send to local listeners
# 		get_listener_manager().add_to_queues(channel, e)
# 
# 	# publish through grip proxy
# 	publish_event(
# 		channel,
# 		event_type,
# 		data,
# 		pub_id,
# 		pub_prev_id,
# 		skip_user_ids=skip_user_ids,
# 		blocking=(not async_publish),
# 		json_encode=json_encode)


# Path: examples/time/timeapp/apps.py
import time
import datetime
import threading
from django.apps import AppConfig
from django_eventstream import send_event
    from django.db import DatabaseError
    from django_eventstream.models import Event


class TimeappConfig(AppConfig):
    name = 'timeapp'

    def ready(self):
        ensure_worker_started()


worker_started = False


def ensure_worker_started():
    global worker_started

    if worker_started:
        return

    if not is_db_ready():
        return

    worker_started = True

    thread = threading.Thread(target=send_worker)
    thread.daemon = True
    thread.start()


def send_worker():
    while True:
        data = datetime.datetime.utcnow().isoformat()

        send_event('time', 'message', data)