Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Add channel selection rules for delivery actions
Browse files Browse the repository at this point in the history
Specifically, define the notion of a 'default plan' (currently, the default plan is the oldest created plan)
whose channel is used when no other channel (based on plan coverage) is indicated.
Closes #303
  • Loading branch information
Richard Rodgers committed Aug 4, 2015
1 parent 2e052e6 commit fa409d5
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions app/workers/Conveyor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ object Conveyor {
val action = if (accept) "deliver" else "discard"
val trans = Transfer.make(hold.subscriberId, hold.subscriptionId, hold.itemId, action)
if (accept) {
transfer(hold.item, trans)
transfer(hold.item, hold.subscription, trans)
}
// clean up hold in any case
hold.resolve(accept)
Expand Down Expand Up @@ -212,32 +212,26 @@ object Conveyor {
! Hold.held(item.id, sub.subscriberId)) {
// create a new transfer or hold, or notify subscriber
sub.action match {
case "deliver" => transfer(item, sub)
case "deliver" => transfer(item, sub, Transfer.make(sub.subscriberId, sub.id, item.id, sub.action))
case "review" => Hold.make(sub.subscriberId, sub.id, item.id)
case "notify" => notify(item, sub)
case _ => println("Unknown action: " + sub.action)
}
}
}

private def transfer(item: Item, sub: Subscription) = {
val trans = Transfer.make(sub.subscriberId, sub.id, item.id, sub.action)
doTransfer(item, sub.subscriber, trans)
}

private def transfer(item: Item, trans: Transfer) = {
Subscriber.findById(trans.subscriberId).map { subscr =>
doTransfer(item, subscr, trans)
}
private def transfer(item: Item, sub: Subscription, trans: Transfer) = {
val subscr = sub.subscriber
// NB: provisional definition of 'default' plan = first one created for subscriber
val plan = subscr.planFor(sub.topic.scheme_id).getOrElse(subscr.plans.sortBy(_.created).head)
doTransfer(item, plan.channel.get, trans)
}

private def doTransfer(item: Item, subscr: Subscriber, trans: Transfer) = {
// should fail if no channel - TODO
subscr.channels.headOption.map { chan =>
chan.protocol match {
case "sword" => swordTransfer(item, chan, trans)
case _ => println("Don't know how to transfer via: " + chan.protocol)
}
private def doTransfer(item: Item, chan: Channel, trans: Transfer) = {
chan.protocol match {
case "sword" => swordTransfer(item, chan, trans)
case "drain" => chan.recordTransfer // essentially No-Op
case _ => println("Don't know how to transfer via: " + chan.protocol)
}
}

Expand Down

0 comments on commit fa409d5

Please sign in to comment.