Calculates the expected lifecycle position the subscription in
    subscription_ids, and creates a BehindSubscription entry for them.

    Args:
        subscription_id (str): ID of subscription to calculate lifecycle for
431293
def calculate_subscription_lifecycle(subscription_id):
    
    subscription = Subscription.objects.select_related("messageset", "schedule").get(
        id=subscription_id
    )
    behind = subscription.messages_behind()
    if behind == 0:
        return

    current_messageset = subscription.messageset
    current_sequence_number = subscription.next_sequence_number
    end_subscription = Subscription.fast_forward_lifecycle(subscription, save=False)[-1]
    BehindSubscription.objects.create(
        subscription=subscription,
        messages_behind=behind,
        current_messageset=current_messageset,
        current_sequence_number=current_sequence_number,
        expected_messageset=end_subscription.messageset,
        expected_sequence_number=end_subscription.next_sequence_number,
    )
645409
def create_subscription(subscription_params = {})
      created_at = Time.current
      if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
        subscription_params[:subscribing_to_email] = subscription_params[:subscribing] 
      end
      subscription = subscriptions.new(subscription_params)
      subscription.subscribing? ?
        subscription.assign_attributes(subscribing: true, subscribed_at: created_at) :
        subscription.assign_attributes(subscribing: false, unsubscribed_at: created_at)
      subscription.subscribing_to_email? ?
        subscription.assign_attributes(subscribing_to_email: true, subscribed_to_email_at: created_at) :
        subscription.assign_attributes(subscribing_to_email: false, unsubscribed_to_email_at: created_at)
      subscription.optional_targets = (subscription.optional_targets || {}).with_indifferent_access
      optional_targets = {}.with_indifferent_access
      subscription.optional_target_names.each do |optional_target_name|
        optional_targets = subscription.subscribing_to_optional_target?(optional_target_name) ?
          optional_targets.merge(
            Subscription.to_optional_target_key(optional_target_name) => true,
            Subscription.to_optional_target_subscribed_at_key(optional_target_name) => created_at
          ) :
          optional_targets.merge(
            Subscription.to_optional_target_key(optional_target_name) => false,
            Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => created_at
          )
      end
      subscription.assign_attributes(optional_targets: optional_targets)
      subscription.save ? subscription : nil
    end
507760
def create_subscriptions(config, profile_name):
    '''  '''
    if 'kinesis' in config.subscription.keys():
        data = config.subscription['kinesis']
        function_name = config.name
        stream_name = data['stream']
        batch_size = data['batch_size']
        starting_position = data['starting_position']
        starting_position_ts = None
        if starting_position == 'AT_TIMESTAMP':
            ts = data.get('starting_position_timestamp')
            starting_position_ts = datetime.strptime(ts, '%Y-%m-%dT%H:%M:%SZ')
        s = KinesisSubscriber(config, profile_name,
                              function_name, stream_name, batch_size,
                              starting_position,
                              starting_position_ts=starting_position_ts)
        s.subscribe()
102931
private synchronized void performReliableSubscription() {
        // If timer is not running, initialize it.
        if (subscriberTimer == null) {
            LOGGER.info("Initializing reliable subscriber");
            subscriberTimer = createTimerInternal();
            ExponentialBackOff backOff = new ExponentialBackOff.Builder()
                    .setMaxElapsedTimeMillis(Integer.MAX_VALUE /* Try forever */)
                    .setMaxIntervalMillis(MAX_BACKOFF_MS)
                    .setMultiplier(MULTIPLIER)
                    .setRandomizationFactor(0.5)
                    .setInitialIntervalMillis(SEED_BACKOFF_MS)
                    .build();
            subscriberTimer.schedule(new SubscriberTask(backOff), SEED_BACKOFF_MS, TimeUnit.MILLISECONDS);
        }
    }
305780
def get_subscription(self, subscription_id):
        
        return self.client._put(self.url + 'subscriptions/{}'.format(subscription_id), headers=self.get_headers())
495346
def get_subscriptions_by_channel_id_and_person_id(
            self, channel_id, person_id):
        
        return self.search_subscriptions(
            channel_id=channel_id, person_id=person_id)
477515
def get_subscriptions_by_subscriber_id(
            self, subscriber_id, max_results=10):
        
        return self.search_subscriptions(
            subscriber_id=subscriber_id, max_results=max_results)
495164
def delete(self, subscription_id, data=None):
        
        if not subscription_id or not subscription_id.startswith(self.RESOURCE_ID_PREFIX):
            raise IdentifierError(
                "Invalid subscription ID: '{id}'. A subscription ID should start with '{prefix}'.".format(
                    id=subscription_id, prefix=self.RESOURCE_ID_PREFIX)
            )
        result = super(CustomerSubscriptions, self).delete(subscription_id, data)
        return self.get_resource_object(result)
1189052
def create(self, id):
        
        resp = self.client.accounts.create(id=id)
        self.display(resp)
720628
def _on_status(data, unique_id):
        
        status_code = data.get('statusCode')
        logger.info('[Subscription: %s]: %s' % (unique_id, status_code))
515782
def select_subscription(subs_code, subscriptions):
    
    if subs_code and subscriptions:
        for subs in subscriptions:
            if (subs.subscription_code == subs_code):
                return subs
    return None
1055126
def list_by_subscription_id(custom_headers:nil)
      response = list_by_subscription_id_async(custom_headers:custom_headers).value!
      response.body unless response.nil?
    end
497527
def push_subscription_update(self, follow_events=None, 
                              favourite_events=None, reblog_events=None, 
                              mention_events=None):
        
        params = {}
        
        if follow_events != None:
            params['data[alerts][follow]'] = follow_events
        
        if favourite_events != None:
            params['data[alerts][favourite]'] = favourite_events
            
        if reblog_events != None:
            params['data[alerts][reblog]'] = reblog_events
            
        if mention_events != None:
            params['data[alerts][mention]'] = mention_events
            
        return self.__api_request('PUT', '/api/v1/push/subscription', params)
552527
def get_subscription(self, subscription_id):
        
        url = self.SUBSCRIPTIONS_ID_URL % subscription_id

        connection = Connection(self.token)
        connection.set_url(self.production, url)

        return connection.get_request()
1264455
def list_presubscriptions(self, **kwargs):
        
        api = self._get_api(mds.SubscriptionsApi)
        resp = api.get_pre_subscriptions(**kwargs)
        return [Presubscription(p) for p in resp]
810606
private ControllableSubscription getSubscription(String id) 
  throws SIMPControllableNotFoundException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getSubscription", id);
      
    //id is assumed to be SIBUuid12
    SIBUuid12 uuid = new SIBUuid12(id);
    SubscriptionTypeFilter filter = new SubscriptionTypeFilter();
    filter.LOCAL = Boolean.TRUE;
    ControllableSubscription sub = getSubscriptionIndex().findByUuid(uuid, filter);
    
    // If the sub is null, throw an exception
    if (sub == null)
    {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(
          tc,
          "getLocalSubscriptionControlByID",
          "SIMPControllableNotFoundException");
          
      throw new SIMPControllableNotFoundException(
        nls.getFormattedMessage(
          "SUBSCRIPTION_NOT_FOUND_ERROR_CWSIP0271",
          new Object[]{id},
          null));  
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getSubscription", sub);
    
    return sub;
  }
934797
def startSubscription(self, reqId, subscriber, contract=None):
        
        self._reqId2Contract[reqId] = contract
        self.reqId2Subscriber[reqId] = subscriber