Store a new announcement locally, atomically.
349321
def store_announcement( working_dir, announcement_hash, announcement_text, force=False ):
   

   if not force:
       # don't store unless we haven't seen it before
       if announcement_hash in ANNOUNCEMENTS:
           return

   announce_filename = get_announce_filename( working_dir )
   announce_filename_tmp = announce_filename + ".tmp"
   announce_text = ""
   announce_cleanup_list = []

   # did we try (and fail) to store a previous announcement?  If so, merge them all
   if os.path.exists( announce_filename_tmp ):

       log.debug("Merge announcement list %s" % announce_filename_tmp )

       with open(announce_filename, "r") as f:
           announce_text += f.read()

       i = 1
       failed_path = announce_filename_tmp + (".%s" % i)
       while os.path.exists( failed_path ):

           log.debug("Merge announcement list %s" % failed_path )
           with open(failed_path, "r") as f:
               announce_text += f.read()

           announce_cleanup_list.append( failed_path )

           i += 1
           failed_path = announce_filename_tmp + (".%s" % i)

       announce_filename_tmp = failed_path

   if os.path.exists( announce_filename ):
       with open(announce_filename, "r" ) as f:
           announce_text += f.read()

   announce_text += ("\n%s\n" % announcement_hash)

   # filter
   if not force:
       announcement_list = announce_text.split("\n")
       unseen_announcements = filter( lambda a: a not in ANNOUNCEMENTS, announcement_list )
       announce_text = "\n".join( unseen_announcements ).strip() + "\n"

   log.debug("Store announcement hash to %s" % announce_filename )

   with open(announce_filename_tmp, "w" ) as f:
       f.write( announce_text )
       f.flush()

   # NOTE: rename doesn't remove the old file on Windows
   if sys.platform == 'win32' and os.path.exists( announce_filename_tmp ):
       try:
           os.unlink( announce_filename_tmp )
       except:
           pass

   try:
       os.rename( announce_filename_tmp, announce_filename )
   except:
       log.error("Failed to save announcement %s to %s" % (announcement_hash, announce_filename ))
       raise

   # clean up
   for tmp_path in announce_cleanup_list:
       try:
           os.unlink( tmp_path )
       except:
           pass

   # put the announcement text
   announcement_text_dir = os.path.join( working_dir, "announcements" )
   if not os.path.exists( announcement_text_dir ):
       try:
           os.makedirs( announcement_text_dir )
       except:
           log.error("Failed to make directory %s" % announcement_text_dir )
           raise

   announcement_text_path = os.path.join( announcement_text_dir, "%s.txt" % announcement_hash )

   try:
       with open( announcement_text_path, "w" ) as f:
           f.write( announcement_text )

   except:
       log.error("Failed to save announcement text to %s" % announcement_text_path )
       raise

   log.debug("Stored announcement to %s" % (announcement_text_path))
758656
def process_announcement( sender_namerec, op, working_dir ):
    
    node_config = get_blockstack_opts()

    # valid announcement
    announce_hash = op['message_hash']
    announcer_id = op['announcer_id']
   
    # verify that it came from this individual
    name_history = sender_namerec['history']
    allowed_value_hashes = []
    for block_height in name_history.keys():
        for historic_namerec in name_history[block_height]:
            if historic_namerec.get('value_hash'):
                allowed_value_hashes.append(historic_namerec['value_hash'])

    if announce_hash not in allowed_value_hashes:
        # this individual did not send this announcement
        log.warning("Announce hash {} not found in name history for {}".format(announce_hash, announcer_id))
        return 

    # go get it from Atlas
    zonefiles_dir = node_config.get('zonefiles', None)
    if not zonefiles_dir:
        log.warning("This node does not store zone files, so no announcement can be found")
        return 

    announce_text = get_atlas_zonefile_data(announce_hash, zonefiles_dir)
    if announce_text is None:
        log.warning("No zone file {} found".format(announce_hash))
        return

    # go append it 
    log.critical("ANNOUNCEMENT (from %s): %s\n------BEGIN MESSAGE------\n%s\n------END MESSAGE------\n" % (announcer_id, announce_hash, announce_text))         
    store_announcement( working_dir, announce_hash, announce_text )
1174699
async def publish(self, message):
        """"""
        try:
            self.write('data: {}\n\n'.format(message))
            await self.flush()
        except StreamClosedError:
            self.finished = True
1139618
def putWebhook(self, hook_id, external_id, url, event_types):
        """"""
        path = 'notification/webhook'
        payload = {'id': hook_id, 'externalId': external_id,
                   'url': url, 'eventTypes': event_types}
        return self.rachio.put(path, payload)
35249
private function save() {
        update_option( 'wp_easy_notify_' . $this->prefix, $this->notices );
        update_option( 'wp_easy_notify_active_' . $this->prefix, $this->active );
    }
888847
def store_mo(self, state, new_mo, overwrite=True): #pylint:disable=unused-argument
        
        start, end = self._resolve_range(new_mo)
        if overwrite:
            self.store_overwrite(state, new_mo, start, end)
        else:
            self.store_underwrite(state, new_mo, start, end)
785995
function (event) {
        var self = this;

        event.monologued = false;
        event.recorded_at = new Date();

        self.events.insert(event, function (err) {
          if (!err) {
            _.delay(function () {
              self.events.remove({
                event_id: event.event_id
              });
            }, 60000);
          }
        });
      }
156660
def notify_block_new(self, block):
        """"""
        payload = block.SerializeToString()
        self._notify(
            "consensus_notifier_notify_block_new", payload, len(payload))
366320
protected function storeLastModuleInformation()
    {
        // Probably should store also arguments (except pager?)
        $foo = BackendUtility::getModuleData(
            array('controller' => '', 'action' => ''),
            array('controller' => $this->getControllerName(), 'action' => $this->getActionName()),
            $this->argumentsKey
        );
    }
301091
async def announce(self):
        
        # send a serialized event
        await self.event_broker.send(
            action_type=intialize_service_action(),
            payload=json.dumps(self.summarize())
        )
1112442
def _store(self, uid, content, data=None):
        """"""
        doc = dict(uid=uid)
        if data:
            gfs = gridfs.GridFS(self.db)
            id = gfs.put(data, encoding='utf-8')
            doc.update(data_id=id)
        doc.update(content)
        self.db.pastes.insert_one(doc)
166234
def announcement_posted_hook(request, obj):
    
    logger.debug("Announcement posted")

    if obj.notify_post:
        logger.debug("Announcement notify on")
        announcement_posted_twitter(request, obj)
        try:
            notify_all = obj.notify_email_all
        except AttributeError:
            notify_all = False

        try:
            if notify_all:
                announcement_posted_email(request, obj, True)
            else:
                announcement_posted_email(request, obj)
        except Exception as e:
            logger.error("Exception when emailing announcement: {}".format(e))
            messages.error(request, "Exception when emailing announcement: {}".format(e))
            raise e
    else:
        logger.debug("Announcement notify off")
158688
async def _on_headline(self, update):
        """"""

        name = update['service']
        message_obj = update['payload']
        new_headline = False

        if name not in self.services:
            return

        with self._state_lock:
            self.services[name].set_headline(message_obj['level'], message_obj['message'])

            if self.services[name].headline.count == 1:
                new_headline = True

        # Notify about this service state change if anyone is listening
        # headline changes are only reported if they are not duplicates
        if self._on_change_callback and new_headline:
            self._on_change_callback(name, self.services[name].id, self.services[name].state, False, True)
566727
def store(label, stats = {}, date = nil, opts = {}, meta = {})
      Event.new(self.name, label, date, stats, options.merge(opts), meta).save
    end
825772
def announce(self, number):
        
        self.client.publish(self.keys.internal, self.keys.key(number))
        self.message('{} granted'.format(number))
373504
public function markAsPersisted(): void
    {
        $this->markNew(false);
        $this->dispatchEvent(new Event\Persisted($this));
    }
72259
def put_nowait(self, item, size=None):
        """""""
        # Don't mark this method into a switchpoint as put() will never switch
        # if block is False.
        return self.put(item, False, size=size)